hedgewars/uScript.pas
changeset 12294 0deabf747b8f
parent 12286 b4dde7035fe2
child 12301 46e1e25fec5e
equal deleted inserted replaced
12293:6383323fdd2c 12294:0deabf747b8f
   221 end;
   221 end;
   222 
   222 
   223 function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   223 function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   224 begin
   224 begin
   225     if lua_isnoneornil(L, i) then i:= -1
   225     if lua_isnoneornil(L, i) then i:= -1
   226     else i:= lua_tointeger(L, i);
   226     else i:= Trunc(lua_tonumber(L, i));
   227     if (i < ord(Low(TGearType))) or (i > ord(High(TGearType))) then
   227     if (i < ord(Low(TGearType))) or (i > ord(High(TGearType))) then
   228         begin
   228         begin
   229         LuaCallError('Invalid gearType!', call, paramsyntax);
   229         LuaCallError('Invalid gearType!', call, paramsyntax);
   230         LuaToGearTypeOrd:= -1;
   230         LuaToGearTypeOrd:= -1;
   231         end
   231         end
   234 end;
   234 end;
   235 
   235 
   236 function LuaToVisualGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   236 function LuaToVisualGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   237 begin
   237 begin
   238     if lua_isnoneornil(L, i) then i:= -1
   238     if lua_isnoneornil(L, i) then i:= -1
   239     else i:= lua_tointeger(L, i);
   239     else i:= Trunc(lua_tonumber(L, i));
   240     if (i < ord(Low(TVisualGearType))) or (i > ord(High(TVisualGearType))) then
   240     if (i < ord(Low(TVisualGearType))) or (i > ord(High(TVisualGearType))) then
   241         begin
   241         begin
   242         LuaCallError('Invalid visualGearType!', call, paramsyntax);
   242         LuaCallError('Invalid visualGearType!', call, paramsyntax);
   243         LuaToVisualGearTypeOrd:= -1;
   243         LuaToVisualGearTypeOrd:= -1;
   244         end
   244         end
   247 end;
   247 end;
   248 
   248 
   249 function LuaToAmmoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   249 function LuaToAmmoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   250 begin
   250 begin
   251     if lua_isnoneornil(L, i) then i:= -1
   251     if lua_isnoneornil(L, i) then i:= -1
   252     else i:= lua_tointeger(L, i);
   252     else i:= Trunc(lua_tonumber(L, i));
   253     if (i < ord(Low(TAmmoType))) or (i > ord(High(TAmmoType))) then
   253     if (i < ord(Low(TAmmoType))) or (i > ord(High(TAmmoType))) then
   254         begin
   254         begin
   255         LuaCallError('Invalid ammoType!', call, paramsyntax);
   255         LuaCallError('Invalid ammoType!', call, paramsyntax);
   256         LuaToAmmoTypeOrd:= -1;
   256         LuaToAmmoTypeOrd:= -1;
   257         end
   257         end
   260 end;
   260 end;
   261 
   261 
   262 function LuaToStatInfoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   262 function LuaToStatInfoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   263 begin
   263 begin
   264     if lua_isnoneornil(L, i) then i:= -1
   264     if lua_isnoneornil(L, i) then i:= -1
   265     else i:= lua_tointeger(L, i);
   265     else i:= Trunc(lua_tonumber(L, i));
   266     if (i < ord(Low(TStatInfoType))) or (i > ord(High(TStatInfoType))) then
   266     if (i < ord(Low(TStatInfoType))) or (i > ord(High(TStatInfoType))) then
   267         begin
   267         begin
   268         LuaCallError('Invalid statInfoType!', call, paramsyntax);
   268         LuaCallError('Invalid statInfoType!', call, paramsyntax);
   269         LuaToStatInfoTypeOrd:= -1;
   269         LuaToStatInfoTypeOrd:= -1;
   270         end
   270         end
   273 end;
   273 end;
   274 
   274 
   275 function LuaToSoundOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   275 function LuaToSoundOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   276 begin
   276 begin
   277     if lua_isnoneornil(L, i) then i:= -1
   277     if lua_isnoneornil(L, i) then i:= -1
   278     else i:= lua_tointeger(L, i);
   278     else i:= Trunc(lua_tonumber(L, i));
   279     if (i < ord(Low(TSound))) or (i > ord(High(TSound))) then
   279     if (i < ord(Low(TSound))) or (i > ord(High(TSound))) then
   280         begin
   280         begin
   281         LuaCallError('Invalid soundId!', call, paramsyntax);
   281         LuaCallError('Invalid soundId!', call, paramsyntax);
   282         LuaToSoundOrd:= -1;
   282         LuaToSoundOrd:= -1;
   283         end
   283         end
   286 end;
   286 end;
   287 
   287 
   288 function LuaToHogEffectOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   288 function LuaToHogEffectOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   289 begin
   289 begin
   290     if lua_isnoneornil(L, i) then i:= -1
   290     if lua_isnoneornil(L, i) then i:= -1
   291     else i:= lua_tointeger(L, i);
   291     else i:= Trunc(lua_tonumber(L, i));
   292     if (i < ord(Low(THogEffect))) or (i > ord(High(THogEffect))) then
   292     if (i < ord(Low(THogEffect))) or (i > ord(High(THogEffect))) then
   293         begin
   293         begin
   294         LuaCallError('Invalid effect type!', call, paramsyntax);
   294         LuaCallError('Invalid effect type!', call, paramsyntax);
   295         LuaToHogEffectOrd:= -1;
   295         LuaToHogEffectOrd:= -1;
   296         end
   296         end
   299 end;
   299 end;
   300 
   300 
   301 function LuaToCapGroupOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   301 function LuaToCapGroupOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   302 begin
   302 begin
   303     if lua_isnoneornil(L, i) then i:= -1
   303     if lua_isnoneornil(L, i) then i:= -1
   304     else i:= lua_tointeger(L, i);
   304     else i:= Trunc(lua_tonumber(L, i));
   305     if (i < ord(Low(TCapGroup))) or (i > ord(High(TCapGroup))) then
   305     if (i < ord(Low(TCapGroup))) or (i > ord(High(TCapGroup))) then
   306         begin
   306         begin
   307         LuaCallError('Invalid capgroup type!', call, paramsyntax);
   307         LuaCallError('Invalid capgroup type!', call, paramsyntax);
   308         LuaToCapGroupOrd:= -1;
   308         LuaToCapGroupOrd:= -1;
   309         end
   309         end
   312 end;
   312 end;
   313 
   313 
   314 function LuaToSpriteOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   314 function LuaToSpriteOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   315 begin
   315 begin
   316     if lua_isnoneornil(L, i) then i:= -1
   316     if lua_isnoneornil(L, i) then i:= -1
   317     else i:= lua_tointeger(L, i);
   317     else i:= Trunc(lua_tonumber(L, i));
   318     if (i < ord(Low(TSprite))) or (i > ord(High(TSprite))) then
   318     if (i < ord(Low(TSprite))) or (i > ord(High(TSprite))) then
   319         begin
   319         begin
   320         LuaCallError('Invalid sprite id!', call, paramsyntax);
   320         LuaCallError('Invalid sprite id!', call, paramsyntax);
   321         LuaToSpriteOrd:= -1;
   321         LuaToSpriteOrd:= -1;
   322         end
   322         end
   325 end;
   325 end;
   326 
   326 
   327 function LuaToMapGenOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   327 function LuaToMapGenOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
   328 begin
   328 begin
   329     if lua_isnoneornil(L, i) then i:= -1
   329     if lua_isnoneornil(L, i) then i:= -1
   330     else i:= lua_tointeger(L, i);
   330     else i:= Trunc(lua_tonumber(L, i));
   331     if (i < ord(Low(TMapGen))) or (i > ord(High(TMapGen))) then
   331     if (i < ord(Low(TMapGen))) or (i > ord(High(TMapGen))) then
   332         begin
   332         begin
   333         LuaCallError('Invalid mapgen id!', call, paramsyntax);
   333         LuaCallError('Invalid mapgen id!', call, paramsyntax);
   334         LuaToMapGenOrd:= -1;
   334         LuaToMapGenOrd:= -1;
   335         end
   335         end
   348 // use as return value the number of variables pushed back to the lua script
   348 // use as return value the number of variables pushed back to the lua script
   349 
   349 
   350 function lc_band(L: PLua_State): LongInt; Cdecl;
   350 function lc_band(L: PLua_State): LongInt; Cdecl;
   351 begin
   351 begin
   352     if CheckLuaParamCount(L, 2, 'band', 'value1, value2') then
   352     if CheckLuaParamCount(L, 2, 'band', 'value1, value2') then
   353         lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1))
   353         lua_pushnumber(L, Trunc(lua_tonumber(L, 2)) and Trunc(lua_tonumber(L, 1)))
   354     else
   354     else
   355         lua_pushnil(L);
   355         lua_pushnil(L);
   356     lc_band := 1;
   356     lc_band := 1;
   357 end;
   357 end;
   358 
   358 
   359 function lc_bor(L: PLua_State): LongInt; Cdecl;
   359 function lc_bor(L: PLua_State): LongInt; Cdecl;
   360 begin
   360 begin
   361     if CheckLuaParamCount(L, 2, 'bor', 'value1, value2') then
   361     if CheckLuaParamCount(L, 2, 'bor', 'value1, value2') then
   362         lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1))
   362         lua_pushnumber(L, Trunc(lua_tonumber(L, 2)) or Trunc(lua_tonumber(L, 1)))
   363     else
   363     else
   364         lua_pushnil(L);
   364         lua_pushnil(L);
   365     lc_bor := 1;
   365     lc_bor := 1;
   366 end;
   366 end;
   367 
   367 
   368 function lc_bnot(L: PLua_State): LongInt; Cdecl;
   368 function lc_bnot(L: PLua_State): LongInt; Cdecl;
   369 begin
   369 begin
   370     if CheckLuaParamCount(L, 1, 'bnot', 'value') then
   370     if CheckLuaParamCount(L, 1, 'bnot', 'value') then
   371         lua_pushinteger(L, (not lua_tointeger(L, 1)))
   371         lua_pushnumber(L, (not Trunc(lua_tonumber(L, 1))))
   372     else
   372     else
   373         lua_pushnil(L);
   373         lua_pushnil(L);
   374     lc_bnot := 1;
   374     lc_bnot := 1;
   375 end;
   375 end;
   376 
   376 
   377 function lc_div(L: PLua_State): LongInt; Cdecl;
   377 function lc_div(L: PLua_State): LongInt; Cdecl;
   378 begin
   378 begin
   379     if CheckLuaParamCount(L, 2, 'div', 'dividend, divisor') then
   379     if CheckLuaParamCount(L, 2, 'div', 'dividend, divisor') then
   380         lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2))
   380         lua_pushnumber(L, Trunc(lua_tonumber(L, 1)) div Trunc(lua_tonumber(L, 2)))
   381     else
   381     else
   382         lua_pushnil(L);
   382         lua_pushnil(L);
   383     lc_div := 1;
   383     lc_div := 1;
   384 end;
   384 end;
   385 
   385 
   386 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl;
   386 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl;
   387 begin
   387 begin
   388     if CheckLuaParamCount(L, 0, 'GetInputMask', '') then
   388     if CheckLuaParamCount(L, 0, 'GetInputMask', '') then
   389         lua_pushinteger(L, InputMask);
   389         lua_pushnumber(L, InputMask);
   390     lc_getinputmask:= 1
   390     lc_getinputmask:= 1
   391 end;
   391 end;
   392 
   392 
   393 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl;
   393 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl;
   394 begin
   394 begin
   395     if CheckLuaParamCount(L, 1, 'SetInputMask', 'mask') then
   395     if CheckLuaParamCount(L, 1, 'SetInputMask', 'mask') then
   396         InputMask:= lua_tointeger(L, 1);
   396         InputMask:= Trunc(lua_tonumber(L, 1));
   397     lc_setinputmask:= 0
   397     lc_setinputmask:= 0
   398 end;
   398 end;
   399 
   399 
   400 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
   400 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
   401 begin
   401 begin
   465             begin
   465             begin
   466             // no args? reset
   466             // no args? reset
   467             cBuildMaxDist:= cDefaultBuildMaxDist;
   467             cBuildMaxDist:= cDefaultBuildMaxDist;
   468             end
   468             end
   469         else
   469         else
   470             CBuildMaxDist:= lua_tointeger(L, 1);
   470             CBuildMaxDist:= Trunc(lua_tonumber(L, 1));
   471         end;
   471         end;
   472     lc_setmaxbuilddistance:= 0;
   472     lc_setmaxbuilddistance:= 0;
   473 end;
   473 end;
   474 
   474 
   475 // sets weapon to whatever weapons is next (wraps around, amSkip is skipped)
   475 // sets weapon to whatever weapons is next (wraps around, amSkip is skipped)
   537 end;
   537 end;
   538 
   538 
   539 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
   539 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
   540 begin
   540 begin
   541     if CheckLuaParamCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then
   541     if CheckLuaParamCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then
   542         ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   542         ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)));
   543     lc_showmission:= 0;
   543     lc_showmission:= 0;
   544 end;
   544 end;
   545 
   545 
   546 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   546 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   547 begin
   547 begin
   582 begin
   582 begin
   583     // can have 1 or more arguments
   583     // can have 1 or more arguments
   584     if CheckAndFetchLuaParamMinCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then
   584     if CheckAndFetchLuaParamMinCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then
   585         begin
   585         begin
   586         for i:= 1 to n do
   586         for i:= 1 to n do
   587             GameFlags := GameFlags or LongWord(lua_tointeger(L, i));
   587             GameFlags := GameFlags or LongWord(Trunc(lua_tonumber(L, i)));
   588         ScriptSetInteger('GameFlags', GameFlags);
   588         ScriptSetInteger('GameFlags', GameFlags);
   589         end;
   589         end;
   590     lc_enablegameflags:= 0;
   590     lc_enablegameflags:= 0;
   591 end;
   591 end;
   592 
   592 
   595 begin
   595 begin
   596     // can have 1 or more arguments
   596     // can have 1 or more arguments
   597     if CheckAndFetchLuaParamMinCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then
   597     if CheckAndFetchLuaParamMinCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then
   598         begin
   598         begin
   599         for i:= 1 to n do
   599         for i:= 1 to n do
   600             GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i)));
   600             GameFlags := GameFlags and (not LongWord(Trunc(lua_tonumber(L, i))));
   601         ScriptSetInteger('GameFlags', GameFlags);
   601         ScriptSetInteger('GameFlags', GameFlags);
   602         end;
   602         end;
   603     lc_disablegameflags:= 0;
   603     lc_disablegameflags:= 0;
   604 end;
   604 end;
   605 
   605 
   614 end;
   614 end;
   615 
   615 
   616 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
   616 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
   617 begin
   617 begin
   618     if CheckLuaParamCount(L, 1, 'GetGameFlag', 'gameflag') then
   618     if CheckLuaParamCount(L, 1, 'GetGameFlag', 'gameflag') then
   619         lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0))
   619         lua_pushboolean(L, (GameFlags and LongWord(Trunc(lua_tonumber(L, 1))) <> 0))
   620     else
   620     else
   621         lua_pushnil(L);
   621         lua_pushnil(L);
   622     lc_getgameflag:= 1;
   622     lc_getgameflag:= 1;
   623 end;
   623 end;
   624 
   624 
   634             AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage)
   634             AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage)
   635         else
   635         else
   636             begin
   636             begin
   637             cg:= LuaToCapGroupOrd(L, 3, call, params);
   637             cg:= LuaToCapGroupOrd(L, 3, call, params);
   638             if cg >= 0 then
   638             if cg >= 0 then
   639                 AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(cg));
   639                 AddCaption(lua_tostringA(L, 1), Trunc(lua_tonumber(L, 2)) shr 8, TCapGroup(cg));
   640             end
   640             end
   641         end;
   641         end;
   642     lc_addcaption:= 0;
   642     lc_addcaption:= 0;
   643 end;
   643 end;
   644 
   644 
   663 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   663 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   664 var gear: PGear;
   664 var gear: PGear;
   665 begin
   665 begin
   666     if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   666     if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   667         begin
   667         begin
   668         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   668         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
   669         HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   669         HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   670         if gear <> nil then
   670         if gear <> nil then
   671              lua_pushinteger(L, gear^.uid)
   671              lua_pushnumber(L, gear^.uid)
   672         else lua_pushnil(L)
   672         else lua_pushnil(L)
   673         end
   673         end
   674     else
   674     else
   675         lua_pushnil(L);
   675         lua_pushnil(L);
   676     lc_spawnfakehealthcrate := 1;
   676     lc_spawnfakehealthcrate := 1;
   679 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   679 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   680 var gear: PGear;
   680 var gear: PGear;
   681 begin
   681 begin
   682     if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
   682     if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
   683         begin
   683         begin
   684         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   684         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
   685         AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   685         AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   686         if gear <> nil then
   686         if gear <> nil then
   687              lua_pushinteger(L, gear^.uid)
   687              lua_pushnumber(L, gear^.uid)
   688         else lua_pushnil(L)
   688         else lua_pushnil(L)
   689         end
   689         end
   690     else
   690     else
   691         lua_pushnil(L);
   691         lua_pushnil(L);
   692     lc_spawnfakeammocrate := 1;
   692     lc_spawnfakeammocrate := 1;
   695 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   695 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   696 var gear: PGear;
   696 var gear: PGear;
   697 begin
   697 begin
   698     if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
   698     if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
   699         begin
   699         begin
   700         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   700         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
   701         UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   701         UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   702         if gear <> nil then
   702         if gear <> nil then
   703              lua_pushinteger(L, gear^.uid)
   703              lua_pushnumber(L, gear^.uid)
   704         else lua_pushnil(L)
   704         else lua_pushnil(L)
   705         end
   705         end
   706     else
   706     else
   707         lua_pushnil(L);
   707         lua_pushnil(L);
   708     lc_spawnfakeutilitycrate := 1;
   708     lc_spawnfakeutilitycrate := 1;
   713 var health, n: LongInt;
   713 var health, n: LongInt;
   714 begin
   714 begin
   715     if CheckAndFetchParamCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then
   715     if CheckAndFetchParamCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then
   716         begin
   716         begin
   717         if n = 3 then
   717         if n = 3 then
   718             health:= lua_tointeger(L, 3)
   718             health:= Trunc(lua_tonumber(L, 3))
   719         else
   719         else
   720             health:= cHealthCaseAmount;
   720             health:= cHealthCaseAmount;
   721         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0);
   721         gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), HealthCrate, health, 0);
   722         if gear <> nil then
   722         if gear <> nil then
   723              lua_pushinteger(L, gear^.uid)
   723              lua_pushnumber(L, gear^.uid)
   724         else lua_pushnil(L);
   724         else lua_pushnil(L);
   725         end
   725         end
   726     else
   726     else
   727         lua_pushnil(L);
   727         lua_pushnil(L);
   728     lc_spawnhealthcrate := 1;
   728     lc_spawnhealthcrate := 1;
   733     n   : LongInt;
   733     n   : LongInt;
   734 begin
   734 begin
   735     if CheckAndFetchParamCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then
   735     if CheckAndFetchParamCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then
   736         begin
   736         begin
   737         if n = 3 then
   737         if n = 3 then
   738              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0)
   738              gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), AmmoCrate, Trunc(lua_tonumber(L, 3)), 0)
   739         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   739         else gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), AmmoCrate, Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)));
   740         if gear <> nil then
   740         if gear <> nil then
   741              lua_pushinteger(L, gear^.uid)
   741              lua_pushnumber(L, gear^.uid)
   742         else lua_pushnil(L);
   742         else lua_pushnil(L);
   743         end
   743         end
   744     else
   744     else
   745         lua_pushnil(L);
   745         lua_pushnil(L);
   746     lc_spawnammocrate := 1;
   746     lc_spawnammocrate := 1;
   751     n   : LongInt;
   751     n   : LongInt;
   752 begin
   752 begin
   753     if CheckAndFetchParamCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then
   753     if CheckAndFetchParamCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then
   754         begin
   754         begin
   755         if n = 3 then
   755         if n = 3 then
   756              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0)
   756              gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), UtilityCrate, Trunc(lua_tonumber(L, 3)), 0)
   757         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   757         else gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), UtilityCrate, Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)));
   758         if gear <> nil then
   758         if gear <> nil then
   759              lua_pushinteger(L, gear^.uid)
   759              lua_pushnumber(L, gear^.uid)
   760         else lua_pushnil(L);
   760         else lua_pushnil(L);
   761        end
   761        end
   762     else
   762     else
   763         lua_pushnil(L);
   763         lua_pushnil(L);
   764     lc_spawnutilitycrate := 1;
   764     lc_spawnutilitycrate := 1;
   777         begin
   777         begin
   778         t:= LuaToGearTypeOrd(L, 3, call, params);
   778         t:= LuaToGearTypeOrd(L, 3, call, params);
   779         if t >= 0 then
   779         if t >= 0 then
   780             begin
   780             begin
   781             gt:= TGearType(t);
   781             gt:= TGearType(t);
   782             x:= lua_tointeger(L, 1);
   782             x:= Trunc(lua_tonumber(L, 1));
   783             y:= lua_tointeger(L, 2);
   783             y:= Trunc(lua_tonumber(L, 2));
   784             s:= lua_tointeger(L, 4);
   784             s:= Trunc(lua_tonumber(L, 4));
   785             dx:= int2hwFloat(lua_tointeger(L, 5)) / 1000000;
   785             dx:= int2hwFloat(Trunc(lua_tonumber(L, 5))) / 1000000;
   786             dy:= int2hwFloat(lua_tointeger(L, 6)) / 1000000;
   786             dy:= int2hwFloat(Trunc(lua_tonumber(L, 6))) / 1000000;
   787             t:= lua_tointeger(L, 7);
   787             t:= Trunc(lua_tonumber(L, 7));
   788 
   788 
   789             gear:= AddGear(x, y, gt, s, dx, dy, t);
   789             gear:= AddGear(x, y, gt, s, dx, dy, t);
   790             lastGearByUID:= gear;
   790             lastGearByUID:= gear;
   791             lua_pushinteger(L, gear^.uid)
   791             lua_pushnumber(L, gear^.uid)
   792             end
   792             end
   793         else
   793         else
   794             lua_pushnil(L);
   794             lua_pushnil(L);
   795         end
   795         end
   796     else
   796     else
   801 function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
   801 function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
   802 var gear : PGear;
   802 var gear : PGear;
   803 begin
   803 begin
   804     if CheckLuaParamCount(L, 1, 'DeleteGear', 'gearUid') then
   804     if CheckLuaParamCount(L, 1, 'DeleteGear', 'gearUid') then
   805         begin
   805         begin
   806         gear:= GearByUID(lua_tointeger(L, 1));
   806         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
   807         if gear <> nil then
   807         if gear <> nil then
   808             gear^.Message:= gear^.Message or gmDelete;
   808             gear^.Message:= gear^.Message or gmDelete;
   809         end;
   809         end;
   810     lc_deletegear:= 0
   810     lc_deletegear:= 0
   811 end;
   811 end;
   825         begin
   825         begin
   826         s:= LuaToVisualGearTypeOrd(L, 3, call, params);
   826         s:= LuaToVisualGearTypeOrd(L, 3, call, params);
   827         if s >= 0 then
   827         if s >= 0 then
   828             begin
   828             begin
   829             vgt:= TVisualGearType(s);
   829             vgt:= TVisualGearType(s);
   830             x:= lua_tointeger(L, 1);
   830             x:= Trunc(lua_tonumber(L, 1));
   831             y:= lua_tointeger(L, 2);
   831             y:= Trunc(lua_tonumber(L, 2));
   832             s:= lua_tointeger(L, 4);
   832             s:= Trunc(lua_tonumber(L, 4));
   833             c:= lua_toboolean(L, 5);
   833             c:= lua_toboolean(L, 5);
   834 
   834 
   835             if n = 6 then
   835             if n = 6 then
   836                 begin
   836                 begin
   837                 layer:= lua_tointeger(L, 6);
   837                 layer:= Trunc(lua_tonumber(L, 6));
   838                 vg:= AddVisualGear(x, y, vgt, s, c, layer);
   838                 vg:= AddVisualGear(x, y, vgt, s, c, layer);
   839                 end
   839                 end
   840             else
   840             else
   841                 vg:= AddVisualGear(x, y, vgt, s, c);
   841                 vg:= AddVisualGear(x, y, vgt, s, c);
   842 
   842 
   843             if vg <> nil then
   843             if vg <> nil then
   844                 begin
   844                 begin
   845                 lastVisualGearByUID:= vg;
   845                 lastVisualGearByUID:= vg;
   846                 uid:= vg^.uid;
   846                 uid:= vg^.uid;
   847                 lua_pushinteger(L, uid);
   847                 lua_pushnumber(L, uid);
   848                 end;
   848                 end;
   849             end
   849             end
   850             else
   850             else
   851                 lua_pushnil(L);
   851                 lua_pushnil(L);
   852         end
   852         end
   859 var vg : PVisualGear;
   859 var vg : PVisualGear;
   860 begin
   860 begin
   861     vg:= nil;
   861     vg:= nil;
   862     if CheckLuaParamCount(L, 1, 'DeleteVisualGear', 'vgUid') then
   862     if CheckLuaParamCount(L, 1, 'DeleteVisualGear', 'vgUid') then
   863         begin
   863         begin
   864         vg:= VisualGearByUID(lua_tointeger(L, 1));
   864         vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
   865         if vg <> nil then
   865         if vg <> nil then
   866             DeleteVisualGear(vg);
   866             DeleteVisualGear(vg);
   867         end;
   867         end;
   868     // allow caller to know whether there was something to delete
   868     // allow caller to know whether there was something to delete
   869     lua_pushboolean(L, vg <> nil);
   869     lua_pushboolean(L, vg <> nil);
   873 function lc_getvisualgeartype(L : Plua_State) : LongInt; Cdecl;
   873 function lc_getvisualgeartype(L : Plua_State) : LongInt; Cdecl;
   874 var vg : PVisualGear;
   874 var vg : PVisualGear;
   875 begin
   875 begin
   876     if CheckLuaParamCount(L, 1, 'GetVisualGearType', 'vgUid') then
   876     if CheckLuaParamCount(L, 1, 'GetVisualGearType', 'vgUid') then
   877         begin
   877         begin
   878         vg := VisualGearByUID(lua_tointeger(L, 1));
   878         vg := VisualGearByUID(Trunc(lua_tonumber(L, 1)));
   879         if vg <> nil then
   879         if vg <> nil then
   880             lua_pushinteger(L, ord(vg^.Kind))
   880             lua_pushnumber(L, ord(vg^.Kind))
   881         else
   881         else
   882             lua_pushnil(L);
   882             lua_pushnil(L);
   883         end
   883         end
   884     else
   884     else
   885         lua_pushnil(L); // return value on stack (nil)
   885         lua_pushnil(L); // return value on stack (nil)
   890 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
   890 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
   891 var vg: PVisualGear;
   891 var vg: PVisualGear;
   892 begin
   892 begin
   893     if CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then
   893     if CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then
   894         begin
   894         begin
   895         vg:= VisualGearByUID(lua_tointeger(L, 1));
   895         vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
   896         if vg <> nil then
   896         if vg <> nil then
   897             begin
   897             begin
   898             lua_pushinteger(L, round(vg^.X));
   898             lua_pushnumber(L, round(vg^.X));
   899             lua_pushinteger(L, round(vg^.Y));
   899             lua_pushnumber(L, round(vg^.Y));
   900             lua_pushnumber(L, vg^.dX);
   900             lua_pushnumber(L, vg^.dX);
   901             lua_pushnumber(L, vg^.dY);
   901             lua_pushnumber(L, vg^.dY);
   902             lua_pushnumber(L, vg^.Angle);
   902             lua_pushnumber(L, vg^.Angle);
   903             lua_pushinteger(L, vg^.Frame);
   903             lua_pushnumber(L, vg^.Frame);
   904             lua_pushinteger(L, vg^.FrameTicks);
   904             lua_pushnumber(L, vg^.FrameTicks);
   905             lua_pushinteger(L, vg^.State);
   905             lua_pushnumber(L, vg^.State);
   906             lua_pushinteger(L, vg^.Timer);
   906             lua_pushnumber(L, vg^.Timer);
   907             lua_pushinteger(L, vg^.Tint);
   907             lua_pushnumber(L, vg^.Tint);
   908             end
   908             end
   909         else
   909         else
   910             begin
   910             begin
   911             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   911             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   912             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   912             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   924 var vg : PVisualGear;
   924 var vg : PVisualGear;
   925 begin
   925 begin
   926 // Param count can be 1-11 at present
   926 // Param count can be 1-11 at present
   927 //    if CheckLuaParamCount(L, 11, 'SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint') then
   927 //    if CheckLuaParamCount(L, 11, 'SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint') then
   928 //        begin
   928 //        begin
   929         vg:= VisualGearByUID(lua_tointeger(L, 1));
   929         vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
   930         if vg <> nil then
   930         if vg <> nil then
   931             begin
   931             begin
   932             if not lua_isnoneornil(L, 2) then
   932             if not lua_isnoneornil(L, 2) then
   933                 vg^.X:= lua_tointeger(L, 2);
   933                 vg^.X:= Trunc(lua_tonumber(L, 2));
   934             if not lua_isnoneornil(L, 3) then
   934             if not lua_isnoneornil(L, 3) then
   935                 vg^.Y:= lua_tointeger(L, 3);
   935                 vg^.Y:= Trunc(lua_tonumber(L, 3));
   936             if not lua_isnoneornil(L, 4) then
   936             if not lua_isnoneornil(L, 4) then
   937                 vg^.dX:= lua_tonumber(L, 4);
   937                 vg^.dX:= lua_tonumber(L, 4);
   938             if not lua_isnoneornil(L, 5) then
   938             if not lua_isnoneornil(L, 5) then
   939                 vg^.dY:= lua_tonumber(L, 5);
   939                 vg^.dY:= lua_tonumber(L, 5);
   940             if not lua_isnoneornil(L, 6) then
   940             if not lua_isnoneornil(L, 6) then
   941                 vg^.Angle:= lua_tonumber(L, 6);
   941                 vg^.Angle:= lua_tonumber(L, 6);
   942             if not lua_isnoneornil(L, 7) then
   942             if not lua_isnoneornil(L, 7) then
   943                 vg^.Frame:= lua_tointeger(L, 7);
   943                 vg^.Frame:= Trunc(lua_tonumber(L, 7));
   944             if not lua_isnoneornil(L, 8) then
   944             if not lua_isnoneornil(L, 8) then
   945                 vg^.FrameTicks:= lua_tointeger(L, 8);
   945                 vg^.FrameTicks:= Trunc(lua_tonumber(L, 8));
   946             if not lua_isnoneornil(L, 9) then
   946             if not lua_isnoneornil(L, 9) then
   947                 vg^.State:= lua_tointeger(L, 9);
   947                 vg^.State:= Trunc(lua_tonumber(L, 9));
   948             if not lua_isnoneornil(L, 10) then
   948             if not lua_isnoneornil(L, 10) then
   949                 vg^.Timer:= lua_tointeger(L, 10);
   949                 vg^.Timer:= Trunc(lua_tonumber(L, 10));
   950             if not lua_isnoneornil(L, 11) then
   950             if not lua_isnoneornil(L, 11) then
   951                 vg^.Tint:= lua_tointeger(L, 11)
   951                 vg^.Tint:= Trunc(lua_tonumber(L, 11))
   952             end;
   952             end;
   953 //        end
   953 //        end
   954 //    else
   954 //    else
   955 //        lua_pushnil(L); // return value on stack (nil)
   955 //        lua_pushnil(L); // return value on stack (nil)
   956     lc_setvisualgearvalues:= 0
   956     lc_setvisualgearvalues:= 0
   961 function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl;
   961 function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl;
   962 var gear: PGear;
   962 var gear: PGear;
   963 begin
   963 begin
   964     if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then
   964     if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then
   965         begin
   965         begin
   966         gear:= GearByUID(lua_tointeger(L, 1));
   966         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
   967         if gear <> nil then
   967         if gear <> nil then
   968             begin
   968             begin
   969             lua_pushinteger(L, gear^.Angle);
   969             lua_pushnumber(L, gear^.Angle);
   970             lua_pushinteger(L, gear^.Power);
   970             lua_pushnumber(L, gear^.Power);
   971             lua_pushinteger(L, gear^.WDTimer);
   971             lua_pushnumber(L, gear^.WDTimer);
   972             lua_pushinteger(L, gear^.Radius);
   972             lua_pushnumber(L, gear^.Radius);
   973             lua_pushinteger(L, hwRound(gear^.Density * _10000));
   973             lua_pushnumber(L, hwRound(gear^.Density * _10000));
   974             lua_pushinteger(L, gear^.Karma);
   974             lua_pushnumber(L, gear^.Karma);
   975             lua_pushnumber(L,  gear^.DirAngle);
   975             lua_pushnumber(L,  gear^.DirAngle);
   976             lua_pushinteger(L, gear^.AdvBounce);
   976             lua_pushnumber(L, gear^.AdvBounce);
   977             lua_pushinteger(L, Integer(gear^.ImpactSound));
   977             lua_pushnumber(L, Integer(gear^.ImpactSound));
   978             lua_pushinteger(L, gear^.nImpactSounds);
   978             lua_pushnumber(L, gear^.nImpactSounds);
   979             lua_pushinteger(L, gear^.Tint);
   979             lua_pushnumber(L, gear^.Tint);
   980             lua_pushinteger(L, gear^.Damage);
   980             lua_pushnumber(L, gear^.Damage);
   981             lua_pushinteger(L, gear^.Boom)
   981             lua_pushnumber(L, gear^.Boom)
   982             end
   982             end
   983         else
   983         else
   984             begin
   984             begin
   985             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   985             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   986             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   986             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
  1000 var gear : PGear;
  1000 var gear : PGear;
  1001 begin
  1001 begin
  1002 // Currently allows 1-14 params
  1002 // Currently allows 1-14 params
  1003 //    if CheckLuaParamCount(L, 14, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint, Damage, Boom') then
  1003 //    if CheckLuaParamCount(L, 14, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint, Damage, Boom') then
  1004 //        begin
  1004 //        begin
  1005         gear:= GearByUID(lua_tointeger(L, 1));
  1005         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1006         if gear <> nil then
  1006         if gear <> nil then
  1007             begin
  1007             begin
  1008             if not lua_isnoneornil(L, 2) then
  1008             if not lua_isnoneornil(L, 2) then
  1009                 gear^.Angle := lua_tointeger(L, 2);
  1009                 gear^.Angle := Trunc(lua_tonumber(L, 2));
  1010             if not lua_isnoneornil(L, 3) then
  1010             if not lua_isnoneornil(L, 3) then
  1011                 gear^.Power := lua_tointeger(L, 3);
  1011                 gear^.Power := Trunc(lua_tonumber(L, 3));
  1012             if not lua_isnoneornil(L, 4) then
  1012             if not lua_isnoneornil(L, 4) then
  1013                 gear^.WDTimer := lua_tointeger(L, 4);
  1013                 gear^.WDTimer := Trunc(lua_tonumber(L, 4));
  1014             if not lua_isnoneornil(L, 5) then
  1014             if not lua_isnoneornil(L, 5) then
  1015                 gear^.Radius := lua_tointeger(L, 5);
  1015                 gear^.Radius := Trunc(lua_tonumber(L, 5));
  1016             if not lua_isnoneornil(L, 6) then
  1016             if not lua_isnoneornil(L, 6) then
  1017                 gear^.Density:= int2hwFloat(lua_tointeger(L, 6)) / 10000;
  1017                 gear^.Density:= int2hwFloat(Trunc(lua_tonumber(L, 6))) / 10000;
  1018             if not lua_isnoneornil(L, 7) then
  1018             if not lua_isnoneornil(L, 7) then
  1019                 gear^.Karma := lua_tointeger(L, 7);
  1019                 gear^.Karma := Trunc(lua_tonumber(L, 7));
  1020             if not lua_isnoneornil(L, 8) then
  1020             if not lua_isnoneornil(L, 8) then
  1021                 gear^.DirAngle:= lua_tonumber(L, 8);
  1021                 gear^.DirAngle:= lua_tonumber(L, 8);
  1022             if not lua_isnoneornil(L, 9) then
  1022             if not lua_isnoneornil(L, 9) then
  1023                 gear^.AdvBounce := lua_tointeger(L, 9);
  1023                 gear^.AdvBounce := Trunc(lua_tonumber(L, 9));
  1024             if not lua_isnoneornil(L, 10) then
  1024             if not lua_isnoneornil(L, 10) then
  1025                 gear^.ImpactSound := TSound(lua_tointeger(L, 10));
  1025                 gear^.ImpactSound := TSound(Trunc(lua_tonumber(L, 10)));
  1026             if not lua_isnoneornil(L, 11) then
  1026             if not lua_isnoneornil(L, 11) then
  1027                 gear^.nImpactSounds := lua_tointeger(L, 11);
  1027                 gear^.nImpactSounds := Trunc(lua_tonumber(L, 11));
  1028             if not lua_isnoneornil(L, 12) then
  1028             if not lua_isnoneornil(L, 12) then
  1029                 gear^.Tint := lua_tointeger(L, 12);
  1029                 gear^.Tint := Trunc(lua_tonumber(L, 12));
  1030             if not lua_isnoneornil(L, 13) then
  1030             if not lua_isnoneornil(L, 13) then
  1031                 gear^.Damage := lua_tointeger(L, 13);
  1031                 gear^.Damage := Trunc(lua_tonumber(L, 13));
  1032             if not lua_isnoneornil(L, 14) then
  1032             if not lua_isnoneornil(L, 14) then
  1033                 gear^.Boom := lua_tointeger(L, 14);
  1033                 gear^.Boom := Trunc(lua_tonumber(L, 14));
  1034             end;
  1034             end;
  1035 //        end
  1035 //        end
  1036 //    else
  1036 //    else
  1037 //        lua_pushnil(L); // return value on stack (nil)
  1037 //        lua_pushnil(L); // return value on stack (nil)
  1038     lc_setgearvalues:= 0
  1038     lc_setgearvalues:= 0
  1043     if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then
  1043     if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then
  1044         begin
  1044         begin
  1045         if FollowGear = nil then
  1045         if FollowGear = nil then
  1046             lua_pushnil(L)
  1046             lua_pushnil(L)
  1047         else
  1047         else
  1048             lua_pushinteger(L, FollowGear^.uid);
  1048             lua_pushnumber(L, FollowGear^.uid);
  1049         end
  1049         end
  1050     else
  1050     else
  1051         lua_pushnil(L);
  1051         lua_pushnil(L);
  1052     lc_getfollowgear:= 1; // 1 return value
  1052     lc_getfollowgear:= 1; // 1 return value
  1053 end;
  1053 end;
  1055 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
  1055 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
  1056 var gear : PGear;
  1056 var gear : PGear;
  1057 begin
  1057 begin
  1058     if CheckLuaParamCount(L, 1, 'GetGearType', 'gearUid') then
  1058     if CheckLuaParamCount(L, 1, 'GetGearType', 'gearUid') then
  1059         begin
  1059         begin
  1060         gear:= GearByUID(lua_tointeger(L, 1));
  1060         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1061         if gear <> nil then
  1061         if gear <> nil then
  1062             lua_pushinteger(L, ord(gear^.Kind))
  1062             lua_pushnumber(L, ord(gear^.Kind))
  1063         else
  1063         else
  1064             lua_pushnil(L);
  1064             lua_pushnil(L);
  1065         end
  1065         end
  1066     else
  1066     else
  1067         lua_pushnil(L); // return value on stack (nil)
  1067         lua_pushnil(L); // return value on stack (nil)
  1071 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl;
  1071 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl;
  1072 var gear : PGear;
  1072 var gear : PGear;
  1073 begin
  1073 begin
  1074     if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then
  1074     if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then
  1075         begin
  1075         begin
  1076         gear:= GearByUID(lua_tointeger(L, 1));
  1076         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1077         if gear <> nil then
  1077         if gear <> nil then
  1078             lua_pushinteger(L, gear^.message)
  1078             lua_pushnumber(L, gear^.message)
  1079         else
  1079         else
  1080             lua_pushnil(L);
  1080             lua_pushnil(L);
  1081         end
  1081         end
  1082     else
  1082     else
  1083         lua_pushnil(L); // return value on stack (nil)
  1083         lua_pushnil(L); // return value on stack (nil)
  1087 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl;
  1087 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl;
  1088 var gear : PGear;
  1088 var gear : PGear;
  1089 begin
  1089 begin
  1090     if CheckLuaParamCount(L, 1, 'GetGearElasticity', 'gearUid') then
  1090     if CheckLuaParamCount(L, 1, 'GetGearElasticity', 'gearUid') then
  1091         begin
  1091         begin
  1092         gear:= GearByUID(lua_tointeger(L, 1));
  1092         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1093         if gear <> nil then
  1093         if gear <> nil then
  1094             lua_pushinteger(L, hwRound(gear^.elasticity * _10000))
  1094             lua_pushnumber(L, hwRound(gear^.elasticity * _10000))
  1095         else
  1095         else
  1096             lua_pushnil(L);
  1096             lua_pushnil(L);
  1097         end
  1097         end
  1098     else
  1098     else
  1099         lua_pushnil(L); // return value on stack (nil)
  1099         lua_pushnil(L); // return value on stack (nil)
  1103 function lc_setgearelasticity(L : Plua_State) : LongInt; Cdecl;
  1103 function lc_setgearelasticity(L : Plua_State) : LongInt; Cdecl;
  1104 var gear: PGear;
  1104 var gear: PGear;
  1105 begin
  1105 begin
  1106     if CheckLuaParamCount(L, 2, 'SetGearElasticity', 'gearUid, Elasticity') then
  1106     if CheckLuaParamCount(L, 2, 'SetGearElasticity', 'gearUid, Elasticity') then
  1107         begin
  1107         begin
  1108         gear:= GearByUID(lua_tointeger(L, 1));
  1108         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1109         if gear <> nil then
  1109         if gear <> nil then
  1110             gear^.Elasticity:= int2hwFloat(lua_tointeger(L, 2)) / 10000
  1110             gear^.Elasticity:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 10000
  1111         end;
  1111         end;
  1112     lc_setgearelasticity:= 0
  1112     lc_setgearelasticity:= 0
  1113 end;
  1113 end;
  1114 
  1114 
  1115 function lc_getgearfriction(L : Plua_State) : LongInt; Cdecl;
  1115 function lc_getgearfriction(L : Plua_State) : LongInt; Cdecl;
  1116 var gear : PGear;
  1116 var gear : PGear;
  1117 begin
  1117 begin
  1118     if CheckLuaParamCount(L, 1, 'GetGearFriction', 'gearUid') then
  1118     if CheckLuaParamCount(L, 1, 'GetGearFriction', 'gearUid') then
  1119         begin
  1119         begin
  1120         gear:= GearByUID(lua_tointeger(L, 1));
  1120         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1121         if gear <> nil then
  1121         if gear <> nil then
  1122             lua_pushinteger(L, hwRound(gear^.friction * _10000))
  1122             lua_pushnumber(L, hwRound(gear^.friction * _10000))
  1123         else
  1123         else
  1124             lua_pushnil(L);
  1124             lua_pushnil(L);
  1125         end
  1125         end
  1126     else
  1126     else
  1127         lua_pushnil(L); // return value on stack (nil)
  1127         lua_pushnil(L); // return value on stack (nil)
  1131 function lc_setgearfriction(L : Plua_State) : LongInt; Cdecl;
  1131 function lc_setgearfriction(L : Plua_State) : LongInt; Cdecl;
  1132 var gear: PGear;
  1132 var gear: PGear;
  1133 begin
  1133 begin
  1134     if CheckLuaParamCount(L, 2, 'SetGearFriction', 'gearUid, Friction') then
  1134     if CheckLuaParamCount(L, 2, 'SetGearFriction', 'gearUid, Friction') then
  1135         begin
  1135         begin
  1136         gear:= GearByUID(lua_tointeger(L, 1));
  1136         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1137         if gear <> nil then
  1137         if gear <> nil then
  1138             gear^.Friction:= int2hwFloat(lua_tointeger(L, 2)) / 10000
  1138             gear^.Friction:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 10000
  1139         end;
  1139         end;
  1140     lc_setgearfriction:= 0
  1140     lc_setgearfriction:= 0
  1141 end;
  1141 end;
  1142 
  1142 
  1143 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl;
  1143 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl;
  1144 var gear : PGear;
  1144 var gear : PGear;
  1145 begin
  1145 begin
  1146     if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then
  1146     if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then
  1147         begin
  1147         begin
  1148         gear:= GearByUID(lua_tointeger(L, 1));
  1148         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1149         if gear <> nil then
  1149         if gear <> nil then
  1150             gear^.message:= lua_tointeger(L, 2);
  1150             gear^.message:= Trunc(lua_tonumber(L, 2));
  1151         end;
  1151         end;
  1152     lc_setgearmessage:= 0
  1152     lc_setgearmessage:= 0
  1153 end;
  1153 end;
  1154 
  1154 
  1155 function lc_getgearpos(L : Plua_State) : LongInt; Cdecl;
  1155 function lc_getgearpos(L : Plua_State) : LongInt; Cdecl;
  1156 var gear : PGear;
  1156 var gear : PGear;
  1157 begin
  1157 begin
  1158     if CheckLuaParamCount(L, 1, 'GetGearPos', 'gearUid') then
  1158     if CheckLuaParamCount(L, 1, 'GetGearPos', 'gearUid') then
  1159         begin
  1159         begin
  1160         gear:= GearByUID(lua_tointeger(L, 1));
  1160         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1161         if gear <> nil then
  1161         if gear <> nil then
  1162             lua_pushinteger(L, gear^.Pos)
  1162             lua_pushnumber(L, gear^.Pos)
  1163         else
  1163         else
  1164             lua_pushnil(L);
  1164             lua_pushnil(L);
  1165         end
  1165         end
  1166     else
  1166     else
  1167         lua_pushnil(L); // return value on stack (nil)
  1167         lua_pushnil(L); // return value on stack (nil)
  1171 function lc_setgearpos(L : Plua_State) : LongInt; Cdecl;
  1171 function lc_setgearpos(L : Plua_State) : LongInt; Cdecl;
  1172 var gear : PGear;
  1172 var gear : PGear;
  1173 begin
  1173 begin
  1174     if CheckLuaParamCount(L, 2, 'SetGearPos', 'gearUid, value') then
  1174     if CheckLuaParamCount(L, 2, 'SetGearPos', 'gearUid, value') then
  1175         begin
  1175         begin
  1176         gear:= GearByUID(lua_tointeger(L, 1));
  1176         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1177         if gear <> nil then
  1177         if gear <> nil then
  1178             gear^.Pos:= lua_tointeger(L, 2);
  1178             gear^.Pos:= Trunc(lua_tonumber(L, 2));
  1179         end;
  1179         end;
  1180     lc_setgearpos:= 0
  1180     lc_setgearpos:= 0
  1181 end;
  1181 end;
  1182 
  1182 
  1183 function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
  1183 function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
  1184 var gear : PGear;
  1184 var gear : PGear;
  1185 begin
  1185 begin
  1186     if CheckLuaParamCount(L, 1, 'GetGearCollisionMask', 'gearUid') then
  1186     if CheckLuaParamCount(L, 1, 'GetGearCollisionMask', 'gearUid') then
  1187         begin
  1187         begin
  1188         gear:= GearByUID(lua_tointeger(L, 1));
  1188         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1189         if gear <> nil then
  1189         if gear <> nil then
  1190             lua_pushinteger(L, gear^.CollisionMask)
  1190             lua_pushnumber(L, gear^.CollisionMask)
  1191         else
  1191         else
  1192             lua_pushnil(L);
  1192             lua_pushnil(L);
  1193         end
  1193         end
  1194     else
  1194     else
  1195         lua_pushnil(L); // return value on stack (nil)
  1195         lua_pushnil(L); // return value on stack (nil)
  1199 function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
  1199 function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
  1200 var gear : PGear;
  1200 var gear : PGear;
  1201 begin
  1201 begin
  1202     if CheckLuaParamCount(L, 2, 'SetGearCollisionMask', 'gearUid, mask') then
  1202     if CheckLuaParamCount(L, 2, 'SetGearCollisionMask', 'gearUid, mask') then
  1203         begin
  1203         begin
  1204         gear:= GearByUID(lua_tointeger(L, 1));
  1204         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1205         if gear <> nil then
  1205         if gear <> nil then
  1206             gear^.CollisionMask:= lua_tointeger(L, 2);
  1206             gear^.CollisionMask:= Trunc(lua_tonumber(L, 2));
  1207         end;
  1207         end;
  1208     lc_setgearcollisionmask:= 0
  1208     lc_setgearcollisionmask:= 0
  1209 end;
  1209 end;
  1210 
  1210 
  1211 function lc_gethoglevel(L : Plua_State): LongInt; Cdecl;
  1211 function lc_gethoglevel(L : Plua_State): LongInt; Cdecl;
  1212 var gear : PGear;
  1212 var gear : PGear;
  1213 begin
  1213 begin
  1214     if CheckLuaParamCount(L, 1, 'GetHogLevel', 'gearUid') then
  1214     if CheckLuaParamCount(L, 1, 'GetHogLevel', 'gearUid') then
  1215         begin
  1215         begin
  1216         gear := GearByUID(lua_tointeger(L, 1));
  1216         gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  1217         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1217         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1218             lua_pushinteger(L, gear^.Hedgehog^.BotLevel)
  1218             lua_pushnumber(L, gear^.Hedgehog^.BotLevel)
  1219         else
  1219         else
  1220             lua_pushnil(L);
  1220             lua_pushnil(L);
  1221     end;
  1221     end;
  1222     lc_gethoglevel := 1;
  1222     lc_gethoglevel := 1;
  1223 end;
  1223 end;
  1225 function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl;
  1225 function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl;
  1226 var gear : PGear;
  1226 var gear : PGear;
  1227 begin
  1227 begin
  1228     if CheckLuaParamCount(L, 2, 'SetHogLevel', 'gearUid, level') then
  1228     if CheckLuaParamCount(L, 2, 'SetHogLevel', 'gearUid, level') then
  1229         begin
  1229         begin
  1230         gear:= GearByUID(lua_tointeger(L, 1));
  1230         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1231         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1231         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1232             gear^.Hedgehog^.BotLevel:= lua_tointeger(L, 2);
  1232             gear^.Hedgehog^.BotLevel:= Trunc(lua_tonumber(L, 2));
  1233         end;
  1233         end;
  1234     lc_sethoglevel:= 0
  1234     lc_sethoglevel:= 0
  1235 end;
  1235 end;
  1236 
  1236 
  1237 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
  1237 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
  1238 var gear : PGear;
  1238 var gear : PGear;
  1239 begin
  1239 begin
  1240     if CheckLuaParamCount(L, 1, 'GetHogClan', 'gearUid') then
  1240     if CheckLuaParamCount(L, 1, 'GetHogClan', 'gearUid') then
  1241         begin
  1241         begin
  1242         gear:= GearByUID(lua_tointeger(L, 1));
  1242         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1243         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1243         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1244             begin
  1244             begin
  1245             lua_pushinteger(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex)
  1245             lua_pushnumber(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex)
  1246             end
  1246             end
  1247         else
  1247         else
  1248             lua_pushnil(L);
  1248             lua_pushnil(L);
  1249         end
  1249         end
  1250     else
  1250     else
  1255 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl;
  1255 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl;
  1256 var idx: integer;
  1256 var idx: integer;
  1257 begin
  1257 begin
  1258     if CheckLuaParamCount(L, 1, 'GetClanColor', 'clanIdx') then
  1258     if CheckLuaParamCount(L, 1, 'GetClanColor', 'clanIdx') then
  1259         begin
  1259         begin
  1260         idx:= lua_tointeger(L, 1);
  1260         idx:= Trunc(lua_tonumber(L, 1));
  1261         if (not lua_isnumber(L, 1)) then
  1261         if (not lua_isnumber(L, 1)) then
  1262             begin
  1262             begin
  1263             LuaError('Argument ''clanIdx'' must be a number!');
  1263             LuaError('Argument ''clanIdx'' must be a number!');
  1264             lua_pushnil(L);
  1264             lua_pushnil(L);
  1265             end
  1265             end
  1267             begin
  1267             begin
  1268             LuaError('Argument ''clanIdx'' out of range! (There are currently ' + IntToStr(ClansCount) + ' clans, so valid range is: 0-' + IntToStr(ClansCount-1) + ')');
  1268             LuaError('Argument ''clanIdx'' out of range! (There are currently ' + IntToStr(ClansCount) + ' clans, so valid range is: 0-' + IntToStr(ClansCount-1) + ')');
  1269             lua_pushnil(L);
  1269             lua_pushnil(L);
  1270             end
  1270             end
  1271         else
  1271         else
  1272             lua_pushinteger(L, ClansArray[idx]^.Color shl 8 or $FF);
  1272             lua_pushnumber(L, ClansArray[idx]^.Color shl 8 or $FF);
  1273         end
  1273         end
  1274     else
  1274     else
  1275         lua_pushnil(L); // return value on stack (nil)
  1275         lua_pushnil(L); // return value on stack (nil)
  1276     lc_getclancolor:= 1
  1276     lc_getclancolor:= 1
  1277 end;
  1277 end;
  1282     hh   : THedgehog;
  1282     hh   : THedgehog;
  1283     i, j : LongInt;
  1283     i, j : LongInt;
  1284 begin
  1284 begin
  1285     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
  1285     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
  1286         begin
  1286         begin
  1287         i:= lua_tointeger(L,1);
  1287         i:= Trunc(lua_tonumber(L,1));
  1288         if i >= ClansCount then exit(0);
  1288         if i >= ClansCount then exit(0);
  1289         clan := ClansArray[i];
  1289         clan := ClansArray[i];
  1290         clan^.Color:= lua_tointeger(L, 2) shr 8;
  1290         clan^.Color:= Trunc(lua_tonumber(L, 2)) shr 8;
  1291 
  1291 
  1292         for i:= 0 to Pred(clan^.TeamsNumber) do
  1292         for i:= 0 to Pred(clan^.TeamsNumber) do
  1293             begin
  1293             begin
  1294             team:= clan^.Teams[i];
  1294             team:= clan^.Teams[i];
  1295             for j:= 0 to 7 do
  1295             for j:= 0 to 7 do
  1316 function lc_gethogvoicepack(L : Plua_State) : LongInt; Cdecl;
  1316 function lc_gethogvoicepack(L : Plua_State) : LongInt; Cdecl;
  1317 var gear : PGear;
  1317 var gear : PGear;
  1318 begin
  1318 begin
  1319     if CheckLuaParamCount(L, 1, 'GetHogVoicepack', 'gearUid') then
  1319     if CheckLuaParamCount(L, 1, 'GetHogVoicepack', 'gearUid') then
  1320         begin
  1320         begin
  1321         gear:= GearByUID(lua_tointeger(L, 1));
  1321         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1322         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1322         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1323             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Voicepack^.name))
  1323             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Voicepack^.name))
  1324         else
  1324         else
  1325             lua_pushnil(L);
  1325             lua_pushnil(L);
  1326         end
  1326         end
  1332 function lc_gethoggrave(L : Plua_State) : LongInt; Cdecl;
  1332 function lc_gethoggrave(L : Plua_State) : LongInt; Cdecl;
  1333 var gear : PGear;
  1333 var gear : PGear;
  1334 begin
  1334 begin
  1335     if CheckLuaParamCount(L, 1, 'GetHogGrave', 'gearUid') then
  1335     if CheckLuaParamCount(L, 1, 'GetHogGrave', 'gearUid') then
  1336         begin
  1336         begin
  1337         gear:= GearByUID(lua_tointeger(L, 1));
  1337         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1338         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1338         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1339             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.GraveName))
  1339             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.GraveName))
  1340         else
  1340         else
  1341             lua_pushnil(L);
  1341             lua_pushnil(L);
  1342         end
  1342         end
  1348 function lc_gethogflag(L : Plua_State) : LongInt; Cdecl;
  1348 function lc_gethogflag(L : Plua_State) : LongInt; Cdecl;
  1349 var gear : PGear;
  1349 var gear : PGear;
  1350 begin
  1350 begin
  1351     if CheckLuaParamCount(L, 1, 'GetHogFlag', 'gearUid') then
  1351     if CheckLuaParamCount(L, 1, 'GetHogFlag', 'gearUid') then
  1352         begin
  1352         begin
  1353         gear:= GearByUID(lua_tointeger(L, 1));
  1353         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1354         // TODO error messages
  1354         // TODO error messages
  1355         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1355         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1356             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Flag))
  1356             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Flag))
  1357         else
  1357         else
  1358             lua_pushnil(L);
  1358             lua_pushnil(L);
  1365 function lc_gethogfort(L : Plua_State) : LongInt; Cdecl;
  1365 function lc_gethogfort(L : Plua_State) : LongInt; Cdecl;
  1366 var gear : PGear;
  1366 var gear : PGear;
  1367 begin
  1367 begin
  1368     if CheckLuaParamCount(L, 1, 'GetHogFort', 'gearUid') then
  1368     if CheckLuaParamCount(L, 1, 'GetHogFort', 'gearUid') then
  1369         begin
  1369         begin
  1370         gear:= GearByUID(lua_tointeger(L, 1));
  1370         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1371         // TODO error messages
  1371         // TODO error messages
  1372         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1372         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1373             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.FortName))
  1373             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.FortName))
  1374         else
  1374         else
  1375             lua_pushnil(L);
  1375             lua_pushnil(L);
  1382 function lc_ishoglocal(L : Plua_State) : LongInt; Cdecl;
  1382 function lc_ishoglocal(L : Plua_State) : LongInt; Cdecl;
  1383 var gear : PGear;
  1383 var gear : PGear;
  1384 begin
  1384 begin
  1385     if CheckLuaParamCount(L, 1, 'IsHogLocal', 'gearUid') then
  1385     if CheckLuaParamCount(L, 1, 'IsHogLocal', 'gearUid') then
  1386         begin
  1386         begin
  1387         gear:= GearByUID(lua_tointeger(L, 1));
  1387         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1388         // TODO error messages
  1388         // TODO error messages
  1389         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1389         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1390             lua_pushboolean(L, IsHogLocal(gear^.Hedgehog))
  1390             lua_pushboolean(L, IsHogLocal(gear^.Hedgehog))
  1391         else
  1391         else
  1392             lua_pushnil(L);
  1392             lua_pushnil(L);
  1399 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
  1399 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
  1400 var gear : PGear;
  1400 var gear : PGear;
  1401 begin
  1401 begin
  1402     if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then
  1402     if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then
  1403         begin
  1403         begin
  1404         gear:= GearByUID(lua_tointeger(L, 1));
  1404         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1405         // TODO error messages
  1405         // TODO error messages
  1406         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1406         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1407             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName))
  1407             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName))
  1408         else
  1408         else
  1409             lua_pushnil(L);
  1409             lua_pushnil(L);
  1416 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl;
  1416 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl;
  1417 var gear : PGear;
  1417 var gear : PGear;
  1418 begin
  1418 begin
  1419     if CheckLuaParamCount(L, 2, 'SetHogTeamName', 'gearUid, name') then
  1419     if CheckLuaParamCount(L, 2, 'SetHogTeamName', 'gearUid, name') then
  1420         begin
  1420         begin
  1421         gear := GearByUID(lua_tointeger(L, 1));
  1421         gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  1422         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1422         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1423             begin
  1423             begin
  1424             gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2);
  1424             gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2);
  1425 
  1425 
  1426             FreeAndNilTexture(gear^.Hedgehog^.Team^.NameTagTex);
  1426             FreeAndNilTexture(gear^.Hedgehog^.Team^.NameTagTex);
  1437 function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
  1437 function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
  1438 var gear : PGear;
  1438 var gear : PGear;
  1439 begin
  1439 begin
  1440     if CheckLuaParamCount(L, 1, 'GetHogName', 'gearUid') then
  1440     if CheckLuaParamCount(L, 1, 'GetHogName', 'gearUid') then
  1441         begin
  1441         begin
  1442         gear:= GearByUID(lua_tointeger(L, 1));
  1442         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1443         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1443         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1444             begin
  1444             begin
  1445             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name))
  1445             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name))
  1446             end
  1446             end
  1447         else
  1447         else
  1455 function lc_sethogname(L : Plua_State) : LongInt; Cdecl;
  1455 function lc_sethogname(L : Plua_State) : LongInt; Cdecl;
  1456 var gear : PGear;
  1456 var gear : PGear;
  1457 begin
  1457 begin
  1458     if CheckLuaParamCount(L, 2, 'SetHogName', 'gearUid, name') then
  1458     if CheckLuaParamCount(L, 2, 'SetHogName', 'gearUid, name') then
  1459         begin
  1459         begin
  1460         gear:= GearByUID(lua_tointeger(L, 1));
  1460         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1461         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1461         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1462             begin
  1462             begin
  1463             gear^.Hedgehog^.Name:= lua_tostring(L, 2);
  1463             gear^.Hedgehog^.Name:= lua_tostring(L, 2);
  1464 
  1464 
  1465             FreeAndNilTexture(gear^.Hedgehog^.NameTagTex);
  1465             FreeAndNilTexture(gear^.Hedgehog^.NameTagTex);
  1472 function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
  1472 function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
  1473 var gear : PGear;
  1473 var gear : PGear;
  1474 begin
  1474 begin
  1475     if CheckLuaParamCount(L, 1, 'GetTimer', 'gearUid') then
  1475     if CheckLuaParamCount(L, 1, 'GetTimer', 'gearUid') then
  1476         begin
  1476         begin
  1477         gear:= GearByUID(lua_tointeger(L, 1));
  1477         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1478         if gear <> nil then
  1478         if gear <> nil then
  1479             lua_pushinteger(L, gear^.Timer)
  1479             lua_pushnumber(L, gear^.Timer)
  1480         else
  1480         else
  1481             lua_pushnil(L);
  1481             lua_pushnil(L);
  1482         end
  1482         end
  1483     else
  1483     else
  1484         lua_pushnil(L); // return value on stack (nil)
  1484         lua_pushnil(L); // return value on stack (nil)
  1488 function lc_getflighttime(L : Plua_State) : LongInt; Cdecl;
  1488 function lc_getflighttime(L : Plua_State) : LongInt; Cdecl;
  1489 var gear : PGear;
  1489 var gear : PGear;
  1490 begin
  1490 begin
  1491     if CheckLuaParamCount(L, 1, 'GetFlightTime', 'gearUid') then
  1491     if CheckLuaParamCount(L, 1, 'GetFlightTime', 'gearUid') then
  1492         begin
  1492         begin
  1493         gear:= GearByUID(lua_tointeger(L, 1));
  1493         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1494         if gear <> nil then
  1494         if gear <> nil then
  1495             lua_pushinteger(L, gear^.FlightTime)
  1495             lua_pushnumber(L, gear^.FlightTime)
  1496         else
  1496         else
  1497             lua_pushnil(L);
  1497             lua_pushnil(L);
  1498         end
  1498         end
  1499     else
  1499     else
  1500         lua_pushnil(L); // return value on stack (nil)
  1500         lua_pushnil(L); // return value on stack (nil)
  1504 function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
  1504 function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
  1505 var gear : PGear;
  1505 var gear : PGear;
  1506 begin
  1506 begin
  1507     if CheckLuaParamCount(L, 1, 'GetHealth', 'gearUid') then
  1507     if CheckLuaParamCount(L, 1, 'GetHealth', 'gearUid') then
  1508         begin
  1508         begin
  1509         gear:= GearByUID(lua_tointeger(L, 1));
  1509         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1510         if gear <> nil then
  1510         if gear <> nil then
  1511             lua_pushinteger(L, gear^.Health)
  1511             lua_pushnumber(L, gear^.Health)
  1512         else
  1512         else
  1513             lua_pushnil(L);
  1513             lua_pushnil(L);
  1514         end
  1514         end
  1515     else
  1515     else
  1516         lua_pushnil(L); // return value on stack (nil)
  1516         lua_pushnil(L); // return value on stack (nil)
  1520 function lc_getx(L : Plua_State) : LongInt; Cdecl;
  1520 function lc_getx(L : Plua_State) : LongInt; Cdecl;
  1521 var gear : PGear;
  1521 var gear : PGear;
  1522 begin
  1522 begin
  1523     if CheckLuaParamCount(L, 1, 'GetX', 'gearUid') then
  1523     if CheckLuaParamCount(L, 1, 'GetX', 'gearUid') then
  1524         begin
  1524         begin
  1525         gear:= GearByUID(lua_tointeger(L, 1));
  1525         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1526         if gear <> nil then
  1526         if gear <> nil then
  1527             lua_pushinteger(L, hwRound(gear^.X))
  1527             lua_pushnumber(L, hwRound(gear^.X))
  1528         else
  1528         else
  1529             lua_pushnil(L);
  1529             lua_pushnil(L);
  1530         end
  1530         end
  1531     else
  1531     else
  1532         lua_pushnil(L); // return value on stack (nil)
  1532         lua_pushnil(L); // return value on stack (nil)
  1536 function lc_gety(L : Plua_State) : LongInt; Cdecl;
  1536 function lc_gety(L : Plua_State) : LongInt; Cdecl;
  1537 var gear : PGear;
  1537 var gear : PGear;
  1538 begin
  1538 begin
  1539     if CheckLuaParamCount(L, 1, 'GetY', 'gearUid') then
  1539     if CheckLuaParamCount(L, 1, 'GetY', 'gearUid') then
  1540         begin
  1540         begin
  1541         gear:= GearByUID(lua_tointeger(L, 1));
  1541         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1542         if gear <> nil then
  1542         if gear <> nil then
  1543             lua_pushinteger(L, hwRound(gear^.Y))
  1543             lua_pushnumber(L, hwRound(gear^.Y))
  1544         else
  1544         else
  1545             lua_pushnil(L);
  1545             lua_pushnil(L);
  1546         end
  1546         end
  1547     else
  1547     else
  1548         lua_pushnil(L); // return value on stack (nil)
  1548         lua_pushnil(L); // return value on stack (nil)
  1552 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
  1552 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
  1553 var gears, geard : PGear;
  1553 var gears, geard : PGear;
  1554 begin
  1554 begin
  1555     if CheckLuaParamCount(L, 2, 'CopyPV', 'fromGearUid, toGearUid') then
  1555     if CheckLuaParamCount(L, 2, 'CopyPV', 'fromGearUid, toGearUid') then
  1556         begin
  1556         begin
  1557         gears:= GearByUID(lua_tointeger(L, 1));
  1557         gears:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1558         geard:= GearByUID(lua_tointeger(L, 2));
  1558         geard:= GearByUID(Trunc(lua_tonumber(L, 2)));
  1559         if (gears <> nil) and (geard <> nil) then
  1559         if (gears <> nil) and (geard <> nil) then
  1560             begin
  1560             begin
  1561             geard^.X:= gears^.X;
  1561             geard^.X:= gears^.X;
  1562             geard^.Y:= gears^.Y;
  1562             geard^.Y:= gears^.Y;
  1563             geard^.dX:= gears^.dX;
  1563             geard^.dX:= gears^.dX;
  1570 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
  1570 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
  1571 var gear : PGear;
  1571 var gear : PGear;
  1572 begin
  1572 begin
  1573     if CheckLuaParamCount(L, 1, 'FollowGear', 'gearUid') then
  1573     if CheckLuaParamCount(L, 1, 'FollowGear', 'gearUid') then
  1574         begin
  1574         begin
  1575         gear:= GearByUID(lua_tointeger(L, 1));
  1575         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1576         if gear <> nil then FollowGear:= gear
  1576         if gear <> nil then FollowGear:= gear
  1577         end;
  1577         end;
  1578     lc_followgear:= 0
  1578     lc_followgear:= 0
  1579 end;
  1579 end;
  1580 
  1580 
  1584        s : LongWord;
  1584        s : LongWord;
  1585        n : LongInt;
  1585        n : LongInt;
  1586 begin
  1586 begin
  1587     if CheckAndFetchParamCount(L, 3, 4, 'HogSay', 'gearUid, text, manner [, vgState]', n) then
  1587     if CheckAndFetchParamCount(L, 3, 4, 'HogSay', 'gearUid, text, manner [, vgState]', n) then
  1588         begin
  1588         begin
  1589         gear:= GearByUID(lua_tointeger(L, 1));
  1589         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1590         if gear <> nil then
  1590         if gear <> nil then
  1591             begin
  1591             begin
  1592             // state defaults to 0 if state param is given
  1592             // state defaults to 0 if state param is given
  1593             if n = 4 then
  1593             if n = 4 then
  1594                 s:= lua_tointeger(L, 4)
  1594                 s:= Trunc(lua_tonumber(L, 4))
  1595             else
  1595             else
  1596                 s:= 0;
  1596                 s:= 0;
  1597             vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true);
  1597             vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true);
  1598             if vgear <> nil then
  1598             if vgear <> nil then
  1599                begin
  1599                begin
  1603                    AddChatString(#9+'[' + gear^.Hedgehog^.Name + '] '+vgear^.text);
  1603                    AddChatString(#9+'[' + gear^.Hedgehog^.Name + '] '+vgear^.text);
  1604                    vgear^.Hedgehog:= gear^.Hedgehog
  1604                    vgear^.Hedgehog:= gear^.Hedgehog
  1605                    end
  1605                    end
  1606                else vgear^.Frame:= gear^.uid;
  1606                else vgear^.Frame:= gear^.uid;
  1607 
  1607 
  1608                vgear^.FrameTicks:= lua_tointeger(L, 3);
  1608                vgear^.FrameTicks:= Trunc(lua_tonumber(L, 3));
  1609                if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then
  1609                if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then
  1610                    vgear^.FrameTicks:= 1;
  1610                    vgear^.FrameTicks:= 1;
  1611                lua_pushinteger(L, vgear^.Uid);
  1611                lua_pushnumber(L, vgear^.Uid);
  1612                end
  1612                end
  1613             end
  1613             end
  1614         else
  1614         else
  1615             lua_pushnil(L)
  1615             lua_pushnil(L)
  1616         end
  1616         end
  1622 function lc_switchhog(L : Plua_State) : LongInt; Cdecl;
  1622 function lc_switchhog(L : Plua_State) : LongInt; Cdecl;
  1623 var gear, prevgear : PGear;
  1623 var gear, prevgear : PGear;
  1624 begin
  1624 begin
  1625     if CheckLuaParamCount(L, 1, 'SwitchHog', 'gearUid') then
  1625     if CheckLuaParamCount(L, 1, 'SwitchHog', 'gearUid') then
  1626         begin
  1626         begin
  1627         gear:= GearByUID(lua_tointeger(L, 1));
  1627         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1628 // should we allow this when there is no current hedgehog? might do some odd(er) things to turn sequence.
  1628 // should we allow this when there is no current hedgehog? might do some odd(er) things to turn sequence.
  1629         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (CurrentHedgehog <> nil) then
  1629         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (CurrentHedgehog <> nil) then
  1630             begin
  1630             begin
  1631             prevgear := CurrentHedgehog^.Gear;
  1631             prevgear := CurrentHedgehog^.Gear;
  1632             if prevgear <> nil then
  1632             if prevgear <> nil then
  1659     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1659     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1660         begin
  1660         begin
  1661         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1661         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1662         if at >= 0 then
  1662         if at >= 0 then
  1663             begin
  1663             begin
  1664             gear:= GearByUID(lua_tointeger(L, 1));
  1664             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1665             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1665             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1666                 if n = 2 then
  1666                 if n = 2 then
  1667                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
  1667                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
  1668                 else
  1668                 else
  1669                     SetAmmo(gear^.Hedgehog^, TAmmoType(at), lua_tointeger(L, 3))
  1669                     SetAmmo(gear^.Hedgehog^, TAmmoType(at), Trunc(lua_tonumber(L, 3)))
  1670             end;
  1670             end;
  1671         end;
  1671         end;
  1672     lc_addammo:= 0
  1672     lc_addammo:= 0
  1673 end;
  1673 end;
  1674 
  1674 
  1680     call = 'GetAmmoCount';
  1680     call = 'GetAmmoCount';
  1681     params = 'gearUid, ammoType';
  1681     params = 'gearUid, ammoType';
  1682 begin
  1682 begin
  1683     if CheckLuaParamCount(L, 2, call, params) then
  1683     if CheckLuaParamCount(L, 2, call, params) then
  1684         begin
  1684         begin
  1685         gear:= GearByUID(lua_tointeger(L, 1));
  1685         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1686         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1686         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1687             begin
  1687             begin
  1688             at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1688             at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1689             if at >= 0 then
  1689             if at >= 0 then
  1690                 begin
  1690                 begin
  1691                 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
  1691                 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
  1692                 if ammo^.AmmoType = amNothing then
  1692                 if ammo^.AmmoType = amNothing then
  1693                     lua_pushinteger(L, 0)
  1693                     lua_pushnumber(L, 0)
  1694                 else
  1694                 else
  1695                     lua_pushinteger(L, ammo^.Count);
  1695                     lua_pushnumber(L, ammo^.Count);
  1696                 end;
  1696                 end;
  1697             end
  1697             end
  1698         else lua_pushinteger(L, 0);
  1698         else lua_pushnumber(L, 0);
  1699         end
  1699         end
  1700     else
  1700     else
  1701         lua_pushnil(L);
  1701         lua_pushnil(L);
  1702     lc_getammocount:= 1
  1702     lc_getammocount:= 1
  1703 end;
  1703 end;
  1705 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
  1705 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
  1706 var gear : PGear;
  1706 var gear : PGear;
  1707 begin
  1707 begin
  1708     if CheckLuaParamCount(L, 2, 'SetHealth', 'gearUid, health') then
  1708     if CheckLuaParamCount(L, 2, 'SetHealth', 'gearUid, health') then
  1709         begin
  1709         begin
  1710         gear:= GearByUID(lua_tointeger(L, 1));
  1710         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1711         if gear <> nil then
  1711         if gear <> nil then
  1712             begin
  1712             begin
  1713             gear^.Health:= lua_tointeger(L, 2);
  1713             gear^.Health:= Trunc(lua_tonumber(L, 2));
  1714 
  1714 
  1715             if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1715             if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1716                 begin
  1716                 begin
  1717                 RenderHealth(gear^.Hedgehog^);
  1717                 RenderHealth(gear^.Hedgehog^);
  1718                 RecountTeamHealth(gear^.Hedgehog^.Team)
  1718                 RecountTeamHealth(gear^.Hedgehog^.Team)
  1729 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
  1729 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
  1730 var gear : PGear;
  1730 var gear : PGear;
  1731 begin
  1731 begin
  1732     if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then
  1732     if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then
  1733         begin
  1733         begin
  1734         gear:= GearByUID(lua_tointeger(L, 1));
  1734         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1735         if gear <> nil then gear^.Timer:= lua_tointeger(L, 2)
  1735         if gear <> nil then gear^.Timer:= Trunc(lua_tonumber(L, 2))
  1736         end;
  1736         end;
  1737     lc_settimer:= 0
  1737     lc_settimer:= 0
  1738 end;
  1738 end;
  1739 
  1739 
  1740 function lc_setflighttime(L : Plua_State) : LongInt; Cdecl;
  1740 function lc_setflighttime(L : Plua_State) : LongInt; Cdecl;
  1741 var gear : PGear;
  1741 var gear : PGear;
  1742 begin
  1742 begin
  1743     if CheckLuaParamCount(L, 2, 'SetFlightTime', 'gearUid, flighttime') then
  1743     if CheckLuaParamCount(L, 2, 'SetFlightTime', 'gearUid, flighttime') then
  1744         begin
  1744         begin
  1745         gear:= GearByUID(lua_tointeger(L, 1));
  1745         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1746         if gear <> nil then gear^.FlightTime:= lua_tointeger(L, 2)
  1746         if gear <> nil then gear^.FlightTime:= Trunc(lua_tonumber(L, 2))
  1747         end;
  1747         end;
  1748     lc_setflighttime:= 0
  1748     lc_setflighttime:= 0
  1749 end;
  1749 end;
  1750 
  1750 
  1751 function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
  1751 function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
  1758     if CheckLuaParamCount(L, 3, call, params) then
  1758     if CheckLuaParamCount(L, 3, call, params) then
  1759         begin
  1759         begin
  1760         t:= LuaToHogEffectOrd(L, 2, call, params);
  1760         t:= LuaToHogEffectOrd(L, 2, call, params);
  1761         if t >= 0 then
  1761         if t >= 0 then
  1762             begin
  1762             begin
  1763             gear := GearByUID(lua_tointeger(L, 1));
  1763             gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  1764             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1764             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1765                 gear^.Hedgehog^.Effects[THogEffect(t)]:= lua_tointeger(L, 3);
  1765                 gear^.Hedgehog^.Effects[THogEffect(t)]:= Trunc(lua_tonumber(L, 3));
  1766             end;
  1766             end;
  1767         end;
  1767         end;
  1768     lc_seteffect := 0;
  1768     lc_seteffect := 0;
  1769 end;
  1769 end;
  1770 
  1770 
  1778     if CheckLuaParamCount(L, 2, call, params) then
  1778     if CheckLuaParamCount(L, 2, call, params) then
  1779         begin
  1779         begin
  1780         t:= LuaToHogEffectOrd(L, 2, call, params);
  1780         t:= LuaToHogEffectOrd(L, 2, call, params);
  1781         if t >= 0 then
  1781         if t >= 0 then
  1782             begin
  1782             begin
  1783             gear:= GearByUID(lua_tointeger(L, 1));
  1783             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1784             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1784             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1785                 lua_pushinteger(L, gear^.Hedgehog^.Effects[THogEffect(t)])
  1785                 lua_pushnumber(L, gear^.Hedgehog^.Effects[THogEffect(t)])
  1786             else
  1786             else
  1787                 lua_pushinteger(L, 0)
  1787                 lua_pushnumber(L, 0)
  1788             end;
  1788             end;
  1789         end
  1789         end
  1790     else
  1790     else
  1791         lua_pushinteger(L, 0);
  1791         lua_pushnumber(L, 0);
  1792     lc_geteffect:= 1
  1792     lc_geteffect:= 1
  1793 end;
  1793 end;
  1794 
  1794 
  1795 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
  1795 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
  1796 var gear : PGear;
  1796 var gear : PGear;
  1797 begin
  1797 begin
  1798     if CheckLuaParamCount(L, 2, 'SetState', 'gearUid, state') then
  1798     if CheckLuaParamCount(L, 2, 'SetState', 'gearUid, state') then
  1799         begin
  1799         begin
  1800         gear:= GearByUID(lua_tointeger(L, 1));
  1800         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1801         if gear <> nil then
  1801         if gear <> nil then
  1802             begin
  1802             begin
  1803             gear^.State:= lua_tointeger(L, 2);
  1803             gear^.State:= Trunc(lua_tonumber(L, 2));
  1804             SetAllToActive;
  1804             SetAllToActive;
  1805             end
  1805             end
  1806         end;
  1806         end;
  1807     lc_setstate:= 0
  1807     lc_setstate:= 0
  1808 end;
  1808 end;
  1810 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
  1810 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
  1811 var gear : PGear;
  1811 var gear : PGear;
  1812 begin
  1812 begin
  1813     if CheckLuaParamCount(L, 1, 'GetState', 'gearUid') then
  1813     if CheckLuaParamCount(L, 1, 'GetState', 'gearUid') then
  1814         begin
  1814         begin
  1815         gear:= GearByUID(lua_tointeger(L, 1));
  1815         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1816         if gear <> nil then
  1816         if gear <> nil then
  1817             lua_pushinteger(L, gear^.State)
  1817             lua_pushnumber(L, gear^.State)
  1818         else
  1818         else
  1819             lua_pushnil(L)
  1819             lua_pushnil(L)
  1820         end
  1820         end
  1821     else
  1821     else
  1822         lua_pushnil(L); // return value on stack (nil)
  1822         lua_pushnil(L); // return value on stack (nil)
  1826 function lc_gettag(L : Plua_State) : LongInt; Cdecl;
  1826 function lc_gettag(L : Plua_State) : LongInt; Cdecl;
  1827 var gear : PGear;
  1827 var gear : PGear;
  1828 begin
  1828 begin
  1829     if CheckLuaParamCount(L, 1, 'GetTag', 'gearUid') then
  1829     if CheckLuaParamCount(L, 1, 'GetTag', 'gearUid') then
  1830         begin
  1830         begin
  1831         gear:= GearByUID(lua_tointeger(L, 1));
  1831         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1832         if gear <> nil then
  1832         if gear <> nil then
  1833             lua_pushinteger(L, gear^.Tag)
  1833             lua_pushnumber(L, gear^.Tag)
  1834         else
  1834         else
  1835             lua_pushnil(L);
  1835             lua_pushnil(L);
  1836         end
  1836         end
  1837     else
  1837     else
  1838         lua_pushnil(L); // return value on stack (nil)
  1838         lua_pushnil(L); // return value on stack (nil)
  1842 function lc_settag(L : Plua_State) : LongInt; Cdecl;
  1842 function lc_settag(L : Plua_State) : LongInt; Cdecl;
  1843 var gear : PGear;
  1843 var gear : PGear;
  1844 begin
  1844 begin
  1845     if CheckLuaParamCount(L, 2, 'SetTag', 'gearUid, tag') then
  1845     if CheckLuaParamCount(L, 2, 'SetTag', 'gearUid, tag') then
  1846         begin
  1846         begin
  1847         gear:= GearByUID(lua_tointeger(L, 1));
  1847         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1848         if gear <> nil then
  1848         if gear <> nil then
  1849             begin
  1849             begin
  1850             gear^.Tag:= lua_tointeger(L, 2);
  1850             gear^.Tag:= Trunc(lua_tonumber(L, 2));
  1851             SetAllToActive;
  1851             SetAllToActive;
  1852             end
  1852             end
  1853         end;
  1853         end;
  1854     lc_settag:= 0
  1854     lc_settag:= 0
  1855 end;
  1855 end;
  1950     tryhard: boolean;
  1950     tryhard: boolean;
  1951     left, right, n: LongInt;
  1951     left, right, n: LongInt;
  1952 begin
  1952 begin
  1953     if CheckAndFetchParamCount(L, 4, 5, 'FindPlace', 'gearUid, fall, left, right [, tryHarder]', n) then
  1953     if CheckAndFetchParamCount(L, 4, 5, 'FindPlace', 'gearUid, fall, left, right [, tryHarder]', n) then
  1954         begin
  1954         begin
  1955         gear:= GearByUID(lua_tointeger(L, 1));
  1955         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1956         fall:= lua_toboolean(L, 2);
  1956         fall:= lua_toboolean(L, 2);
  1957         left:= lua_tointeger(L, 3);
  1957         left:= Trunc(lua_tonumber(L, 3));
  1958         right:= lua_tointeger(L, 4);
  1958         right:= Trunc(lua_tonumber(L, 4));
  1959         if n = 5 then
  1959         if n = 5 then
  1960             tryhard:= lua_toboolean(L, 5)
  1960             tryhard:= lua_toboolean(L, 5)
  1961         else
  1961         else
  1962             tryhard:= false;
  1962             tryhard:= false;
  1963         if gear <> nil then
  1963         if gear <> nil then
  1964             FindPlace(gear, fall, left, right, tryhard);
  1964             FindPlace(gear, fall, left, right, tryhard);
  1965         if gear <> nil then
  1965         if gear <> nil then
  1966             lua_pushinteger(L, gear^.uid)
  1966             lua_pushnumber(L, gear^.uid)
  1967         else
  1967         else
  1968             lua_pushnil(L);
  1968             lua_pushnil(L);
  1969         end
  1969         end
  1970     else
  1970     else
  1971         lua_pushnil(L); // return value on stack (nil)
  1971         lua_pushnil(L); // return value on stack (nil)
  1987             // no gear specified
  1987             // no gear specified
  1988             if n = 1 then
  1988             if n = 1 then
  1989                 PlaySound(TSound(s))
  1989                 PlaySound(TSound(s))
  1990             else
  1990             else
  1991                 begin
  1991                 begin
  1992                 gear:= GearByUID(lua_tointeger(L, 2));
  1992                 gear:= GearByUID(Trunc(lua_tonumber(L, 2)));
  1993                 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1993                 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1994                     AddVoice(TSound(s),gear^.Hedgehog^.Team^.Voicepack)
  1994                     AddVoice(TSound(s),gear^.Hedgehog^.Team^.Voicepack)
  1995                 end;
  1995                 end;
  1996             end;
  1996             end;
  1997         end;
  1997         end;
  2008         ParseCommand('fort ' + lua_tostring(L, 4), true, true);
  2008         ParseCommand('fort ' + lua_tostring(L, 4), true, true);
  2009         ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
  2009         ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
  2010         if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
  2010         if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
  2011         CurrentTeam^.Binds:= DefaultBinds
  2011         CurrentTeam^.Binds:= DefaultBinds
  2012         // fails on x64
  2012         // fails on x64
  2013         //lua_pushinteger(L, LongInt(CurrentTeam));
  2013         //lua_pushnumber(L, LongInt(CurrentTeam));
  2014         end;
  2014         end;
  2015     //else
  2015     //else
  2016         //lua_pushnil(L)
  2016         //lua_pushnil(L)
  2017     lc_addteam:= 0;//1;
  2017     lc_addteam:= 0;//1;
  2018 end;
  2018 end;
  2066     if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then
  2066     if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then
  2067         begin
  2067         begin
  2068         temp:= lua_tostring(L, 4);
  2068         temp:= lua_tostring(L, 4);
  2069         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
  2069         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
  2070         ParseCommand('hat ' + temp, true, true);
  2070         ParseCommand('hat ' + temp, true, true);
  2071         lua_pushinteger(L, CurrentHedgehog^.Gear^.uid);
  2071         lua_pushnumber(L, CurrentHedgehog^.Gear^.uid);
  2072         end
  2072         end
  2073     else
  2073     else
  2074         lua_pushnil(L);
  2074         lua_pushnil(L);
  2075     lc_addhog:= 1;
  2075     lc_addhog:= 1;
  2076 end;
  2076 end;
  2078 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
  2078 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
  2079 var gear: PGear;
  2079 var gear: PGear;
  2080 begin
  2080 begin
  2081     if CheckLuaParamCount(L, 2, 'HogTurnLeft', 'gearUid, boolean') then
  2081     if CheckLuaParamCount(L, 2, 'HogTurnLeft', 'gearUid, boolean') then
  2082         begin
  2082         begin
  2083         gear:= GearByUID(lua_tointeger(L, 1));
  2083         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2084         if gear <> nil then
  2084         if gear <> nil then
  2085             gear^.dX.isNegative:= lua_toboolean(L, 2);
  2085             gear^.dX.isNegative:= lua_toboolean(L, 2);
  2086         end;
  2086         end;
  2087     lc_hogturnleft:= 0;
  2087     lc_hogturnleft:= 0;
  2088 end;
  2088 end;
  2090 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
  2090 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
  2091 var gear: PGear;
  2091 var gear: PGear;
  2092 begin
  2092 begin
  2093     if CheckLuaParamCount(L, 1, 'GetGearPosition', 'gearUid') then
  2093     if CheckLuaParamCount(L, 1, 'GetGearPosition', 'gearUid') then
  2094         begin
  2094         begin
  2095         gear:= GearByUID(lua_tointeger(L, 1));
  2095         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2096         if gear <> nil then
  2096         if gear <> nil then
  2097             begin
  2097             begin
  2098             lua_pushinteger(L, hwRound(gear^.X));
  2098             lua_pushnumber(L, hwRound(gear^.X));
  2099             lua_pushinteger(L, hwRound(gear^.Y))
  2099             lua_pushnumber(L, hwRound(gear^.Y))
  2100             end
  2100             end
  2101         else
  2101         else
  2102             begin
  2102             begin
  2103             lua_pushnil(L);
  2103             lua_pushnil(L);
  2104             lua_pushnil(L)
  2104             lua_pushnil(L)
  2117     col: boolean;
  2117     col: boolean;
  2118     x, y: LongInt;
  2118     x, y: LongInt;
  2119 begin
  2119 begin
  2120     if CheckLuaParamCount(L, 3, 'SetGearPosition', 'gearUid, x, y') then
  2120     if CheckLuaParamCount(L, 3, 'SetGearPosition', 'gearUid, x, y') then
  2121         begin
  2121         begin
  2122         gear:= GearByUID(lua_tointeger(L, 1));
  2122         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2123         if gear <> nil then
  2123         if gear <> nil then
  2124             begin
  2124             begin
  2125             col:= gear^.CollisionIndex >= 0;
  2125             col:= gear^.CollisionIndex >= 0;
  2126             x:= lua_tointeger(L, 2);
  2126             x:= Trunc(lua_tonumber(L, 2));
  2127             y:= lua_tointeger(L, 3);
  2127             y:= Trunc(lua_tonumber(L, 3));
  2128             if col then
  2128             if col then
  2129                 DeleteCI(gear);
  2129                 DeleteCI(gear);
  2130             gear^.X:= int2hwfloat(x);
  2130             gear^.X:= int2hwfloat(x);
  2131             gear^.Y:= int2hwfloat(y);
  2131             gear^.Y:= int2hwfloat(y);
  2132             if col then
  2132             if col then
  2140 function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl;
  2140 function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl;
  2141 var gear: PGear;
  2141 var gear: PGear;
  2142 begin
  2142 begin
  2143     if CheckLuaParamCount(L, 1, 'GetGearTarget', 'gearUid') then
  2143     if CheckLuaParamCount(L, 1, 'GetGearTarget', 'gearUid') then
  2144         begin
  2144         begin
  2145         gear:= GearByUID(lua_tointeger(L, 1));
  2145         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2146         if gear <> nil then
  2146         if gear <> nil then
  2147             begin
  2147             begin
  2148             lua_pushinteger(L, gear^.Target.X);
  2148             lua_pushnumber(L, gear^.Target.X);
  2149             lua_pushinteger(L, gear^.Target.Y)
  2149             lua_pushnumber(L, gear^.Target.Y)
  2150             end
  2150             end
  2151         else
  2151         else
  2152             begin
  2152             begin
  2153             lua_pushnil(L);
  2153             lua_pushnil(L);
  2154             lua_pushnil(L)
  2154             lua_pushnil(L)
  2165 function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl;
  2165 function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl;
  2166 var gear: PGear;
  2166 var gear: PGear;
  2167 begin
  2167 begin
  2168     if CheckLuaParamCount(L, 3, 'SetGearTarget', 'gearUid, x, y') then
  2168     if CheckLuaParamCount(L, 3, 'SetGearTarget', 'gearUid, x, y') then
  2169         begin
  2169         begin
  2170         gear:= GearByUID(lua_tointeger(L, 1));
  2170         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2171         if gear <> nil then
  2171         if gear <> nil then
  2172             begin
  2172             begin
  2173             gear^.Target.X:= lua_tointeger(L, 2);
  2173             gear^.Target.X:= Trunc(lua_tonumber(L, 2));
  2174             gear^.Target.Y:= lua_tointeger(L, 3)
  2174             gear^.Target.Y:= Trunc(lua_tonumber(L, 3))
  2175             end
  2175             end
  2176         end;
  2176         end;
  2177     lc_setgeartarget:= 0
  2177     lc_setgeartarget:= 0
  2178 end;
  2178 end;
  2179 
  2179 
  2181 var gear: PGear;
  2181 var gear: PGear;
  2182 var t: LongInt;
  2182 var t: LongInt;
  2183 begin
  2183 begin
  2184     if CheckLuaParamCount(L, 1, 'GetGearVelocity', 'gearUid') then
  2184     if CheckLuaParamCount(L, 1, 'GetGearVelocity', 'gearUid') then
  2185         begin
  2185         begin
  2186         gear:= GearByUID(lua_tointeger(L, 1));
  2186         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2187         if gear <> nil then
  2187         if gear <> nil then
  2188             begin
  2188             begin
  2189             t:= hwRound(gear^.dX * 1000000);
  2189             t:= hwRound(gear^.dX * 1000000);
  2190             // gear dX determines hog orientation
  2190             // gear dX determines hog orientation
  2191             if (gear^.dX.isNegative) and (t = 0) then t:= -1;
  2191             if (gear^.dX.isNegative) and (t = 0) then t:= -1;
  2192             lua_pushinteger(L, t);
  2192             lua_pushnumber(L, t);
  2193             lua_pushinteger(L, hwRound(gear^.dY * 1000000))
  2193             lua_pushnumber(L, hwRound(gear^.dY * 1000000))
  2194             end
  2194             end
  2195         end
  2195         end
  2196     else
  2196     else
  2197         begin
  2197         begin
  2198         lua_pushnil(L);
  2198         lua_pushnil(L);
  2204 function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl;
  2204 function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl;
  2205 var gear: PGear;
  2205 var gear: PGear;
  2206 begin
  2206 begin
  2207     if CheckLuaParamCount(L, 3, 'SetGearVelocity', 'gearUid, dx, dy') then
  2207     if CheckLuaParamCount(L, 3, 'SetGearVelocity', 'gearUid, dx, dy') then
  2208         begin
  2208         begin
  2209         gear:= GearByUID(lua_tointeger(L, 1));
  2209         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2210         if gear <> nil then
  2210         if gear <> nil then
  2211             begin
  2211             begin
  2212             gear^.dX:= int2hwFloat(lua_tointeger(L, 2)) / 1000000;
  2212             gear^.dX:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 1000000;
  2213             gear^.dY:= int2hwFloat(lua_tointeger(L, 3)) / 1000000;
  2213             gear^.dY:= int2hwFloat(Trunc(lua_tonumber(L, 3))) / 1000000;
  2214             SetAllToActive;
  2214             SetAllToActive;
  2215             end
  2215             end
  2216         end;
  2216         end;
  2217     lc_setgearvelocity:= 0
  2217     lc_setgearvelocity:= 0
  2218 end;
  2218 end;
  2249         begin
  2249         begin
  2250         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2250         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2251         if at >= 0 then
  2251         if at >= 0 then
  2252             begin
  2252             begin
  2253             if np = 4 then
  2253             if np = 4 then
  2254                 ScriptSetAmmo(TAmmoType(at), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
  2254                 ScriptSetAmmo(TAmmoType(at), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)), 1)
  2255             else
  2255             else
  2256                 ScriptSetAmmo(TAmmoType(at), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
  2256                 ScriptSetAmmo(TAmmoType(at), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)));
  2257             end;
  2257             end;
  2258         end;
  2258         end;
  2259     lc_setammo:= 0
  2259     lc_setammo:= 0
  2260 end;
  2260 end;
  2261 
  2261 
  2267 begin
  2267 begin
  2268     if CheckLuaParamCount(L, 2, call, params) then
  2268     if CheckLuaParamCount(L, 2, call, params) then
  2269         begin
  2269         begin
  2270         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2270         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2271         if at >= 0 then
  2271         if at >= 0 then
  2272             ScriptSetAmmoDelay(TAmmoType(at), lua_tointeger(L, 2));
  2272             ScriptSetAmmoDelay(TAmmoType(at), Trunc(lua_tonumber(L, 2)));
  2273         end;
  2273         end;
  2274     lc_setammodelay:= 0
  2274     lc_setammodelay:= 0
  2275 end;
  2275 end;
  2276 
  2276 
  2277 function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
  2277 function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
  2278 var m : LongInt;
  2278 var m : LongInt;
  2279 begin
  2279 begin
  2280     if CheckLuaParamCount(L, 1, 'GetRandom', 'number') then
  2280     if CheckLuaParamCount(L, 1, 'GetRandom', 'number') then
  2281         begin
  2281         begin
  2282         m:= lua_tointeger(L, 1);
  2282         m:= Trunc(lua_tonumber(L, 1));
  2283         if (m > 0) then
  2283         if (m > 0) then
  2284             lua_pushinteger(L, GetRandom(m))
  2284             lua_pushnumber(L, GetRandom(m))
  2285         else
  2285         else
  2286             begin
  2286             begin
  2287             LuaError('Lua: Tried to pass 0 to GetRandom!');
  2287             LuaError('Lua: Tried to pass 0 to GetRandom!');
  2288             lua_pushnil(L);
  2288             lua_pushnil(L);
  2289             end
  2289             end
  2295 
  2295 
  2296 function lc_setwind(L : Plua_State) : LongInt; Cdecl;
  2296 function lc_setwind(L : Plua_State) : LongInt; Cdecl;
  2297 begin
  2297 begin
  2298     if CheckLuaParamCount(L, 1, 'SetWind', 'windSpeed') then
  2298     if CheckLuaParamCount(L, 1, 'SetWind', 'windSpeed') then
  2299         begin
  2299         begin
  2300         cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed;
  2300         cWindSpeed:= int2hwfloat(Trunc(lua_tonumber(L, 1))) / 100 * cMaxWindSpeed;
  2301         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  2301         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  2302         if cWindSpeed.isNegative then
  2302         if cWindSpeed.isNegative then
  2303             CWindSpeedf := -cWindSpeedf;
  2303             CWindSpeedf := -cWindSpeedf;
  2304         AddVisualGear(0, 0, vgtSmoothWindBar);
  2304         AddVisualGear(0, 0, vgtSmoothWindBar);
  2305         end;
  2305         end;
  2318 function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
  2318 function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
  2319 var gear : PGear;
  2319 var gear : PGear;
  2320 begin
  2320 begin
  2321     if CheckLuaParamCount(L, 1, 'GetGearRadius', 'gearUid') then
  2321     if CheckLuaParamCount(L, 1, 'GetGearRadius', 'gearUid') then
  2322         begin
  2322         begin
  2323         gear:= GearByUID(lua_tointeger(L, 1));
  2323         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2324         if gear <> nil then
  2324         if gear <> nil then
  2325             lua_pushinteger(L, gear^.Radius)
  2325             lua_pushnumber(L, gear^.Radius)
  2326         else
  2326         else
  2327             lua_pushnil(L);
  2327             lua_pushnil(L);
  2328         end
  2328         end
  2329     else
  2329     else
  2330         lua_pushnil(L); // return value on stack (nil)
  2330         lua_pushnil(L); // return value on stack (nil)
  2334 function lc_gethoghat(L : Plua_State): LongInt; Cdecl;
  2334 function lc_gethoghat(L : Plua_State): LongInt; Cdecl;
  2335 var gear : PGear;
  2335 var gear : PGear;
  2336 begin
  2336 begin
  2337     if CheckLuaParamCount(L, 1, 'GetHogHat', 'gearUid') then
  2337     if CheckLuaParamCount(L, 1, 'GetHogHat', 'gearUid') then
  2338         begin
  2338         begin
  2339         gear := GearByUID(lua_tointeger(L, 1));
  2339         gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  2340         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  2340         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  2341             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat))
  2341             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat))
  2342         else
  2342         else
  2343             lua_pushnil(L);
  2343             lua_pushnil(L);
  2344         end
  2344         end
  2351 var gear : PGear;
  2351 var gear : PGear;
  2352     hat: ShortString;
  2352     hat: ShortString;
  2353 begin
  2353 begin
  2354     if CheckLuaParamCount(L, 2, 'SetHogHat', 'gearUid, hat') then
  2354     if CheckLuaParamCount(L, 2, 'SetHogHat', 'gearUid, hat') then
  2355         begin
  2355         begin
  2356         gear:= GearByUID(lua_tointeger(L, 1));
  2356         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2357         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  2357         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  2358             begin
  2358             begin
  2359             hat:= lua_tostring(L, 2);
  2359             hat:= lua_tostring(L, 2);
  2360             gear^.Hedgehog^.Hat:= hat;
  2360             gear^.Hedgehog^.Hat:= hat;
  2361             AddFileLog('Changed hat to: '+hat);
  2361             AddFileLog('Changed hat to: '+hat);
  2380 begin
  2380 begin
  2381     placed:= false;
  2381     placed:= false;
  2382     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2382     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2383         begin
  2383         begin
  2384         if not lua_isnoneornil(L, 5) then
  2384         if not lua_isnoneornil(L, 5) then
  2385             tint := lua_tointeger(L, 5)
  2385             tint := Trunc(lua_tonumber(L, 5))
  2386         else tint := $FFFFFFFF;
  2386         else tint := $FFFFFFFF;
  2387         if not lua_isnoneornil(L, 6) then
  2387         if not lua_isnoneornil(L, 6) then
  2388             behind := lua_toboolean(L, 6)
  2388             behind := lua_toboolean(L, 6)
  2389         else behind := false;
  2389         else behind := false;
  2390         if not lua_isnoneornil(L, 7) then
  2390         if not lua_isnoneornil(L, 7) then
  2395         else flipVert := false;
  2395         else flipVert := false;
  2396         lf:= 0;
  2396         lf:= 0;
  2397 
  2397 
  2398         // accept any amount of landflags, loop is never executed if n<9
  2398         // accept any amount of landflags, loop is never executed if n<9
  2399         for i:= 9 to n do
  2399         for i:= 9 to n do
  2400             lf:= lf or lua_tointeger(L, i);
  2400             lf:= lf or Trunc(lua_tonumber(L, i));
  2401 
  2401 
  2402         n:= LuaToSpriteOrd(L, 3, call, params);
  2402         n:= LuaToSpriteOrd(L, 3, call, params);
  2403         if n >= 0 then
  2403         if n >= 0 then
  2404             begin
  2404             begin
  2405             spr:= TSprite(n);
  2405             spr:= TSprite(n);
  2406             if SpritesData[spr].Surface = nil then
  2406             if SpritesData[spr].Surface = nil then
  2407                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2407                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2408             else
  2408             else
  2409                 placed:= ForcePlaceOnLand(
  2409                 placed:= ForcePlaceOnLand(
  2410                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
  2410                     Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
  2411                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
  2411                     Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
  2412                     spr, lua_tointeger(L, 4), lf, tint, behind, flipHoriz, flipVert);
  2412                     spr, Trunc(lua_tonumber(L, 4)), lf, tint, behind, flipHoriz, flipVert);
  2413             end;
  2413             end;
  2414         end;
  2414         end;
  2415 
  2415 
  2416     lua_pushboolean(L, placed);
  2416     lua_pushboolean(L, placed);
  2417     lc_placesprite:= 1
  2417     lc_placesprite:= 1
  2442         else flipVert := false;
  2442         else flipVert := false;
  2443         lf:= 0;
  2443         lf:= 0;
  2444 
  2444 
  2445         // accept any amount of landflags, loop is never executed if n<9
  2445         // accept any amount of landflags, loop is never executed if n<9
  2446         for i:= 9 to n do
  2446         for i:= 9 to n do
  2447             lf:= lf or lua_tointeger(L, i);
  2447             lf:= lf or Trunc(lua_tonumber(L, i));
  2448 
  2448 
  2449         n:= LuaToSpriteOrd(L, 3, call, params);
  2449         n:= LuaToSpriteOrd(L, 3, call, params);
  2450         if n >= 0 then
  2450         if n >= 0 then
  2451             begin
  2451             begin
  2452             spr:= TSprite(n);
  2452             spr:= TSprite(n);
  2453             if SpritesData[spr].Surface = nil then
  2453             if SpritesData[spr].Surface = nil then
  2454                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2454                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2455             else
  2455             else
  2456                 EraseLand(
  2456                 EraseLand(
  2457                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
  2457                     Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
  2458                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
  2458                     Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
  2459                     spr, lua_tointeger(L, 4), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
  2459                     spr, Trunc(lua_tonumber(L, 4)), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
  2460             end;
  2460             end;
  2461         end;
  2461         end;
  2462     lc_erasesprite:= 0
  2462     lc_erasesprite:= 0
  2463 end;
  2463 end;
  2464 
  2464 
  2466 var placed: boolean;
  2466 var placed: boolean;
  2467 begin
  2467 begin
  2468     placed:= false;
  2468     placed:= false;
  2469     if CheckLuaParamCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then
  2469     if CheckLuaParamCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then
  2470         placed:= TryPlaceOnLandSimple(
  2470         placed:= TryPlaceOnLandSimple(
  2471             lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2,
  2471             Trunc(lua_tonumber(L, 1)) - SpritesData[sprAmGirder].Width div 2,
  2472             lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2,
  2472             Trunc(lua_tonumber(L, 2)) - SpritesData[sprAmGirder].Height div 2,
  2473             sprAmGirder, lua_tointeger(L, 3), true, false);
  2473             sprAmGirder, Trunc(lua_tonumber(L, 3)), true, false);
  2474 
  2474 
  2475     lua_pushboolean(L, placed);
  2475     lua_pushboolean(L, placed);
  2476     lc_placegirder:= 1
  2476     lc_placegirder:= 1
  2477 end;
  2477 end;
  2478 
  2478 
  2480 var placed: boolean;
  2480 var placed: boolean;
  2481 begin
  2481 begin
  2482     placed:= false;
  2482     placed:= false;
  2483     if CheckLuaParamCount(L, 3, 'PlaceRubber', 'x, y, frameIdx') then
  2483     if CheckLuaParamCount(L, 3, 'PlaceRubber', 'x, y, frameIdx') then
  2484         placed:= TryPlaceOnLand(
  2484         placed:= TryPlaceOnLand(
  2485             lua_tointeger(L, 1) - SpritesData[sprAmRubber].Width div 2,
  2485             Trunc(lua_tonumber(L, 1)) - SpritesData[sprAmRubber].Width div 2,
  2486             lua_tointeger(L, 2) - SpritesData[sprAmRubber].Height div 2,
  2486             Trunc(lua_tonumber(L, 2)) - SpritesData[sprAmRubber].Height div 2,
  2487             sprAmRubber, lua_tointeger(L, 3), true, lfBouncy);
  2487             sprAmRubber, Trunc(lua_tonumber(L, 3)), true, lfBouncy);
  2488 
  2488 
  2489     lua_pushboolean(L, placed);
  2489     lua_pushboolean(L, placed);
  2490     lc_placerubber:= 1
  2490     lc_placerubber:= 1
  2491 end;
  2491 end;
  2492 
  2492 
  2493 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
  2493 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
  2494 begin
  2494 begin
  2495     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, 'GetCurAmmoType', '')) then
  2495     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, 'GetCurAmmoType', '')) then
  2496         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType))
  2496         lua_pushnumber(L, ord(CurrentHedgehog^.CurAmmoType))
  2497     else
  2497     else
  2498         lua_pushinteger(L, ord(amNothing));
  2498         lua_pushnumber(L, ord(amNothing));
  2499     lc_getcurammotype := 1;
  2499     lc_getcurammotype := 1;
  2500 end;
  2500 end;
  2501 
  2501 
  2502 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
  2502 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
  2503 begin
  2503 begin
  2517 function lc_hidehog(L: Plua_State): LongInt; Cdecl;
  2517 function lc_hidehog(L: Plua_State): LongInt; Cdecl;
  2518 var gear: PGear;
  2518 var gear: PGear;
  2519 begin
  2519 begin
  2520     if CheckLuaParamCount(L, 1, 'HideHog', 'gearUid') then
  2520     if CheckLuaParamCount(L, 1, 'HideHog', 'gearUid') then
  2521         begin
  2521         begin
  2522         gear:= GearByUID(lua_tointeger(L, 1));
  2522         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2523         HideHog(gear^.hedgehog)
  2523         HideHog(gear^.hedgehog)
  2524         end;
  2524         end;
  2525     lc_hidehog := 0;
  2525     lc_hidehog := 0;
  2526 end;
  2526 end;
  2527 
  2527 
  2529 var i, h: LongInt;
  2529 var i, h: LongInt;
  2530     uid: LongWord;
  2530     uid: LongWord;
  2531 begin
  2531 begin
  2532     if CheckLuaParamCount(L, 1, 'RestoreHog', 'gearUid') then
  2532     if CheckLuaParamCount(L, 1, 'RestoreHog', 'gearUid') then
  2533         begin
  2533         begin
  2534         uid:= LongWord(lua_tointeger(L, 1));
  2534         uid:= LongWord(Trunc(lua_tonumber(L, 1)));
  2535         if TeamsCount > 0 then
  2535         if TeamsCount > 0 then
  2536             for i:= 0 to Pred(TeamsCount) do
  2536             for i:= 0 to Pred(TeamsCount) do
  2537                 for h:= 0 to cMaxHHIndex do
  2537                 for h:= 0 to cMaxHHIndex do
  2538                     if (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil) and (TeamsArray[i]^.Hedgehogs[h].GearHidden^.uid = uid) then
  2538                     if (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil) and (TeamsArray[i]^.Hedgehogs[h].GearHidden^.uid = uid) then
  2539                         begin
  2539                         begin
  2549 var rtn: Boolean;
  2549 var rtn: Boolean;
  2550 begin
  2550 begin
  2551     if CheckLuaParamCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then
  2551     if CheckLuaParamCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then
  2552         begin
  2552         begin
  2553         rtn:= TestRectangleForObstacle(
  2553         rtn:= TestRectangleForObstacle(
  2554                     lua_tointeger(L, 1),
  2554                     Trunc(lua_tonumber(L, 1)),
  2555                     lua_tointeger(L, 2),
  2555                     Trunc(lua_tonumber(L, 2)),
  2556                     lua_tointeger(L, 3),
  2556                     Trunc(lua_tonumber(L, 3)),
  2557                     lua_tointeger(L, 4),
  2557                     Trunc(lua_tonumber(L, 4)),
  2558                     lua_toboolean(L, 5)
  2558                     lua_toboolean(L, 5)
  2559                     );
  2559                     );
  2560         lua_pushboolean(L, rtn);
  2560         lua_pushboolean(L, rtn);
  2561         end
  2561         end
  2562     else
  2562     else
  2566 
  2566 
  2567 
  2567 
  2568 function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
  2568 function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
  2569 begin
  2569 begin
  2570     if CheckLuaParamCount(L, 0, 'GetGravity', '') then
  2570     if CheckLuaParamCount(L, 0, 'GetGravity', '') then
  2571         lua_pushinteger(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed)));
  2571         lua_pushnumber(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed)));
  2572     lc_getgravity:= 1
  2572     lc_getgravity:= 1
  2573 end;
  2573 end;
  2574 
  2574 
  2575 function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
  2575 function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
  2576 begin
  2576 begin
  2577     if CheckLuaParamCount(L, 1, 'SetGravity', 'percent') then
  2577     if CheckLuaParamCount(L, 1, 'SetGravity', 'percent') then
  2578         begin
  2578         begin
  2579         cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed;
  2579         cGravity:= _0_02 * Trunc(lua_tonumber(L, 1)) * cMaxWindSpeed;
  2580         cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02
  2580         cGravityf:= 0.00025 * Trunc(lua_tonumber(L, 1)) * 0.02
  2581         end;
  2581         end;
  2582     lc_setgravity:= 0
  2582     lc_setgravity:= 0
  2583 end;
  2583 end;
  2584 
  2584 
  2585 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
  2585 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
  2586 var iterator: PGear;
  2586 var iterator: PGear;
  2587 begin
  2587 begin
  2588     if CheckLuaParamCount(L, 1, 'SetWaterLine', 'waterline') then
  2588     if CheckLuaParamCount(L, 1, 'SetWaterLine', 'waterline') then
  2589         begin
  2589         begin
  2590         cWaterLine:= lua_tointeger(L,1);
  2590         cWaterLine:= Trunc(lua_tonumber(L,1));
  2591         AllInactive:= false;
  2591         AllInactive:= false;
  2592         iterator:= GearsList;
  2592         iterator:= GearsList;
  2593         while iterator <> nil do
  2593         while iterator <> nil do
  2594             begin
  2594             begin
  2595             if not (iterator^.Kind in [gtPortal, gtAirAttack]) and (iterator^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) then
  2595             if not (iterator^.Kind in [gtPortal, gtAirAttack]) and (iterator^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) then
  2608 function lc_setgearaihints(L : Plua_State) : LongInt; Cdecl;
  2608 function lc_setgearaihints(L : Plua_State) : LongInt; Cdecl;
  2609 var gear: PGear;
  2609 var gear: PGear;
  2610 begin
  2610 begin
  2611     if CheckLuaParamCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then
  2611     if CheckLuaParamCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then
  2612         begin
  2612         begin
  2613         gear:= GearByUID(lua_tointeger(L, 1));
  2613         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2614         if gear <> nil then
  2614         if gear <> nil then
  2615             gear^.aihints:= lua_tointeger(L, 2);
  2615             gear^.aihints:= Trunc(lua_tonumber(L, 2));
  2616         end;
  2616         end;
  2617     lc_setgearaihints:= 0
  2617     lc_setgearaihints:= 0
  2618 end;
  2618 end;
  2619 
  2619 
  2620 
  2620 
  2629 
  2629 
  2630 
  2630 
  2631 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  2631 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  2632 begin
  2632 begin
  2633     if CheckLuaParamCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then
  2633     if CheckLuaParamCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then
  2634         declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4));
  2634         declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), Trunc(lua_tonumber(L, 4)));
  2635     lc_declareachievement:= 0
  2635     lc_declareachievement:= 0
  2636 end;
  2636 end;
  2637 
  2637 
  2638 function lc_getammoname(L : Plua_state) : LongInt; Cdecl;
  2638 function lc_getammoname(L : Plua_state) : LongInt; Cdecl;
  2639 var np, at: LongInt;
  2639 var np, at: LongInt;
  2659 end;
  2659 end;
  2660 
  2660 
  2661 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
  2661 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
  2662 begin
  2662 begin
  2663     if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
  2663     if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
  2664         startGhostPoints(lua_tointeger(L, 1));
  2664         startGhostPoints(Trunc(lua_tonumber(L, 1)));
  2665     lc_startghostpoints:= 0
  2665     lc_startghostpoints:= 0
  2666 end;
  2666 end;
  2667 
  2667 
  2668 function lc_dumppoint(L : Plua_State) : LongInt; Cdecl;
  2668 function lc_dumppoint(L : Plua_State) : LongInt; Cdecl;
  2669 begin
  2669 begin
  2670     if CheckLuaParamCount(L, 2, 'DumpPoint', 'x, y') then
  2670     if CheckLuaParamCount(L, 2, 'DumpPoint', 'x, y') then
  2671         dumpPoint(lua_tointeger(L, 1), lua_tointeger(L, 2));
  2671         dumpPoint(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)));
  2672     lc_dumppoint:= 0
  2672     lc_dumppoint:= 0
  2673 end;
  2673 end;
  2674 
  2674 
  2675 
  2675 
  2676 procedure ScriptFlushPoints();
  2676 procedure ScriptFlushPoints();
  2684 var np, param: LongInt;
  2684 var np, param: LongInt;
  2685 begin
  2685 begin
  2686     if CheckAndFetchParamCountRange(L, 2, 4, 'AddPoint', 'x, y [, width [, erase] ]', np) then
  2686     if CheckAndFetchParamCountRange(L, 2, 4, 'AddPoint', 'x, y [, width [, erase] ]', np) then
  2687         begin
  2687         begin
  2688         // x
  2688         // x
  2689         param:= LongInt(lua_tointeger(L,1));
  2689         param:= LongInt(Trunc(lua_tonumber(L,1)));
  2690         PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
  2690         PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
  2691         PointsBuffer:= PointsBuffer + char((param and $FF));
  2691         PointsBuffer:= PointsBuffer + char((param and $FF));
  2692         // y
  2692         // y
  2693         param:= LongInt(lua_tointeger(L,2));
  2693         param:= LongInt(Trunc(lua_tonumber(L,2)));
  2694         PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
  2694         PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
  2695         PointsBuffer:= PointsBuffer + char((param and $FF));
  2695         PointsBuffer:= PointsBuffer + char((param and $FF));
  2696         // width
  2696         // width
  2697         if np > 2 then
  2697         if np > 2 then
  2698             begin
  2698             begin
  2699             param:= lua_tointeger(L,3);
  2699             param:= Trunc(lua_tonumber(L,3));
  2700             param:= (param or $80);
  2700             param:= (param or $80);
  2701             // erase
  2701             // erase
  2702             if (np > 3) and lua_toboolean(L, 4) then
  2702             if (np > 3) and lua_toboolean(L, 4) then
  2703                 param:= (param or $40);
  2703                 param:= (param or $40);
  2704             PointsBuffer:= PointsBuffer + char(param);
  2704             PointsBuffer:= PointsBuffer + char(param);
  2731     params = 'TEST_SUCCESSFUL or TEST_FAILED';
  2731     params = 'TEST_SUCCESSFUL or TEST_FAILED';
  2732 begin
  2732 begin
  2733     if CheckLuaParamCount(L, 1, call, params) then
  2733     if CheckLuaParamCount(L, 1, call, params) then
  2734         begin
  2734         begin
  2735 
  2735 
  2736         case lua_tointeger(L, 1) of
  2736         case Trunc(lua_tonumber(L, 1)) of
  2737             HaltTestSuccess : rstring:= 'Success';
  2737             HaltTestSuccess : rstring:= 'Success';
  2738             HaltTestFailed: rstring:= 'FAILED';
  2738             HaltTestFailed: rstring:= 'FAILED';
  2739         else
  2739         else
  2740             begin
  2740             begin
  2741             LuaCallError('Parameter must be either ' + params, call, params);
  2741             LuaCallError('Parameter must be either ' + params, call, params);
  2744         end;
  2744         end;
  2745 
  2745 
  2746         if cTestLua then
  2746         if cTestLua then
  2747             begin
  2747             begin
  2748             WriteLnToConsole('Lua test finished, result: ' + rstring);
  2748             WriteLnToConsole('Lua test finished, result: ' + rstring);
  2749             halt(lua_tointeger(L, 1));
  2749             halt(Trunc(lua_tonumber(L, 1)));
  2750             end
  2750             end
  2751         else LuaError('Not in lua test mode, engine will keep running. Reported test result: ' + rstring);
  2751         else LuaError('Not in lua test mode, engine will keep running. Reported test result: ' + rstring);
  2752 
  2752 
  2753         end;
  2753         end;
  2754 
  2754 
  2781     lua_setglobal(luaState, Str2PChar(name));
  2781     lua_setglobal(luaState, Str2PChar(name));
  2782 end;
  2782 end;
  2783 
  2783 
  2784 procedure ScriptSetInteger(name : shortstring; value : LongInt);
  2784 procedure ScriptSetInteger(name : shortstring; value : LongInt);
  2785 begin
  2785 begin
  2786     lua_pushinteger(luaState, value);
  2786     lua_pushnumber(luaState, value);
  2787     lua_setglobal(luaState, Str2PChar(name));
  2787     lua_setglobal(luaState, Str2PChar(name));
  2788 end;
  2788 end;
  2789 
  2789 
  2790 procedure ScriptSetString(name : shortstring; value : shortstring);
  2790 procedure ScriptSetString(name : shortstring; value : shortstring);
  2791 begin
  2791 begin
  2794 end;
  2794 end;
  2795 
  2795 
  2796 function ScriptGetInteger(name : shortstring) : LongInt;
  2796 function ScriptGetInteger(name : shortstring) : LongInt;
  2797 begin
  2797 begin
  2798     lua_getglobal(luaState, Str2PChar(name));
  2798     lua_getglobal(luaState, Str2PChar(name));
  2799     ScriptGetInteger:= lua_tointeger(luaState, -1);
  2799     ScriptGetInteger:= Trunc(lua_tonumber(luaState, -1));
  2800     lua_pop(luaState, 1);
  2800     lua_pop(luaState, 1);
  2801 end;
  2801 end;
  2802 
  2802 
  2803 function ScriptGetString(name : shortstring) : shortstring;
  2803 function ScriptGetString(name : shortstring) : shortstring;
  2804 begin
  2804 begin
  3103 begin
  3103 begin
  3104 if (not ScriptLoaded) or (not ScriptExists(fname)) then
  3104 if (not ScriptLoaded) or (not ScriptExists(fname)) then
  3105     exit(0);
  3105     exit(0);
  3106 SetGlobals;
  3106 SetGlobals;
  3107 lua_getglobal(luaState, Str2PChar(fname));
  3107 lua_getglobal(luaState, Str2PChar(fname));
  3108 lua_pushinteger(luaState, par1);
  3108 lua_pushnumber(luaState, par1);
  3109 lua_pushinteger(luaState, par2);
  3109 lua_pushnumber(luaState, par2);
  3110 lua_pushinteger(luaState, par3);
  3110 lua_pushnumber(luaState, par3);
  3111 lua_pushinteger(luaState, par4);
  3111 lua_pushnumber(luaState, par4);
  3112 ScriptCall:= 0;
  3112 ScriptCall:= 0;
  3113 if lua_pcall(luaState, 4, 1, 0) <> 0 then
  3113 if lua_pcall(luaState, 4, 1, 0) <> 0 then
  3114     begin
  3114     begin
  3115     LuaError('Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
  3115     LuaError('Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
  3116     lua_pop(luaState, 1)
  3116     lua_pop(luaState, 1)
  3117     end
  3117     end
  3118 else
  3118 else
  3119     begin
  3119     begin
  3120     ScriptCall:= lua_tointeger(luaState, -1);
  3120     ScriptCall:= Trunc(lua_tonumber(luaState, -1));
  3121     lua_pop(luaState, 1)
  3121     lua_pop(luaState, 1)
  3122     end;
  3122     end;
  3123 GetGlobals;
  3123 GetGlobals;
  3124 end;
  3124 end;
  3125 
  3125