hedgewars/uScript.pas
branchqmlfrontend
changeset 12855 1b2b84315d27
parent 12848 076d00110223
child 12910 383445810e42
equal deleted inserted replaced
11843:01f88c3b7b66 12855:1b2b84315d27
    21 unit uScript;
    21 unit uScript;
    22 (*
    22 (*
    23  * This unit defines, implements and registers functions and
    23  * This unit defines, implements and registers functions and
    24  * variables/constants bindings for usage in Lua scripts.
    24  * variables/constants bindings for usage in Lua scripts.
    25  *
    25  *
    26  * Please keep http://hedgewars.org/kb/LuaAPI up to date!
    26  * Please keep https://hedgewars.org/kb/LuaAPI up to date!
    27  *
    27  *
    28  * Note: If you add a new function, make sure to test if _all_ parameters
    28  * Note: If you add a new function, make sure to test if _all_ parameters
    29  *       work as intended! (Especially conversions errors can sneak in
    29  *       work as intended! (Especially conversions errors can sneak in
    30  *       unnoticed and render the parameter useless!)
    30  *       unnoticed and render the parameter useless!)
    31  *)
    31  *)
   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 gear type!', call, paramsyntax);
   294         LuaCallError('Invalid effect type!', call, paramsyntax);
   295         LuaToHogEffectOrd:= -1;
   295         LuaToHogEffectOrd:= -1;
   296         end
   296         end
   297     else
   297     else
   298         LuaToHogEffectOrd:= i;
   298         LuaToHogEffectOrd:= i;
   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
   548     L:= L; // avoid compiler hint
   548     L:= L; // avoid compiler hint
   549     HideMission;
   549     HideMission;
   550     lc_hidemission:= 0;
   550     lc_hidemission:= 0;
   551 end;
   551 end;
   552 
   552 
       
   553 function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
       
   554 const
       
   555     call = 'SetAmmoTexts';
       
   556     params = 'ammoType, name, caption, description';
       
   557 begin
       
   558     if CheckLuaParamCount(L, 4, call, params) then
       
   559         SetAmmoTexts(TAmmoType(LuaToAmmoTypeOrd(L, 1, call, params)), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tostringA(L, 4));
       
   560     lc_setammotexts:= 0;
       
   561 end;
       
   562 
       
   563 function lc_setammodescriptionappendix(L : Plua_State) : LongInt; Cdecl;
       
   564 const
       
   565     call = 'SetAmmoDescriptionAppendix';
       
   566     params = 'ammoType, descAppend';
       
   567 var
       
   568     ammoType: TAmmoType;
       
   569     descAppend: ansistring;
       
   570 begin
       
   571     if CheckLuaParamCount(L, 2, call, params) then
       
   572         begin
       
   573         ammoType := TAmmoType(LuaToAmmoTypeOrd(L, 1, call, params));
       
   574         descAppend := lua_tostringA(L, 2);
       
   575         trluaammoa[Ammoz[ammoType].NameId] := descAppend;
       
   576         end;
       
   577     lc_setammodescriptionappendix := 0;
       
   578 end;
       
   579 
   553 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
   580 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
   554 var i, n : integer;
   581 var i, n : integer;
   555 begin
   582 begin
   556     // can have 1 or more arguments
   583     // can have 1 or more arguments
   557     if CheckAndFetchLuaParamMinCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then
   584     if CheckAndFetchLuaParamMinCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then
   558         begin
   585         begin
   559         for i:= 1 to n do
   586         for i:= 1 to n do
   560             GameFlags := GameFlags or LongWord(lua_tointeger(L, i));
   587             GameFlags := GameFlags or LongWord(Trunc(lua_tonumber(L, i)));
   561         ScriptSetInteger('GameFlags', GameFlags);
   588         ScriptSetInteger('GameFlags', GameFlags);
   562         end;
   589         end;
   563     lc_enablegameflags:= 0;
   590     lc_enablegameflags:= 0;
   564 end;
   591 end;
   565 
   592 
   568 begin
   595 begin
   569     // can have 1 or more arguments
   596     // can have 1 or more arguments
   570     if CheckAndFetchLuaParamMinCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then
   597     if CheckAndFetchLuaParamMinCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then
   571         begin
   598         begin
   572         for i:= 1 to n do
   599         for i:= 1 to n do
   573             GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i)));
   600             GameFlags := GameFlags and (not LongWord(Trunc(lua_tonumber(L, i))));
   574         ScriptSetInteger('GameFlags', GameFlags);
   601         ScriptSetInteger('GameFlags', GameFlags);
   575         end;
   602         end;
   576     lc_disablegameflags:= 0;
   603     lc_disablegameflags:= 0;
   577 end;
   604 end;
   578 
   605 
   587 end;
   614 end;
   588 
   615 
   589 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
   616 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
   590 begin
   617 begin
   591     if CheckLuaParamCount(L, 1, 'GetGameFlag', 'gameflag') then
   618     if CheckLuaParamCount(L, 1, 'GetGameFlag', 'gameflag') then
   592         lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0))
   619         lua_pushboolean(L, (GameFlags and LongWord(Trunc(lua_tonumber(L, 1))) <> 0))
   593     else
   620     else
   594         lua_pushnil(L);
   621         lua_pushnil(L);
   595     lc_getgameflag:= 1;
   622     lc_getgameflag:= 1;
   596 end;
   623 end;
   597 
   624 
   607             AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage)
   634             AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage)
   608         else
   635         else
   609             begin
   636             begin
   610             cg:= LuaToCapGroupOrd(L, 3, call, params);
   637             cg:= LuaToCapGroupOrd(L, 3, call, params);
   611             if cg >= 0 then
   638             if cg >= 0 then
   612                 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));
   613             end
   640             end
   614         end;
   641         end;
   615     lc_addcaption:= 0;
   642     lc_addcaption:= 0;
   616 end;
   643 end;
   617 
   644 
   636 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   663 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   637 var gear: PGear;
   664 var gear: PGear;
   638 begin
   665 begin
   639     if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   666     if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   640         begin
   667         begin
   641         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   668         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
   642         HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   669         HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   643         if gear <> nil then
   670         if gear <> nil then
   644              lua_pushinteger(L, gear^.uid)
   671              lua_pushnumber(L, gear^.uid)
   645         else lua_pushnil(L)
   672         else lua_pushnil(L)
   646         end
   673         end
   647     else
   674     else
   648         lua_pushnil(L);
   675         lua_pushnil(L);
   649     lc_spawnfakehealthcrate := 1;
   676     lc_spawnfakehealthcrate := 1;
   652 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   679 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   653 var gear: PGear;
   680 var gear: PGear;
   654 begin
   681 begin
   655     if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
   682     if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
   656         begin
   683         begin
   657         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   684         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
   658         AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   685         AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   659         if gear <> nil then
   686         if gear <> nil then
   660              lua_pushinteger(L, gear^.uid)
   687              lua_pushnumber(L, gear^.uid)
   661         else lua_pushnil(L)
   688         else lua_pushnil(L)
   662         end
   689         end
   663     else
   690     else
   664         lua_pushnil(L);
   691         lua_pushnil(L);
   665     lc_spawnfakeammocrate := 1;
   692     lc_spawnfakeammocrate := 1;
   668 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   695 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   669 var gear: PGear;
   696 var gear: PGear;
   670 begin
   697 begin
   671     if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
   698     if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
   672         begin
   699         begin
   673         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   700         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
   674         UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   701         UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   675         if gear <> nil then
   702         if gear <> nil then
   676              lua_pushinteger(L, gear^.uid)
   703              lua_pushnumber(L, gear^.uid)
   677         else lua_pushnil(L)
   704         else lua_pushnil(L)
   678         end
   705         end
   679     else
   706     else
   680         lua_pushnil(L);
   707         lua_pushnil(L);
   681     lc_spawnfakeutilitycrate := 1;
   708     lc_spawnfakeutilitycrate := 1;
   686 var health, n: LongInt;
   713 var health, n: LongInt;
   687 begin
   714 begin
   688     if CheckAndFetchParamCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then
   715     if CheckAndFetchParamCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then
   689         begin
   716         begin
   690         if n = 3 then
   717         if n = 3 then
   691             health:= lua_tointeger(L, 3)
   718             health:= Trunc(lua_tonumber(L, 3))
   692         else
   719         else
   693             health:= cHealthCaseAmount;
   720             health:= cHealthCaseAmount;
   694         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);
   695         if gear <> nil then
   722         if gear <> nil then
   696              lua_pushinteger(L, gear^.uid)
   723              lua_pushnumber(L, gear^.uid)
   697         else lua_pushnil(L);
   724         else lua_pushnil(L);
   698         end
   725         end
   699     else
   726     else
   700         lua_pushnil(L);
   727         lua_pushnil(L);
   701     lc_spawnhealthcrate := 1;
   728     lc_spawnhealthcrate := 1;
   706     n   : LongInt;
   733     n   : LongInt;
   707 begin
   734 begin
   708     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
   709         begin
   736         begin
   710         if n = 3 then
   737         if n = 3 then
   711              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)
   712         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)));
   713         if gear <> nil then
   740         if gear <> nil then
   714              lua_pushinteger(L, gear^.uid)
   741              lua_pushnumber(L, gear^.uid)
   715         else lua_pushnil(L);
   742         else lua_pushnil(L);
   716         end
   743         end
   717     else
   744     else
   718         lua_pushnil(L);
   745         lua_pushnil(L);
   719     lc_spawnammocrate := 1;
   746     lc_spawnammocrate := 1;
   724     n   : LongInt;
   751     n   : LongInt;
   725 begin
   752 begin
   726     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
   727         begin
   754         begin
   728         if n = 3 then
   755         if n = 3 then
   729              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)
   730         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)));
   731         if gear <> nil then
   758         if gear <> nil then
   732              lua_pushinteger(L, gear^.uid)
   759              lua_pushnumber(L, gear^.uid)
   733         else lua_pushnil(L);
   760         else lua_pushnil(L);
   734        end
   761        end
   735     else
   762     else
   736         lua_pushnil(L);
   763         lua_pushnil(L);
   737     lc_spawnutilitycrate := 1;
   764     lc_spawnutilitycrate := 1;
   750         begin
   777         begin
   751         t:= LuaToGearTypeOrd(L, 3, call, params);
   778         t:= LuaToGearTypeOrd(L, 3, call, params);
   752         if t >= 0 then
   779         if t >= 0 then
   753             begin
   780             begin
   754             gt:= TGearType(t);
   781             gt:= TGearType(t);
   755             x:= lua_tointeger(L, 1);
   782             x:= Trunc(lua_tonumber(L, 1));
   756             y:= lua_tointeger(L, 2);
   783             y:= Trunc(lua_tonumber(L, 2));
   757             s:= lua_tointeger(L, 4);
   784             s:= Trunc(lua_tonumber(L, 4));
   758             dx:= int2hwFloat(lua_tointeger(L, 5)) / 1000000;
   785             dx:= int2hwFloat(Trunc(lua_tonumber(L, 5))) / 1000000;
   759             dy:= int2hwFloat(lua_tointeger(L, 6)) / 1000000;
   786             dy:= int2hwFloat(Trunc(lua_tonumber(L, 6))) / 1000000;
   760             t:= lua_tointeger(L, 7);
   787             t:= Trunc(lua_tonumber(L, 7));
   761 
   788 
   762             gear:= AddGear(x, y, gt, s, dx, dy, t);
   789             gear:= AddGear(x, y, gt, s, dx, dy, t);
   763             lastGearByUID:= gear;
   790             lastGearByUID:= gear;
   764             lua_pushinteger(L, gear^.uid)
   791             lua_pushnumber(L, gear^.uid)
   765             end
   792             end
   766         else
   793         else
   767             lua_pushnil(L);
   794             lua_pushnil(L);
   768         end
   795         end
   769     else
   796     else
   774 function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
   801 function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
   775 var gear : PGear;
   802 var gear : PGear;
   776 begin
   803 begin
   777     if CheckLuaParamCount(L, 1, 'DeleteGear', 'gearUid') then
   804     if CheckLuaParamCount(L, 1, 'DeleteGear', 'gearUid') then
   778         begin
   805         begin
   779         gear:= GearByUID(lua_tointeger(L, 1));
   806         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
   780         if gear <> nil then
   807         if gear <> nil then
   781             gear^.Message:= gear^.Message or gmDelete;
   808             gear^.Message:= gear^.Message or gmDelete;
   782         end;
   809         end;
   783     lc_deletegear:= 0
   810     lc_deletegear:= 0
   784 end;
   811 end;
   798         begin
   825         begin
   799         s:= LuaToVisualGearTypeOrd(L, 3, call, params);
   826         s:= LuaToVisualGearTypeOrd(L, 3, call, params);
   800         if s >= 0 then
   827         if s >= 0 then
   801             begin
   828             begin
   802             vgt:= TVisualGearType(s);
   829             vgt:= TVisualGearType(s);
   803             x:= lua_tointeger(L, 1);
   830             x:= Trunc(lua_tonumber(L, 1));
   804             y:= lua_tointeger(L, 2);
   831             y:= Trunc(lua_tonumber(L, 2));
   805             s:= lua_tointeger(L, 4);
   832             s:= Trunc(lua_tonumber(L, 4));
   806             c:= lua_toboolean(L, 5);
   833             c:= lua_toboolean(L, 5);
   807 
   834 
   808             if n = 6 then
   835             if n = 6 then
   809                 begin
   836                 begin
   810                 layer:= lua_tointeger(L, 6);
   837                 layer:= Trunc(lua_tonumber(L, 6));
   811                 vg:= AddVisualGear(x, y, vgt, s, c, layer);
   838                 vg:= AddVisualGear(x, y, vgt, s, c, layer);
   812                 end
   839                 end
   813             else
   840             else
   814                 vg:= AddVisualGear(x, y, vgt, s, c);
   841                 vg:= AddVisualGear(x, y, vgt, s, c);
   815 
   842 
   816             if vg <> nil then
   843             if vg <> nil then
   817                 begin
   844                 begin
   818                 lastVisualGearByUID:= vg;
   845                 lastVisualGearByUID:= vg;
   819                 uid:= vg^.uid;
   846                 uid:= vg^.uid;
   820                 lua_pushinteger(L, uid);
   847                 lua_pushnumber(L, uid);
   821                 end;
   848                 end;
   822             end
   849             end
   823             else
   850             else
   824                 lua_pushnil(L);
   851                 lua_pushnil(L);
   825         end
   852         end
   832 var vg : PVisualGear;
   859 var vg : PVisualGear;
   833 begin
   860 begin
   834     vg:= nil;
   861     vg:= nil;
   835     if CheckLuaParamCount(L, 1, 'DeleteVisualGear', 'vgUid') then
   862     if CheckLuaParamCount(L, 1, 'DeleteVisualGear', 'vgUid') then
   836         begin
   863         begin
   837         vg:= VisualGearByUID(lua_tointeger(L, 1));
   864         vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
   838         if vg <> nil then
   865         if vg <> nil then
   839             DeleteVisualGear(vg);
   866             DeleteVisualGear(vg);
   840         end;
   867         end;
   841     // allow caller to know whether there was something to delete
   868     // allow caller to know whether there was something to delete
   842     lua_pushboolean(L, vg <> nil);
   869     lua_pushboolean(L, vg <> nil);
   843     lc_deletevisualgear:= 1
   870     lc_deletevisualgear:= 1
   844 end;
   871 end;
   845 
   872 
       
   873 function lc_getvisualgeartype(L : Plua_State) : LongInt; Cdecl;
       
   874 var vg : PVisualGear;
       
   875 begin
       
   876     if CheckLuaParamCount(L, 1, 'GetVisualGearType', 'vgUid') then
       
   877         begin
       
   878         vg := VisualGearByUID(Trunc(lua_tonumber(L, 1)));
       
   879         if vg <> nil then
       
   880             lua_pushnumber(L, ord(vg^.Kind))
       
   881         else
       
   882             lua_pushnil(L);
       
   883         end
       
   884     else
       
   885         lua_pushnil(L); // return value on stack (nil)
       
   886     lc_getvisualgeartype:= 1
       
   887 end;
       
   888 
       
   889 
   846 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
   890 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
   847 var vg: PVisualGear;
   891 var vg: PVisualGear;
   848 begin
   892 begin
   849     if CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then
   893     if CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then
   850         begin
   894         begin
   851         vg:= VisualGearByUID(lua_tointeger(L, 1));
   895         vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
   852         if vg <> nil then
   896         if vg <> nil then
   853             begin
   897             begin
   854             lua_pushinteger(L, round(vg^.X));
   898             lua_pushnumber(L, round(vg^.X));
   855             lua_pushinteger(L, round(vg^.Y));
   899             lua_pushnumber(L, round(vg^.Y));
   856             lua_pushnumber(L, vg^.dX);
   900             lua_pushnumber(L, vg^.dX);
   857             lua_pushnumber(L, vg^.dY);
   901             lua_pushnumber(L, vg^.dY);
   858             lua_pushnumber(L, vg^.Angle);
   902             lua_pushnumber(L, vg^.Angle);
   859             lua_pushinteger(L, vg^.Frame);
   903             lua_pushnumber(L, vg^.Frame);
   860             lua_pushinteger(L, vg^.FrameTicks);
   904             lua_pushnumber(L, vg^.FrameTicks);
   861             lua_pushinteger(L, vg^.State);
   905             lua_pushnumber(L, vg^.State);
   862             lua_pushinteger(L, vg^.Timer);
   906             lua_pushnumber(L, vg^.Timer);
   863             lua_pushinteger(L, vg^.Tint);
   907             lua_pushnumber(L, vg^.Tint);
   864             end
   908             end
   865         else
   909         else
   866             begin
   910             begin
   867             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);
   868             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);
   880 var vg : PVisualGear;
   924 var vg : PVisualGear;
   881 begin
   925 begin
   882 // Param count can be 1-11 at present
   926 // Param count can be 1-11 at present
   883 //    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
   884 //        begin
   928 //        begin
   885         vg:= VisualGearByUID(lua_tointeger(L, 1));
   929         vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
   886         if vg <> nil then
   930         if vg <> nil then
   887             begin
   931             begin
   888             if not lua_isnoneornil(L, 2) then
   932             if not lua_isnoneornil(L, 2) then
   889                 vg^.X:= lua_tointeger(L, 2);
   933                 vg^.X:= Trunc(lua_tonumber(L, 2));
   890             if not lua_isnoneornil(L, 3) then
   934             if not lua_isnoneornil(L, 3) then
   891                 vg^.Y:= lua_tointeger(L, 3);
   935                 vg^.Y:= Trunc(lua_tonumber(L, 3));
   892             if not lua_isnoneornil(L, 4) then
   936             if not lua_isnoneornil(L, 4) then
   893                 vg^.dX:= lua_tonumber(L, 4);
   937                 vg^.dX:= lua_tonumber(L, 4);
   894             if not lua_isnoneornil(L, 5) then
   938             if not lua_isnoneornil(L, 5) then
   895                 vg^.dY:= lua_tonumber(L, 5);
   939                 vg^.dY:= lua_tonumber(L, 5);
   896             if not lua_isnoneornil(L, 6) then
   940             if not lua_isnoneornil(L, 6) then
   897                 vg^.Angle:= lua_tonumber(L, 6);
   941                 vg^.Angle:= lua_tonumber(L, 6);
   898             if not lua_isnoneornil(L, 7) then
   942             if not lua_isnoneornil(L, 7) then
   899                 vg^.Frame:= lua_tointeger(L, 7);
   943                 vg^.Frame:= Trunc(lua_tonumber(L, 7));
   900             if not lua_isnoneornil(L, 8) then
   944             if not lua_isnoneornil(L, 8) then
   901                 vg^.FrameTicks:= lua_tointeger(L, 8);
   945                 vg^.FrameTicks:= Trunc(lua_tonumber(L, 8));
   902             if not lua_isnoneornil(L, 9) then
   946             if not lua_isnoneornil(L, 9) then
   903                 vg^.State:= lua_tointeger(L, 9);
   947                 vg^.State:= Trunc(lua_tonumber(L, 9));
   904             if not lua_isnoneornil(L, 10) then
   948             if not lua_isnoneornil(L, 10) then
   905                 vg^.Timer:= lua_tointeger(L, 10);
   949                 vg^.Timer:= Trunc(lua_tonumber(L, 10));
   906             if not lua_isnoneornil(L, 11) then
   950             if not lua_isnoneornil(L, 11) then
   907                 vg^.Tint:= lua_tointeger(L, 11)
   951                 vg^.Tint:= Trunc(lua_tonumber(L, 11))
   908             end;
   952             end;
   909 //        end
   953 //        end
   910 //    else
   954 //    else
   911 //        lua_pushnil(L); // return value on stack (nil)
   955 //        lua_pushnil(L); // return value on stack (nil)
   912     lc_setvisualgearvalues:= 0
   956     lc_setvisualgearvalues:= 0
   917 function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl;
   961 function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl;
   918 var gear: PGear;
   962 var gear: PGear;
   919 begin
   963 begin
   920     if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then
   964     if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then
   921         begin
   965         begin
   922         gear:= GearByUID(lua_tointeger(L, 1));
   966         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
   923         if gear <> nil then
   967         if gear <> nil then
   924             begin
   968             begin
   925             lua_pushinteger(L, gear^.Angle);
   969             lua_pushnumber(L, gear^.Angle);
   926             lua_pushinteger(L, gear^.Power);
   970             lua_pushnumber(L, gear^.Power);
   927             lua_pushinteger(L, gear^.WDTimer);
   971             lua_pushnumber(L, gear^.WDTimer);
   928             lua_pushinteger(L, gear^.Radius);
   972             lua_pushnumber(L, gear^.Radius);
   929             lua_pushinteger(L, hwRound(gear^.Density * _10000));
   973             lua_pushnumber(L, hwRound(gear^.Density * _10000));
   930             lua_pushinteger(L, gear^.Karma);
   974             lua_pushnumber(L, gear^.Karma);
   931             lua_pushnumber(L,  gear^.DirAngle);
   975             lua_pushnumber(L,  gear^.DirAngle);
   932             lua_pushinteger(L, gear^.AdvBounce);
   976             lua_pushnumber(L, gear^.AdvBounce);
   933             lua_pushinteger(L, Integer(gear^.ImpactSound));
   977             lua_pushnumber(L, Integer(gear^.ImpactSound));
   934             lua_pushinteger(L, gear^.nImpactSounds);
   978             lua_pushnumber(L, gear^.nImpactSounds);
   935             lua_pushinteger(L, gear^.Tint);
   979             lua_pushnumber(L, gear^.Tint);
   936             lua_pushinteger(L, gear^.Damage);
   980             lua_pushnumber(L, gear^.Damage);
   937             lua_pushinteger(L, gear^.Boom)
   981             lua_pushnumber(L, gear^.Boom)
   938             end
   982             end
   939         else
   983         else
   940             begin
   984             begin
   941             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);
   942             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);
   956 var gear : PGear;
  1000 var gear : PGear;
   957 begin
  1001 begin
   958 // Currently allows 1-14 params
  1002 // Currently allows 1-14 params
   959 //    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
   960 //        begin
  1004 //        begin
   961         gear:= GearByUID(lua_tointeger(L, 1));
  1005         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
   962         if gear <> nil then
  1006         if gear <> nil then
   963             begin
  1007             begin
   964             if not lua_isnoneornil(L, 2) then
  1008             if not lua_isnoneornil(L, 2) then
   965                 gear^.Angle := lua_tointeger(L, 2);
  1009                 gear^.Angle := Trunc(lua_tonumber(L, 2));
   966             if not lua_isnoneornil(L, 3) then
  1010             if not lua_isnoneornil(L, 3) then
   967                 gear^.Power := lua_tointeger(L, 3);
  1011                 gear^.Power := Trunc(lua_tonumber(L, 3));
   968             if not lua_isnoneornil(L, 4) then
  1012             if not lua_isnoneornil(L, 4) then
   969                 gear^.WDTimer := lua_tointeger(L, 4);
  1013                 gear^.WDTimer := Trunc(lua_tonumber(L, 4));
   970             if not lua_isnoneornil(L, 5) then
  1014             if not lua_isnoneornil(L, 5) then
   971                 gear^.Radius := lua_tointeger(L, 5);
  1015                 gear^.Radius := Trunc(lua_tonumber(L, 5));
   972             if not lua_isnoneornil(L, 6) then
  1016             if not lua_isnoneornil(L, 6) then
   973                 gear^.Density:= int2hwFloat(lua_tointeger(L, 6)) / 10000;
  1017                 gear^.Density:= int2hwFloat(Trunc(lua_tonumber(L, 6))) / 10000;
   974             if not lua_isnoneornil(L, 7) then
  1018             if not lua_isnoneornil(L, 7) then
   975                 gear^.Karma := lua_tointeger(L, 7);
  1019                 gear^.Karma := Trunc(lua_tonumber(L, 7));
   976             if not lua_isnoneornil(L, 8) then
  1020             if not lua_isnoneornil(L, 8) then
   977                 gear^.DirAngle:= lua_tonumber(L, 8);
  1021                 gear^.DirAngle:= lua_tonumber(L, 8);
   978             if not lua_isnoneornil(L, 9) then
  1022             if not lua_isnoneornil(L, 9) then
   979                 gear^.AdvBounce := lua_tointeger(L, 9);
  1023                 gear^.AdvBounce := Trunc(lua_tonumber(L, 9));
   980             if not lua_isnoneornil(L, 10) then
  1024             if not lua_isnoneornil(L, 10) then
   981                 gear^.ImpactSound := TSound(lua_tointeger(L, 10));
  1025                 gear^.ImpactSound := TSound(Trunc(lua_tonumber(L, 10)));
   982             if not lua_isnoneornil(L, 11) then
  1026             if not lua_isnoneornil(L, 11) then
   983                 gear^.nImpactSounds := lua_tointeger(L, 11);
  1027                 gear^.nImpactSounds := Trunc(lua_tonumber(L, 11));
   984             if not lua_isnoneornil(L, 12) then
  1028             if not lua_isnoneornil(L, 12) then
   985                 gear^.Tint := lua_tointeger(L, 12);
  1029                 gear^.Tint := Trunc(lua_tonumber(L, 12));
   986             if not lua_isnoneornil(L, 13) then
  1030             if not lua_isnoneornil(L, 13) then
   987                 gear^.Damage := lua_tointeger(L, 13);
  1031                 gear^.Damage := Trunc(lua_tonumber(L, 13));
   988             if not lua_isnoneornil(L, 14) then
  1032             if not lua_isnoneornil(L, 14) then
   989                 gear^.Boom := lua_tointeger(L, 14);
  1033                 gear^.Boom := Trunc(lua_tonumber(L, 14));
   990             end;
  1034             end;
   991 //        end
  1035 //        end
   992 //    else
  1036 //    else
   993 //        lua_pushnil(L); // return value on stack (nil)
  1037 //        lua_pushnil(L); // return value on stack (nil)
   994     lc_setgearvalues:= 0
  1038     lc_setgearvalues:= 0
   999     if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then
  1043     if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then
  1000         begin
  1044         begin
  1001         if FollowGear = nil then
  1045         if FollowGear = nil then
  1002             lua_pushnil(L)
  1046             lua_pushnil(L)
  1003         else
  1047         else
  1004             lua_pushinteger(L, FollowGear^.uid);
  1048             lua_pushnumber(L, FollowGear^.uid);
  1005         end
  1049         end
  1006     else
  1050     else
  1007         lua_pushnil(L);
  1051         lua_pushnil(L);
  1008     lc_getfollowgear:= 1; // 1 return value
  1052     lc_getfollowgear:= 1; // 1 return value
  1009 end;
  1053 end;
  1011 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
  1055 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
  1012 var gear : PGear;
  1056 var gear : PGear;
  1013 begin
  1057 begin
  1014     if CheckLuaParamCount(L, 1, 'GetGearType', 'gearUid') then
  1058     if CheckLuaParamCount(L, 1, 'GetGearType', 'gearUid') then
  1015         begin
  1059         begin
  1016         gear:= GearByUID(lua_tointeger(L, 1));
  1060         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1017         if gear <> nil then
  1061         if gear <> nil then
  1018             lua_pushinteger(L, ord(gear^.Kind))
  1062             lua_pushnumber(L, ord(gear^.Kind))
  1019         else
  1063         else
  1020             lua_pushnil(L);
  1064             lua_pushnil(L);
  1021         end
  1065         end
  1022     else
  1066     else
  1023         lua_pushnil(L); // return value on stack (nil)
  1067         lua_pushnil(L); // return value on stack (nil)
  1027 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl;
  1071 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl;
  1028 var gear : PGear;
  1072 var gear : PGear;
  1029 begin
  1073 begin
  1030     if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then
  1074     if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then
  1031         begin
  1075         begin
  1032         gear:= GearByUID(lua_tointeger(L, 1));
  1076         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1033         if gear <> nil then
  1077         if gear <> nil then
  1034             lua_pushinteger(L, gear^.message)
  1078             lua_pushnumber(L, gear^.message)
  1035         else
  1079         else
  1036             lua_pushnil(L);
  1080             lua_pushnil(L);
  1037         end
  1081         end
  1038     else
  1082     else
  1039         lua_pushnil(L); // return value on stack (nil)
  1083         lua_pushnil(L); // return value on stack (nil)
  1043 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl;
  1087 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl;
  1044 var gear : PGear;
  1088 var gear : PGear;
  1045 begin
  1089 begin
  1046     if CheckLuaParamCount(L, 1, 'GetGearElasticity', 'gearUid') then
  1090     if CheckLuaParamCount(L, 1, 'GetGearElasticity', 'gearUid') then
  1047         begin
  1091         begin
  1048         gear:= GearByUID(lua_tointeger(L, 1));
  1092         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1049         if gear <> nil then
  1093         if gear <> nil then
  1050             lua_pushinteger(L, hwRound(gear^.elasticity * _10000))
  1094             lua_pushnumber(L, hwRound(gear^.elasticity * _10000))
  1051         else
  1095         else
  1052             lua_pushnil(L);
  1096             lua_pushnil(L);
  1053         end
  1097         end
  1054     else
  1098     else
  1055         lua_pushnil(L); // return value on stack (nil)
  1099         lua_pushnil(L); // return value on stack (nil)
  1059 function lc_setgearelasticity(L : Plua_State) : LongInt; Cdecl;
  1103 function lc_setgearelasticity(L : Plua_State) : LongInt; Cdecl;
  1060 var gear: PGear;
  1104 var gear: PGear;
  1061 begin
  1105 begin
  1062     if CheckLuaParamCount(L, 2, 'SetGearElasticity', 'gearUid, Elasticity') then
  1106     if CheckLuaParamCount(L, 2, 'SetGearElasticity', 'gearUid, Elasticity') then
  1063         begin
  1107         begin
  1064         gear:= GearByUID(lua_tointeger(L, 1));
  1108         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1065         if gear <> nil then
  1109         if gear <> nil then
  1066             gear^.Elasticity:= int2hwFloat(lua_tointeger(L, 2)) / 10000
  1110             gear^.Elasticity:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 10000
  1067         end;
  1111         end;
  1068     lc_setgearelasticity:= 0
  1112     lc_setgearelasticity:= 0
  1069 end;
  1113 end;
  1070 
  1114 
  1071 function lc_getgearfriction(L : Plua_State) : LongInt; Cdecl;
  1115 function lc_getgearfriction(L : Plua_State) : LongInt; Cdecl;
  1072 var gear : PGear;
  1116 var gear : PGear;
  1073 begin
  1117 begin
  1074     if CheckLuaParamCount(L, 1, 'GetGearFriction', 'gearUid') then
  1118     if CheckLuaParamCount(L, 1, 'GetGearFriction', 'gearUid') then
  1075         begin
  1119         begin
  1076         gear:= GearByUID(lua_tointeger(L, 1));
  1120         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1077         if gear <> nil then
  1121         if gear <> nil then
  1078             lua_pushinteger(L, hwRound(gear^.friction * _10000))
  1122             lua_pushnumber(L, hwRound(gear^.friction * _10000))
  1079         else
  1123         else
  1080             lua_pushnil(L);
  1124             lua_pushnil(L);
  1081         end
  1125         end
  1082     else
  1126     else
  1083         lua_pushnil(L); // return value on stack (nil)
  1127         lua_pushnil(L); // return value on stack (nil)
  1087 function lc_setgearfriction(L : Plua_State) : LongInt; Cdecl;
  1131 function lc_setgearfriction(L : Plua_State) : LongInt; Cdecl;
  1088 var gear: PGear;
  1132 var gear: PGear;
  1089 begin
  1133 begin
  1090     if CheckLuaParamCount(L, 2, 'SetGearFriction', 'gearUid, Friction') then
  1134     if CheckLuaParamCount(L, 2, 'SetGearFriction', 'gearUid, Friction') then
  1091         begin
  1135         begin
  1092         gear:= GearByUID(lua_tointeger(L, 1));
  1136         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1093         if gear <> nil then
  1137         if gear <> nil then
  1094             gear^.Friction:= int2hwFloat(lua_tointeger(L, 2)) / 10000
  1138             gear^.Friction:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 10000
  1095         end;
  1139         end;
  1096     lc_setgearfriction:= 0
  1140     lc_setgearfriction:= 0
  1097 end;
  1141 end;
  1098 
  1142 
  1099 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl;
  1143 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl;
  1100 var gear : PGear;
  1144 var gear : PGear;
  1101 begin
  1145 begin
  1102     if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then
  1146     if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then
  1103         begin
  1147         begin
  1104         gear:= GearByUID(lua_tointeger(L, 1));
  1148         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1105         if gear <> nil then
  1149         if gear <> nil then
  1106             gear^.message:= lua_tointeger(L, 2);
  1150             gear^.message:= Trunc(lua_tonumber(L, 2));
  1107         end;
  1151         end;
  1108     lc_setgearmessage:= 0
  1152     lc_setgearmessage:= 0
  1109 end;
  1153 end;
  1110 
  1154 
  1111 function lc_getgearpos(L : Plua_State) : LongInt; Cdecl;
  1155 function lc_getgearpos(L : Plua_State) : LongInt; Cdecl;
  1112 var gear : PGear;
  1156 var gear : PGear;
  1113 begin
  1157 begin
  1114     if CheckLuaParamCount(L, 1, 'GetGearPos', 'gearUid') then
  1158     if CheckLuaParamCount(L, 1, 'GetGearPos', 'gearUid') then
  1115         begin
  1159         begin
  1116         gear:= GearByUID(lua_tointeger(L, 1));
  1160         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1117         if gear <> nil then
  1161         if gear <> nil then
  1118             lua_pushinteger(L, gear^.Pos)
  1162             lua_pushnumber(L, gear^.Pos)
  1119         else
  1163         else
  1120             lua_pushnil(L);
  1164             lua_pushnil(L);
  1121         end
  1165         end
  1122     else
  1166     else
  1123         lua_pushnil(L); // return value on stack (nil)
  1167         lua_pushnil(L); // return value on stack (nil)
  1127 function lc_setgearpos(L : Plua_State) : LongInt; Cdecl;
  1171 function lc_setgearpos(L : Plua_State) : LongInt; Cdecl;
  1128 var gear : PGear;
  1172 var gear : PGear;
  1129 begin
  1173 begin
  1130     if CheckLuaParamCount(L, 2, 'SetGearPos', 'gearUid, value') then
  1174     if CheckLuaParamCount(L, 2, 'SetGearPos', 'gearUid, value') then
  1131         begin
  1175         begin
  1132         gear:= GearByUID(lua_tointeger(L, 1));
  1176         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1133         if gear <> nil then
  1177         if gear <> nil then
  1134             gear^.Pos:= lua_tointeger(L, 2);
  1178             gear^.Pos:= Trunc(lua_tonumber(L, 2));
  1135         end;
  1179         end;
  1136     lc_setgearpos:= 0
  1180     lc_setgearpos:= 0
  1137 end;
  1181 end;
  1138 
  1182 
  1139 function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
  1183 function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
  1140 var gear : PGear;
  1184 var gear : PGear;
  1141 begin
  1185 begin
  1142     if CheckLuaParamCount(L, 1, 'GetGearCollisionMask', 'gearUid') then
  1186     if CheckLuaParamCount(L, 1, 'GetGearCollisionMask', 'gearUid') then
  1143         begin
  1187         begin
  1144         gear:= GearByUID(lua_tointeger(L, 1));
  1188         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1145         if gear <> nil then
  1189         if gear <> nil then
  1146             lua_pushinteger(L, gear^.CollisionMask)
  1190             lua_pushnumber(L, gear^.CollisionMask)
  1147         else
  1191         else
  1148             lua_pushnil(L);
  1192             lua_pushnil(L);
  1149         end
  1193         end
  1150     else
  1194     else
  1151         lua_pushnil(L); // return value on stack (nil)
  1195         lua_pushnil(L); // return value on stack (nil)
  1155 function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
  1199 function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
  1156 var gear : PGear;
  1200 var gear : PGear;
  1157 begin
  1201 begin
  1158     if CheckLuaParamCount(L, 2, 'SetGearCollisionMask', 'gearUid, mask') then
  1202     if CheckLuaParamCount(L, 2, 'SetGearCollisionMask', 'gearUid, mask') then
  1159         begin
  1203         begin
  1160         gear:= GearByUID(lua_tointeger(L, 1));
  1204         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1161         if gear <> nil then
  1205         if gear <> nil then
  1162             gear^.CollisionMask:= lua_tointeger(L, 2);
  1206             gear^.CollisionMask:= Trunc(lua_tonumber(L, 2));
  1163         end;
  1207         end;
  1164     lc_setgearcollisionmask:= 0
  1208     lc_setgearcollisionmask:= 0
  1165 end;
  1209 end;
  1166 
  1210 
  1167 function lc_gethoglevel(L : Plua_State): LongInt; Cdecl;
  1211 function lc_gethoglevel(L : Plua_State): LongInt; Cdecl;
  1168 var gear : PGear;
  1212 var gear : PGear;
  1169 begin
  1213 begin
  1170     if CheckLuaParamCount(L, 1, 'GetHogLevel', 'gearUid') then
  1214     if CheckLuaParamCount(L, 1, 'GetHogLevel', 'gearUid') then
  1171         begin
  1215         begin
  1172         gear := GearByUID(lua_tointeger(L, 1));
  1216         gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  1173         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
  1174             lua_pushinteger(L, gear^.Hedgehog^.BotLevel)
  1218             lua_pushnumber(L, gear^.Hedgehog^.BotLevel)
  1175         else
  1219         else
  1176             lua_pushnil(L);
  1220             lua_pushnil(L);
  1177     end;
  1221     end;
  1178     lc_gethoglevel := 1;
  1222     lc_gethoglevel := 1;
  1179 end;
  1223 end;
  1181 function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl;
  1225 function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl;
  1182 var gear : PGear;
  1226 var gear : PGear;
  1183 begin
  1227 begin
  1184     if CheckLuaParamCount(L, 2, 'SetHogLevel', 'gearUid, level') then
  1228     if CheckLuaParamCount(L, 2, 'SetHogLevel', 'gearUid, level') then
  1185         begin
  1229         begin
  1186         gear:= GearByUID(lua_tointeger(L, 1));
  1230         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1187         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
  1188             gear^.Hedgehog^.BotLevel:= lua_tointeger(L, 2);
  1232             gear^.Hedgehog^.BotLevel:= Trunc(lua_tonumber(L, 2));
  1189         end;
  1233         end;
  1190     lc_sethoglevel:= 0
  1234     lc_sethoglevel:= 0
  1191 end;
  1235 end;
  1192 
  1236 
  1193 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
  1237 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
  1194 var gear : PGear;
  1238 var gear : PGear;
  1195 begin
  1239 begin
  1196     if CheckLuaParamCount(L, 1, 'GetHogClan', 'gearUid') then
  1240     if CheckLuaParamCount(L, 1, 'GetHogClan', 'gearUid') then
  1197         begin
  1241         begin
  1198         gear:= GearByUID(lua_tointeger(L, 1));
  1242         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1199         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
  1200             begin
  1244             begin
  1201             lua_pushinteger(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex)
  1245             lua_pushnumber(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex)
  1202             end
  1246             end
  1203         else
  1247         else
  1204             lua_pushnil(L);
  1248             lua_pushnil(L);
  1205         end
  1249         end
  1206     else
  1250     else
  1211 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl;
  1255 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl;
  1212 var idx: integer;
  1256 var idx: integer;
  1213 begin
  1257 begin
  1214     if CheckLuaParamCount(L, 1, 'GetClanColor', 'clanIdx') then
  1258     if CheckLuaParamCount(L, 1, 'GetClanColor', 'clanIdx') then
  1215         begin
  1259         begin
  1216         idx:= lua_tointeger(L, 1);
  1260         idx:= Trunc(lua_tonumber(L, 1));
  1217         if (not lua_isnumber(L, 1)) then
  1261         if (not lua_isnumber(L, 1)) then
  1218             begin
  1262             begin
  1219             LuaError('Argument ''clanIdx'' must be a number!');
  1263             LuaError('Argument ''clanIdx'' must be a number!');
  1220             lua_pushnil(L);
  1264             lua_pushnil(L);
  1221             end
  1265             end
  1223             begin
  1267             begin
  1224             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) + ')');
  1225             lua_pushnil(L);
  1269             lua_pushnil(L);
  1226             end
  1270             end
  1227         else
  1271         else
  1228             lua_pushinteger(L, ClansArray[idx]^.Color shl 8 or $FF);
  1272             lua_pushnumber(L, ClansArray[idx]^.Color shl 8 or $FF);
  1229         end
  1273         end
  1230     else
  1274     else
  1231         lua_pushnil(L); // return value on stack (nil)
  1275         lua_pushnil(L); // return value on stack (nil)
  1232     lc_getclancolor:= 1
  1276     lc_getclancolor:= 1
  1233 end;
  1277 end;
  1238     hh   : THedgehog;
  1282     hh   : THedgehog;
  1239     i, j : LongInt;
  1283     i, j : LongInt;
  1240 begin
  1284 begin
  1241     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
  1285     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
  1242         begin
  1286         begin
  1243         i:= lua_tointeger(L,1);
  1287         i:= Trunc(lua_tonumber(L,1));
  1244         if i >= ClansCount then exit(0);
  1288         if i >= ClansCount then exit(0);
  1245         clan := ClansArray[i];
  1289         clan := ClansArray[i];
  1246         clan^.Color:= lua_tointeger(L, 2) shr 8;
  1290         clan^.Color:= Trunc(lua_tonumber(L, 2)) shr 8;
  1247 
  1291 
  1248         for i:= 0 to Pred(clan^.TeamsNumber) do
  1292         for i:= 0 to Pred(clan^.TeamsNumber) do
  1249             begin
  1293             begin
  1250             team:= clan^.Teams[i];
  1294             team:= clan^.Teams[i];
  1251             for j:= 0 to 7 do
  1295             for j:= 0 to 7 do
  1272 function lc_gethogvoicepack(L : Plua_State) : LongInt; Cdecl;
  1316 function lc_gethogvoicepack(L : Plua_State) : LongInt; Cdecl;
  1273 var gear : PGear;
  1317 var gear : PGear;
  1274 begin
  1318 begin
  1275     if CheckLuaParamCount(L, 1, 'GetHogVoicepack', 'gearUid') then
  1319     if CheckLuaParamCount(L, 1, 'GetHogVoicepack', 'gearUid') then
  1276         begin
  1320         begin
  1277         gear:= GearByUID(lua_tointeger(L, 1));
  1321         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1278         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
  1279             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Voicepack^.name))
  1323             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Voicepack^.name))
  1280         else
  1324         else
  1281             lua_pushnil(L);
  1325             lua_pushnil(L);
  1282         end
  1326         end
  1288 function lc_gethoggrave(L : Plua_State) : LongInt; Cdecl;
  1332 function lc_gethoggrave(L : Plua_State) : LongInt; Cdecl;
  1289 var gear : PGear;
  1333 var gear : PGear;
  1290 begin
  1334 begin
  1291     if CheckLuaParamCount(L, 1, 'GetHogGrave', 'gearUid') then
  1335     if CheckLuaParamCount(L, 1, 'GetHogGrave', 'gearUid') then
  1292         begin
  1336         begin
  1293         gear:= GearByUID(lua_tointeger(L, 1));
  1337         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1294         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
  1295             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.GraveName))
  1339             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.GraveName))
  1296         else
  1340         else
  1297             lua_pushnil(L);
  1341             lua_pushnil(L);
  1298         end
  1342         end
  1304 function lc_gethogflag(L : Plua_State) : LongInt; Cdecl;
  1348 function lc_gethogflag(L : Plua_State) : LongInt; Cdecl;
  1305 var gear : PGear;
  1349 var gear : PGear;
  1306 begin
  1350 begin
  1307     if CheckLuaParamCount(L, 1, 'GetHogFlag', 'gearUid') then
  1351     if CheckLuaParamCount(L, 1, 'GetHogFlag', 'gearUid') then
  1308         begin
  1352         begin
  1309         gear:= GearByUID(lua_tointeger(L, 1));
  1353         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
       
  1354         // TODO error messages
  1310         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
  1311             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Flag))
  1356             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Flag))
  1312         else
  1357         else
  1313             lua_pushnil(L);
  1358             lua_pushnil(L);
  1314         end
  1359         end
  1315     else
  1360     else
  1316         lua_pushnil(L); // return value on stack (nil)
  1361         lua_pushnil(L); // return value on stack (nil)
  1317     lc_gethogflag:= 1
  1362     lc_gethogflag:= 1
  1318 end;
  1363 end;
  1319 
  1364 
       
  1365 function lc_gethogfort(L : Plua_State) : LongInt; Cdecl;
       
  1366 var gear : PGear;
       
  1367 begin
       
  1368     if CheckLuaParamCount(L, 1, 'GetHogFort', 'gearUid') then
       
  1369         begin
       
  1370         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
       
  1371         // TODO error messages
       
  1372         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
       
  1373             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.FortName))
       
  1374         else
       
  1375             lua_pushnil(L);
       
  1376         end
       
  1377     else
       
  1378         lua_pushnil(L); // return value on stack (nil)
       
  1379     lc_gethogfort:= 1
       
  1380 end;
       
  1381 
       
  1382 function lc_ishoglocal(L : Plua_State) : LongInt; Cdecl;
       
  1383 var gear : PGear;
       
  1384 begin
       
  1385     if CheckLuaParamCount(L, 1, 'IsHogLocal', 'gearUid') then
       
  1386         begin
       
  1387         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
       
  1388         // TODO error messages
       
  1389         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
       
  1390             lua_pushboolean(L, IsHogLocal(gear^.Hedgehog))
       
  1391         else
       
  1392             lua_pushnil(L);
       
  1393         end
       
  1394     else
       
  1395         lua_pushnil(L); // return value on stack (nil)
       
  1396     lc_ishoglocal:= 1
       
  1397 end;
       
  1398 
  1320 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
  1399 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
  1321 var gear : PGear;
  1400 var gear : PGear;
  1322 begin
  1401 begin
  1323     if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then
  1402     if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then
  1324         begin
  1403         begin
  1325         gear:= GearByUID(lua_tointeger(L, 1));
  1404         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
       
  1405         // TODO error messages
  1326         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
  1327             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName))
  1407             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName))
  1328         else
  1408         else
  1329             lua_pushnil(L);
  1409             lua_pushnil(L);
  1330         end
  1410         end
  1336 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl;
  1416 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl;
  1337 var gear : PGear;
  1417 var gear : PGear;
  1338 begin
  1418 begin
  1339     if CheckLuaParamCount(L, 2, 'SetHogTeamName', 'gearUid, name') then
  1419     if CheckLuaParamCount(L, 2, 'SetHogTeamName', 'gearUid, name') then
  1340         begin
  1420         begin
  1341         gear := GearByUID(lua_tointeger(L, 1));
  1421         gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  1342         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
  1343             begin
  1423             begin
  1344             gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2);
  1424             gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2);
  1345 
  1425 
  1346             FreeAndNilTexture(gear^.Hedgehog^.Team^.NameTagTex);
  1426             FreeAndNilTexture(gear^.Hedgehog^.Team^.NameTagTex);
  1357 function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
  1437 function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
  1358 var gear : PGear;
  1438 var gear : PGear;
  1359 begin
  1439 begin
  1360     if CheckLuaParamCount(L, 1, 'GetHogName', 'gearUid') then
  1440     if CheckLuaParamCount(L, 1, 'GetHogName', 'gearUid') then
  1361         begin
  1441         begin
  1362         gear:= GearByUID(lua_tointeger(L, 1));
  1442         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1363         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
  1364             begin
  1444             begin
  1365             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name))
  1445             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name))
  1366             end
  1446             end
  1367         else
  1447         else
  1375 function lc_sethogname(L : Plua_State) : LongInt; Cdecl;
  1455 function lc_sethogname(L : Plua_State) : LongInt; Cdecl;
  1376 var gear : PGear;
  1456 var gear : PGear;
  1377 begin
  1457 begin
  1378     if CheckLuaParamCount(L, 2, 'SetHogName', 'gearUid, name') then
  1458     if CheckLuaParamCount(L, 2, 'SetHogName', 'gearUid, name') then
  1379         begin
  1459         begin
  1380         gear:= GearByUID(lua_tointeger(L, 1));
  1460         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1381         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
  1382             begin
  1462             begin
  1383             gear^.Hedgehog^.Name:= lua_tostring(L, 2);
  1463             gear^.Hedgehog^.Name:= lua_tostring(L, 2);
  1384 
  1464 
  1385             FreeAndNilTexture(gear^.Hedgehog^.NameTagTex);
  1465             FreeAndNilTexture(gear^.Hedgehog^.NameTagTex);
  1392 function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
  1472 function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
  1393 var gear : PGear;
  1473 var gear : PGear;
  1394 begin
  1474 begin
  1395     if CheckLuaParamCount(L, 1, 'GetTimer', 'gearUid') then
  1475     if CheckLuaParamCount(L, 1, 'GetTimer', 'gearUid') then
  1396         begin
  1476         begin
  1397         gear:= GearByUID(lua_tointeger(L, 1));
  1477         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1398         if gear <> nil then
  1478         if gear <> nil then
  1399             lua_pushinteger(L, gear^.Timer)
  1479             lua_pushnumber(L, gear^.Timer)
  1400         else
  1480         else
  1401             lua_pushnil(L);
  1481             lua_pushnil(L);
  1402         end
  1482         end
  1403     else
  1483     else
  1404         lua_pushnil(L); // return value on stack (nil)
  1484         lua_pushnil(L); // return value on stack (nil)
  1408 function lc_getflighttime(L : Plua_State) : LongInt; Cdecl;
  1488 function lc_getflighttime(L : Plua_State) : LongInt; Cdecl;
  1409 var gear : PGear;
  1489 var gear : PGear;
  1410 begin
  1490 begin
  1411     if CheckLuaParamCount(L, 1, 'GetFlightTime', 'gearUid') then
  1491     if CheckLuaParamCount(L, 1, 'GetFlightTime', 'gearUid') then
  1412         begin
  1492         begin
  1413         gear:= GearByUID(lua_tointeger(L, 1));
  1493         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1414         if gear <> nil then
  1494         if gear <> nil then
  1415             lua_pushinteger(L, gear^.FlightTime)
  1495             lua_pushnumber(L, gear^.FlightTime)
  1416         else
  1496         else
  1417             lua_pushnil(L);
  1497             lua_pushnil(L);
  1418         end
  1498         end
  1419     else
  1499     else
  1420         lua_pushnil(L); // return value on stack (nil)
  1500         lua_pushnil(L); // return value on stack (nil)
  1424 function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
  1504 function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
  1425 var gear : PGear;
  1505 var gear : PGear;
  1426 begin
  1506 begin
  1427     if CheckLuaParamCount(L, 1, 'GetHealth', 'gearUid') then
  1507     if CheckLuaParamCount(L, 1, 'GetHealth', 'gearUid') then
  1428         begin
  1508         begin
  1429         gear:= GearByUID(lua_tointeger(L, 1));
  1509         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1430         if gear <> nil then
  1510         if gear <> nil then
  1431             lua_pushinteger(L, gear^.Health)
  1511             lua_pushnumber(L, gear^.Health)
  1432         else
  1512         else
  1433             lua_pushnil(L);
  1513             lua_pushnil(L);
  1434         end
  1514         end
  1435     else
  1515     else
  1436         lua_pushnil(L); // return value on stack (nil)
  1516         lua_pushnil(L); // return value on stack (nil)
  1440 function lc_getx(L : Plua_State) : LongInt; Cdecl;
  1520 function lc_getx(L : Plua_State) : LongInt; Cdecl;
  1441 var gear : PGear;
  1521 var gear : PGear;
  1442 begin
  1522 begin
  1443     if CheckLuaParamCount(L, 1, 'GetX', 'gearUid') then
  1523     if CheckLuaParamCount(L, 1, 'GetX', 'gearUid') then
  1444         begin
  1524         begin
  1445         gear:= GearByUID(lua_tointeger(L, 1));
  1525         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1446         if gear <> nil then
  1526         if gear <> nil then
  1447             lua_pushinteger(L, hwRound(gear^.X))
  1527             lua_pushnumber(L, hwRound(gear^.X))
  1448         else
  1528         else
  1449             lua_pushnil(L);
  1529             lua_pushnil(L);
  1450         end
  1530         end
  1451     else
  1531     else
  1452         lua_pushnil(L); // return value on stack (nil)
  1532         lua_pushnil(L); // return value on stack (nil)
  1456 function lc_gety(L : Plua_State) : LongInt; Cdecl;
  1536 function lc_gety(L : Plua_State) : LongInt; Cdecl;
  1457 var gear : PGear;
  1537 var gear : PGear;
  1458 begin
  1538 begin
  1459     if CheckLuaParamCount(L, 1, 'GetY', 'gearUid') then
  1539     if CheckLuaParamCount(L, 1, 'GetY', 'gearUid') then
  1460         begin
  1540         begin
  1461         gear:= GearByUID(lua_tointeger(L, 1));
  1541         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1462         if gear <> nil then
  1542         if gear <> nil then
  1463             lua_pushinteger(L, hwRound(gear^.Y))
  1543             lua_pushnumber(L, hwRound(gear^.Y))
  1464         else
  1544         else
  1465             lua_pushnil(L);
  1545             lua_pushnil(L);
  1466         end
  1546         end
  1467     else
  1547     else
  1468         lua_pushnil(L); // return value on stack (nil)
  1548         lua_pushnil(L); // return value on stack (nil)
  1472 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
  1552 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
  1473 var gears, geard : PGear;
  1553 var gears, geard : PGear;
  1474 begin
  1554 begin
  1475     if CheckLuaParamCount(L, 2, 'CopyPV', 'fromGearUid, toGearUid') then
  1555     if CheckLuaParamCount(L, 2, 'CopyPV', 'fromGearUid, toGearUid') then
  1476         begin
  1556         begin
  1477         gears:= GearByUID(lua_tointeger(L, 1));
  1557         gears:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1478         geard:= GearByUID(lua_tointeger(L, 2));
  1558         geard:= GearByUID(Trunc(lua_tonumber(L, 2)));
  1479         if (gears <> nil) and (geard <> nil) then
  1559         if (gears <> nil) and (geard <> nil) then
  1480             begin
  1560             begin
  1481             geard^.X:= gears^.X;
  1561             geard^.X:= gears^.X;
  1482             geard^.Y:= gears^.Y;
  1562             geard^.Y:= gears^.Y;
  1483             geard^.dX:= gears^.dX;
  1563             geard^.dX:= gears^.dX;
  1490 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
  1570 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
  1491 var gear : PGear;
  1571 var gear : PGear;
  1492 begin
  1572 begin
  1493     if CheckLuaParamCount(L, 1, 'FollowGear', 'gearUid') then
  1573     if CheckLuaParamCount(L, 1, 'FollowGear', 'gearUid') then
  1494         begin
  1574         begin
  1495         gear:= GearByUID(lua_tointeger(L, 1));
  1575         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1496         if gear <> nil then FollowGear:= gear
  1576         if gear <> nil then FollowGear:= gear
  1497         end;
  1577         end;
  1498     lc_followgear:= 0
  1578     lc_followgear:= 0
  1499 end;
  1579 end;
  1500 
  1580 
  1504        s : LongWord;
  1584        s : LongWord;
  1505        n : LongInt;
  1585        n : LongInt;
  1506 begin
  1586 begin
  1507     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
  1508         begin
  1588         begin
  1509         gear:= GearByUID(lua_tointeger(L, 1));
  1589         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1510         if gear <> nil then
  1590         if gear <> nil then
  1511             begin
  1591             begin
  1512             // state defaults to 0 if state param is given
  1592             // state defaults to 0 if state param is given
  1513             if n = 4 then
  1593             if n = 4 then
  1514                 s:= lua_tointeger(L, 4)
  1594                 s:= Trunc(lua_tonumber(L, 4))
  1515             else
  1595             else
  1516                 s:= 0;
  1596                 s:= 0;
  1517             vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true);
  1597             vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true);
  1518             if vgear <> nil then
  1598             if vgear <> nil then
  1519                begin
  1599                begin
  1523                    AddChatString(#9+'[' + gear^.Hedgehog^.Name + '] '+vgear^.text);
  1603                    AddChatString(#9+'[' + gear^.Hedgehog^.Name + '] '+vgear^.text);
  1524                    vgear^.Hedgehog:= gear^.Hedgehog
  1604                    vgear^.Hedgehog:= gear^.Hedgehog
  1525                    end
  1605                    end
  1526                else vgear^.Frame:= gear^.uid;
  1606                else vgear^.Frame:= gear^.uid;
  1527 
  1607 
  1528                vgear^.FrameTicks:= lua_tointeger(L, 3);
  1608                vgear^.FrameTicks:= Trunc(lua_tonumber(L, 3));
  1529                if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then
  1609                if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then
  1530                    vgear^.FrameTicks:= 1;
  1610                    vgear^.FrameTicks:= 1;
  1531                lua_pushinteger(L, vgear^.Uid);
  1611                lua_pushnumber(L, vgear^.Uid);
  1532                end
  1612                end
  1533             end
  1613             end
  1534         else
  1614         else
  1535             lua_pushnil(L)
  1615             lua_pushnil(L)
  1536         end
  1616         end
  1542 function lc_switchhog(L : Plua_State) : LongInt; Cdecl;
  1622 function lc_switchhog(L : Plua_State) : LongInt; Cdecl;
  1543 var gear, prevgear : PGear;
  1623 var gear, prevgear : PGear;
  1544 begin
  1624 begin
  1545     if CheckLuaParamCount(L, 1, 'SwitchHog', 'gearUid') then
  1625     if CheckLuaParamCount(L, 1, 'SwitchHog', 'gearUid') then
  1546         begin
  1626         begin
  1547         gear:= GearByUID(lua_tointeger(L, 1));
  1627         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1548 // 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.
  1549         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
  1550             begin
  1630             begin
  1551             prevgear := CurrentHedgehog^.Gear;
  1631             prevgear := CurrentHedgehog^.Gear;
  1552             if prevgear <> nil then
  1632             if prevgear <> nil then
  1556                 prevgear^.Z := cHHZ;
  1636                 prevgear^.Z := cHHZ;
  1557                 prevgear^.Message:= prevgear^.Message or gmRemoveFromList or gmAddToList;
  1637                 prevgear^.Message:= prevgear^.Message or gmRemoveFromList or gmAddToList;
  1558                 end;
  1638                 end;
  1559 
  1639 
  1560             SwitchCurrentHedgehog(gear^.Hedgehog);
  1640             SwitchCurrentHedgehog(gear^.Hedgehog);
       
  1641             AmmoMenuInvalidated:= true;
  1561             CurrentTeam:= CurrentHedgehog^.Team;
  1642             CurrentTeam:= CurrentHedgehog^.Team;
       
  1643 
       
  1644             repeat
       
  1645                 CurrentTeam^.CurrHedgehog := (CurrentTeam^.CurrHedgehog + 1) mod CurrentTeam^.HedgehogsNumber
       
  1646             until
       
  1647                 CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear = CurrentHedgehog^.Gear;
  1562 
  1648 
  1563             gear^.State:= gear^.State or gstHHDriven;
  1649             gear^.State:= gear^.State or gstHHDriven;
  1564             gear^.Active := true;
  1650             gear^.Active := true;
  1565             gear^.Z := cCurrHHZ;
  1651             gear^.Z := cCurrHHZ;
  1566             gear^.Message:= gear^.Message or gmRemoveFromList or gmAddToList;
  1652             gear^.Message:= gear^.Message or gmRemoveFromList or gmAddToList;
  1579     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1665     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1580         begin
  1666         begin
  1581         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1667         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1582         if at >= 0 then
  1668         if at >= 0 then
  1583             begin
  1669             begin
  1584             gear:= GearByUID(lua_tointeger(L, 1));
  1670             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1585             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1671             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1586                 if n = 2 then
  1672                 if n = 2 then
  1587                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
  1673                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
  1588                 else
  1674                 else
  1589                     SetAmmo(gear^.Hedgehog^, TAmmoType(at), lua_tointeger(L, 3))
  1675                     SetAmmo(gear^.Hedgehog^, TAmmoType(at), Trunc(lua_tonumber(L, 3)))
  1590             end;
  1676             end;
  1591         end;
  1677         end;
  1592     lc_addammo:= 0
  1678     lc_addammo:= 0
  1593 end;
  1679 end;
  1594 
  1680 
  1600     call = 'GetAmmoCount';
  1686     call = 'GetAmmoCount';
  1601     params = 'gearUid, ammoType';
  1687     params = 'gearUid, ammoType';
  1602 begin
  1688 begin
  1603     if CheckLuaParamCount(L, 2, call, params) then
  1689     if CheckLuaParamCount(L, 2, call, params) then
  1604         begin
  1690         begin
  1605         gear:= GearByUID(lua_tointeger(L, 1));
  1691         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1606         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1692         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1607             begin
  1693             begin
  1608             at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1694             at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1609             if at >= 0 then
  1695             if at >= 0 then
  1610                 begin
  1696                 begin
  1611                 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
  1697                 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
  1612                 if ammo^.AmmoType = amNothing then
  1698                 if ammo^.AmmoType = amNothing then
  1613                     lua_pushinteger(L, 0)
  1699                     lua_pushnumber(L, 0)
  1614                 else
  1700                 else
  1615                     lua_pushinteger(L, ammo^.Count);
  1701                     lua_pushnumber(L, ammo^.Count);
  1616                 end;
  1702                 end;
  1617             end
  1703             end
  1618         else lua_pushinteger(L, 0);
  1704         else lua_pushnumber(L, 0);
  1619         end
  1705         end
  1620     else
  1706     else
  1621         lua_pushnil(L);
  1707         lua_pushnil(L);
  1622     lc_getammocount:= 1
  1708     lc_getammocount:= 1
  1623 end;
  1709 end;
  1625 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
  1711 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
  1626 var gear : PGear;
  1712 var gear : PGear;
  1627 begin
  1713 begin
  1628     if CheckLuaParamCount(L, 2, 'SetHealth', 'gearUid, health') then
  1714     if CheckLuaParamCount(L, 2, 'SetHealth', 'gearUid, health') then
  1629         begin
  1715         begin
  1630         gear:= GearByUID(lua_tointeger(L, 1));
  1716         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1631         if gear <> nil then
  1717         if gear <> nil then
  1632             begin
  1718             begin
  1633             gear^.Health:= lua_tointeger(L, 2);
  1719             gear^.Health:= Trunc(lua_tonumber(L, 2));
  1634 
  1720 
  1635             if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1721             if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1636                 begin
  1722                 begin
  1637                 RenderHealth(gear^.Hedgehog^);
  1723                 RenderHealth(gear^.Hedgehog^);
  1638                 RecountTeamHealth(gear^.Hedgehog^.Team)
  1724                 RecountTeamHealth(gear^.Hedgehog^.Team)
  1649 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
  1735 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
  1650 var gear : PGear;
  1736 var gear : PGear;
  1651 begin
  1737 begin
  1652     if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then
  1738     if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then
  1653         begin
  1739         begin
  1654         gear:= GearByUID(lua_tointeger(L, 1));
  1740         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1655         if gear <> nil then gear^.Timer:= lua_tointeger(L, 2)
  1741         if gear <> nil then gear^.Timer:= Trunc(lua_tonumber(L, 2))
  1656         end;
  1742         end;
  1657     lc_settimer:= 0
  1743     lc_settimer:= 0
  1658 end;
  1744 end;
  1659 
  1745 
  1660 function lc_setflighttime(L : Plua_State) : LongInt; Cdecl;
  1746 function lc_setflighttime(L : Plua_State) : LongInt; Cdecl;
  1661 var gear : PGear;
  1747 var gear : PGear;
  1662 begin
  1748 begin
  1663     if CheckLuaParamCount(L, 2, 'SetFlightTime', 'gearUid, flighttime') then
  1749     if CheckLuaParamCount(L, 2, 'SetFlightTime', 'gearUid, flighttime') then
  1664         begin
  1750         begin
  1665         gear:= GearByUID(lua_tointeger(L, 1));
  1751         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1666         if gear <> nil then gear^.FlightTime:= lua_tointeger(L, 2)
  1752         if gear <> nil then gear^.FlightTime:= Trunc(lua_tonumber(L, 2))
  1667         end;
  1753         end;
  1668     lc_setflighttime:= 0
  1754     lc_setflighttime:= 0
  1669 end;
  1755 end;
  1670 
  1756 
  1671 function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
  1757 function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
  1678     if CheckLuaParamCount(L, 3, call, params) then
  1764     if CheckLuaParamCount(L, 3, call, params) then
  1679         begin
  1765         begin
  1680         t:= LuaToHogEffectOrd(L, 2, call, params);
  1766         t:= LuaToHogEffectOrd(L, 2, call, params);
  1681         if t >= 0 then
  1767         if t >= 0 then
  1682             begin
  1768             begin
  1683             gear := GearByUID(lua_tointeger(L, 1));
  1769             gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  1684             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1770             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1685                 gear^.Hedgehog^.Effects[THogEffect(t)]:= lua_tointeger(L, 3);
  1771                 gear^.Hedgehog^.Effects[THogEffect(t)]:= Trunc(lua_tonumber(L, 3));
  1686             end;
  1772             end;
  1687         end;
  1773         end;
  1688     lc_seteffect := 0;
  1774     lc_seteffect := 0;
  1689 end;
  1775 end;
  1690 
  1776 
  1698     if CheckLuaParamCount(L, 2, call, params) then
  1784     if CheckLuaParamCount(L, 2, call, params) then
  1699         begin
  1785         begin
  1700         t:= LuaToHogEffectOrd(L, 2, call, params);
  1786         t:= LuaToHogEffectOrd(L, 2, call, params);
  1701         if t >= 0 then
  1787         if t >= 0 then
  1702             begin
  1788             begin
  1703             gear:= GearByUID(lua_tointeger(L, 1));
  1789             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1704             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1790             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1705                 lua_pushinteger(L, gear^.Hedgehog^.Effects[THogEffect(t)])
  1791                 lua_pushnumber(L, gear^.Hedgehog^.Effects[THogEffect(t)])
  1706             else
  1792             else
  1707                 lua_pushinteger(L, 0)
  1793                 lua_pushnumber(L, 0)
  1708             end;
  1794             end;
  1709         end
  1795         end
  1710     else
  1796     else
  1711         lua_pushinteger(L, 0);
  1797         lua_pushnumber(L, 0);
  1712     lc_geteffect:= 1
  1798     lc_geteffect:= 1
  1713 end;
  1799 end;
  1714 
  1800 
  1715 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
  1801 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
  1716 var gear : PGear;
  1802 var gear : PGear;
  1717 begin
  1803 begin
  1718     if CheckLuaParamCount(L, 2, 'SetState', 'gearUid, state') then
  1804     if CheckLuaParamCount(L, 2, 'SetState', 'gearUid, state') then
  1719         begin
  1805         begin
  1720         gear:= GearByUID(lua_tointeger(L, 1));
  1806         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1721         if gear <> nil then
  1807         if gear <> nil then
  1722             begin
  1808             begin
  1723             gear^.State:= lua_tointeger(L, 2);
  1809             gear^.State:= Trunc(lua_tonumber(L, 2));
  1724             SetAllToActive;
  1810             SetAllToActive;
  1725             end
  1811             end
  1726         end;
  1812         end;
  1727     lc_setstate:= 0
  1813     lc_setstate:= 0
  1728 end;
  1814 end;
  1730 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
  1816 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
  1731 var gear : PGear;
  1817 var gear : PGear;
  1732 begin
  1818 begin
  1733     if CheckLuaParamCount(L, 1, 'GetState', 'gearUid') then
  1819     if CheckLuaParamCount(L, 1, 'GetState', 'gearUid') then
  1734         begin
  1820         begin
  1735         gear:= GearByUID(lua_tointeger(L, 1));
  1821         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1736         if gear <> nil then
  1822         if gear <> nil then
  1737             lua_pushinteger(L, gear^.State)
  1823             lua_pushnumber(L, gear^.State)
  1738         else
  1824         else
  1739             lua_pushnil(L)
  1825             lua_pushnil(L)
  1740         end
  1826         end
  1741     else
  1827     else
  1742         lua_pushnil(L); // return value on stack (nil)
  1828         lua_pushnil(L); // return value on stack (nil)
  1746 function lc_gettag(L : Plua_State) : LongInt; Cdecl;
  1832 function lc_gettag(L : Plua_State) : LongInt; Cdecl;
  1747 var gear : PGear;
  1833 var gear : PGear;
  1748 begin
  1834 begin
  1749     if CheckLuaParamCount(L, 1, 'GetTag', 'gearUid') then
  1835     if CheckLuaParamCount(L, 1, 'GetTag', 'gearUid') then
  1750         begin
  1836         begin
  1751         gear:= GearByUID(lua_tointeger(L, 1));
  1837         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1752         if gear <> nil then
  1838         if gear <> nil then
  1753             lua_pushinteger(L, gear^.Tag)
  1839             lua_pushnumber(L, gear^.Tag)
  1754         else
  1840         else
  1755             lua_pushnil(L);
  1841             lua_pushnil(L);
  1756         end
  1842         end
  1757     else
  1843     else
  1758         lua_pushnil(L); // return value on stack (nil)
  1844         lua_pushnil(L); // return value on stack (nil)
  1762 function lc_settag(L : Plua_State) : LongInt; Cdecl;
  1848 function lc_settag(L : Plua_State) : LongInt; Cdecl;
  1763 var gear : PGear;
  1849 var gear : PGear;
  1764 begin
  1850 begin
  1765     if CheckLuaParamCount(L, 2, 'SetTag', 'gearUid, tag') then
  1851     if CheckLuaParamCount(L, 2, 'SetTag', 'gearUid, tag') then
  1766         begin
  1852         begin
  1767         gear:= GearByUID(lua_tointeger(L, 1));
  1853         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1768         if gear <> nil then
  1854         if gear <> nil then
  1769             begin
  1855             begin
  1770             gear^.Tag:= lua_tointeger(L, 2);
  1856             gear^.Tag:= Trunc(lua_tonumber(L, 2));
  1771             SetAllToActive;
  1857             SetAllToActive;
  1772             end
  1858             end
  1773         end;
  1859         end;
  1774     lc_settag:= 0
  1860     lc_settag:= 0
  1775 end;
  1861 end;
  1777 function lc_endgame(L : Plua_State) : LongInt; Cdecl;
  1863 function lc_endgame(L : Plua_State) : LongInt; Cdecl;
  1778 begin
  1864 begin
  1779     L:= L; // avoid compiler hint
  1865     L:= L; // avoid compiler hint
  1780     AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000);
  1866     AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000);
  1781     lc_endgame:= 0
  1867     lc_endgame:= 0
       
  1868 end;
       
  1869 
       
  1870 function lc_endturn(L : Plua_State) : LongInt; Cdecl;
       
  1871 var n: LongInt;
       
  1872 const
       
  1873     call = 'EndTurn';
       
  1874     params = '[noTaunts]';
       
  1875 begin
       
  1876     if CheckAndFetchParamCount(L, 0, 1, call, params, n) then
       
  1877         if n >= 1 then
       
  1878             LuaNoEndTurnTaunts:= lua_toboolean(L, 1);
       
  1879     LuaEndTurnRequested:= true;
       
  1880     lc_endturn:= 0
  1782 end;
  1881 end;
  1783 
  1882 
  1784 function lc_sendstat(L : Plua_State) : LongInt; Cdecl;
  1883 function lc_sendstat(L : Plua_State) : LongInt; Cdecl;
  1785 var statInfo : TStatInfoType;
  1884 var statInfo : TStatInfoType;
  1786     i, n     : LongInt;
  1885     i, n     : LongInt;
  1842             end;
  1941             end;
  1843         end;
  1942         end;
  1844     lc_sendstat:= 0
  1943     lc_sendstat:= 0
  1845 end;
  1944 end;
  1846 
  1945 
       
  1946 function lc_sendgameresultoff(L : Plua_State) : LongInt; Cdecl;
       
  1947 begin
       
  1948     L:= L; // avoid compiler hint
       
  1949     uStats.SendGameResultOn := false;
       
  1950     lc_sendgameresultoff:= 0
       
  1951 end;
       
  1952 
       
  1953 function lc_sendrankingstatsoff(L : Plua_State) : LongInt; Cdecl;
       
  1954 begin
       
  1955     L:= L; // avoid compiler hint
       
  1956     uStats.SendRankingStatsOn := false;
       
  1957     lc_sendrankingstatsoff:= 0
       
  1958 end;
       
  1959 
       
  1960 function lc_sendachievementsstatsoff(L : Plua_State) : LongInt; Cdecl;
       
  1961 begin
       
  1962     L:= L; // avoid compiler hint
       
  1963     uStats.SendAchievementsStatsOn := false;
       
  1964     lc_sendachievementsstatsoff:= 0
       
  1965 end;
       
  1966 
  1847 function lc_sendhealthstatsoff(L : Plua_State) : LongInt; Cdecl;
  1967 function lc_sendhealthstatsoff(L : Plua_State) : LongInt; Cdecl;
  1848 begin
  1968 begin
  1849     L:= L; // avoid compiler hint
  1969     L:= L; // avoid compiler hint
  1850     uStats.SendHealthStatsOn := false;
  1970     uStats.SendHealthStatsOn := false;
  1851     lc_sendhealthstatsoff:= 0
  1971     lc_sendhealthstatsoff:= 0
  1857     tryhard: boolean;
  1977     tryhard: boolean;
  1858     left, right, n: LongInt;
  1978     left, right, n: LongInt;
  1859 begin
  1979 begin
  1860     if CheckAndFetchParamCount(L, 4, 5, 'FindPlace', 'gearUid, fall, left, right [, tryHarder]', n) then
  1980     if CheckAndFetchParamCount(L, 4, 5, 'FindPlace', 'gearUid, fall, left, right [, tryHarder]', n) then
  1861         begin
  1981         begin
  1862         gear:= GearByUID(lua_tointeger(L, 1));
  1982         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1863         fall:= lua_toboolean(L, 2);
  1983         fall:= lua_toboolean(L, 2);
  1864         left:= lua_tointeger(L, 3);
  1984         left:= Trunc(lua_tonumber(L, 3));
  1865         right:= lua_tointeger(L, 4);
  1985         right:= Trunc(lua_tonumber(L, 4));
  1866         if n = 5 then
  1986         if n = 5 then
  1867             tryhard:= lua_toboolean(L, 5)
  1987             tryhard:= lua_toboolean(L, 5)
  1868         else
  1988         else
  1869             tryhard:= false;
  1989             tryhard:= false;
  1870         if gear <> nil then
  1990         if gear <> nil then
  1871             FindPlace(gear, fall, left, right, tryhard);
  1991             FindPlace(gear, fall, left, right, tryhard);
  1872         if gear <> nil then
  1992         if gear <> nil then
  1873             lua_pushinteger(L, gear^.uid)
  1993             lua_pushnumber(L, gear^.uid)
  1874         else
  1994         else
  1875             lua_pushnil(L);
  1995             lua_pushnil(L);
  1876         end
  1996         end
  1877     else
  1997     else
  1878         lua_pushnil(L); // return value on stack (nil)
  1998         lua_pushnil(L); // return value on stack (nil)
  1894             // no gear specified
  2014             // no gear specified
  1895             if n = 1 then
  2015             if n = 1 then
  1896                 PlaySound(TSound(s))
  2016                 PlaySound(TSound(s))
  1897             else
  2017             else
  1898                 begin
  2018                 begin
  1899                 gear:= GearByUID(lua_tointeger(L, 2));
  2019                 gear:= GearByUID(Trunc(lua_tonumber(L, 2)));
  1900                 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  2020                 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1901                     AddVoice(TSound(s),gear^.Hedgehog^.Team^.Voicepack)
  2021                     AddVoice(TSound(s),gear^.Hedgehog^.Team^.Voicepack)
  1902                 end;
  2022                 end;
  1903             end;
  2023             end;
  1904         end;
  2024         end;
  1915         ParseCommand('fort ' + lua_tostring(L, 4), true, true);
  2035         ParseCommand('fort ' + lua_tostring(L, 4), true, true);
  1916         ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
  2036         ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
  1917         if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
  2037         if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
  1918         CurrentTeam^.Binds:= DefaultBinds
  2038         CurrentTeam^.Binds:= DefaultBinds
  1919         // fails on x64
  2039         // fails on x64
  1920         //lua_pushinteger(L, LongInt(CurrentTeam));
  2040         //lua_pushnumber(L, LongInt(CurrentTeam));
  1921         end;
  2041         end;
  1922     //else
  2042     //else
  1923         //lua_pushnil(L)
  2043         //lua_pushnil(L)
  1924     lc_addteam:= 0;//1;
  2044     lc_addteam:= 0;//1;
  1925 end;
  2045 end;
  1965                 end;
  2085                 end;
  1966         end;
  2086         end;
  1967     lc_dismissteam:= 0;
  2087     lc_dismissteam:= 0;
  1968 end;
  2088 end;
  1969 
  2089 
       
  2090 function lc_getteamstats(L : Plua_State) : LongInt; Cdecl;
       
  2091 var i: LongInt;
       
  2092 begin
       
  2093     if CheckLuaParamCount(L, 1, 'GetTeamStats', 'teamname') then
       
  2094         begin
       
  2095         if TeamsCount > 0 then
       
  2096             for i:= 0 to Pred(TeamsCount) do
       
  2097                 begin
       
  2098                 // skip teams that don't have matching name
       
  2099                 if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
       
  2100                     continue;
       
  2101 
       
  2102                 lua_newtable(L);
       
  2103 
       
  2104                 lua_pushstring(L, str2pchar('Kills'));
       
  2105                 lua_pushnumber(L, TeamsArray[i]^.stats.Kills);
       
  2106                 lua_settable(L, -3);
       
  2107 
       
  2108                 lua_pushstring(L, str2pchar('Suicides'));
       
  2109                 lua_pushnumber(L, TeamsArray[i]^.stats.Suicides);
       
  2110                 lua_settable(L, -3);
       
  2111 
       
  2112                 lua_pushstring(L, str2pchar('AIKills'));
       
  2113                 lua_pushnumber(L, TeamsArray[i]^.stats.AIKills);
       
  2114                 lua_settable(L, -3);
       
  2115 
       
  2116                 lua_pushstring(L, str2pchar('TeamKills'));
       
  2117                 lua_pushnumber(L, TeamsArray[i]^.stats.TeamKills);
       
  2118                 lua_settable(L, -3);
       
  2119 
       
  2120                 lua_pushstring(L, str2pchar('TurnSkips'));
       
  2121                 lua_pushnumber(L, TeamsArray[i]^.stats.TurnSkips);
       
  2122                 lua_settable(L, -3);
       
  2123 
       
  2124                 lua_pushstring(L, str2pchar('TeamDamage'));
       
  2125                 lua_pushnumber(L, TeamsArray[i]^.stats.TeamDamage);
       
  2126                 lua_settable(L, -3);
       
  2127 
       
  2128                 end;
       
  2129         end
       
  2130     else
       
  2131         lua_pushnil(L);
       
  2132     lc_getteamstats:= 1;
       
  2133 end;
       
  2134 
       
  2135 
       
  2136 
  1970 function lc_addhog(L : Plua_State) : LongInt; Cdecl;
  2137 function lc_addhog(L : Plua_State) : LongInt; Cdecl;
  1971 var temp: ShortString;
  2138 var temp: ShortString;
  1972 begin
  2139 begin
  1973     if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then
  2140     if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then
  1974         begin
  2141         begin
  1975         temp:= lua_tostring(L, 4);
  2142         temp:= lua_tostring(L, 4);
  1976         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
  2143         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
  1977         ParseCommand('hat ' + temp, true, true);
  2144         ParseCommand('hat ' + temp, true, true);
  1978         lua_pushinteger(L, CurrentHedgehog^.Gear^.uid);
  2145         lua_pushnumber(L, CurrentHedgehog^.Gear^.uid);
  1979         end
  2146         end
  1980     else
  2147     else
  1981         lua_pushnil(L);
  2148         lua_pushnil(L);
  1982     lc_addhog:= 1;
  2149     lc_addhog:= 1;
  1983 end;
  2150 end;
  1985 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
  2152 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
  1986 var gear: PGear;
  2153 var gear: PGear;
  1987 begin
  2154 begin
  1988     if CheckLuaParamCount(L, 2, 'HogTurnLeft', 'gearUid, boolean') then
  2155     if CheckLuaParamCount(L, 2, 'HogTurnLeft', 'gearUid, boolean') then
  1989         begin
  2156         begin
  1990         gear:= GearByUID(lua_tointeger(L, 1));
  2157         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1991         if gear <> nil then
  2158         if gear <> nil then
  1992             gear^.dX.isNegative:= lua_toboolean(L, 2);
  2159             gear^.dX.isNegative:= lua_toboolean(L, 2);
  1993         end;
  2160         end;
  1994     lc_hogturnleft:= 0;
  2161     lc_hogturnleft:= 0;
  1995 end;
  2162 end;
  1997 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
  2164 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
  1998 var gear: PGear;
  2165 var gear: PGear;
  1999 begin
  2166 begin
  2000     if CheckLuaParamCount(L, 1, 'GetGearPosition', 'gearUid') then
  2167     if CheckLuaParamCount(L, 1, 'GetGearPosition', 'gearUid') then
  2001         begin
  2168         begin
  2002         gear:= GearByUID(lua_tointeger(L, 1));
  2169         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2003         if gear <> nil then
  2170         if gear <> nil then
  2004             begin
  2171             begin
  2005             lua_pushinteger(L, hwRound(gear^.X));
  2172             lua_pushnumber(L, hwRound(gear^.X));
  2006             lua_pushinteger(L, hwRound(gear^.Y))
  2173             lua_pushnumber(L, hwRound(gear^.Y))
  2007             end
  2174             end
  2008         else
  2175         else
  2009             begin
  2176             begin
  2010             lua_pushnil(L);
  2177             lua_pushnil(L);
  2011             lua_pushnil(L)
  2178             lua_pushnil(L)
  2024     col: boolean;
  2191     col: boolean;
  2025     x, y: LongInt;
  2192     x, y: LongInt;
  2026 begin
  2193 begin
  2027     if CheckLuaParamCount(L, 3, 'SetGearPosition', 'gearUid, x, y') then
  2194     if CheckLuaParamCount(L, 3, 'SetGearPosition', 'gearUid, x, y') then
  2028         begin
  2195         begin
  2029         gear:= GearByUID(lua_tointeger(L, 1));
  2196         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2030         if gear <> nil then
  2197         if gear <> nil then
  2031             begin
  2198             begin
  2032             col:= gear^.CollisionIndex >= 0;
  2199             col:= gear^.CollisionIndex >= 0;
  2033             x:= lua_tointeger(L, 2);
  2200             x:= Trunc(lua_tonumber(L, 2));
  2034             y:= lua_tointeger(L, 3);
  2201             y:= Trunc(lua_tonumber(L, 3));
  2035             if col then
  2202             if col then
  2036                 DeleteCI(gear);
  2203                 DeleteCI(gear);
  2037             gear^.X:= int2hwfloat(x);
  2204             gear^.X:= int2hwfloat(x);
  2038             gear^.Y:= int2hwfloat(y);
  2205             gear^.Y:= int2hwfloat(y);
  2039             if col then
  2206             if col then
  2047 function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl;
  2214 function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl;
  2048 var gear: PGear;
  2215 var gear: PGear;
  2049 begin
  2216 begin
  2050     if CheckLuaParamCount(L, 1, 'GetGearTarget', 'gearUid') then
  2217     if CheckLuaParamCount(L, 1, 'GetGearTarget', 'gearUid') then
  2051         begin
  2218         begin
  2052         gear:= GearByUID(lua_tointeger(L, 1));
  2219         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2053         if gear <> nil then
  2220         if gear <> nil then
  2054             begin
  2221             begin
  2055             lua_pushinteger(L, gear^.Target.X);
  2222             lua_pushnumber(L, gear^.Target.X);
  2056             lua_pushinteger(L, gear^.Target.Y)
  2223             lua_pushnumber(L, gear^.Target.Y)
  2057             end
  2224             end
  2058         else
  2225         else
  2059             begin
  2226             begin
  2060             lua_pushnil(L);
  2227             lua_pushnil(L);
  2061             lua_pushnil(L)
  2228             lua_pushnil(L)
  2072 function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl;
  2239 function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl;
  2073 var gear: PGear;
  2240 var gear: PGear;
  2074 begin
  2241 begin
  2075     if CheckLuaParamCount(L, 3, 'SetGearTarget', 'gearUid, x, y') then
  2242     if CheckLuaParamCount(L, 3, 'SetGearTarget', 'gearUid, x, y') then
  2076         begin
  2243         begin
  2077         gear:= GearByUID(lua_tointeger(L, 1));
  2244         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2078         if gear <> nil then
  2245         if gear <> nil then
  2079             begin
  2246             begin
  2080             gear^.Target.X:= lua_tointeger(L, 2);
  2247             gear^.Target.X:= Trunc(lua_tonumber(L, 2));
  2081             gear^.Target.Y:= lua_tointeger(L, 3)
  2248             gear^.Target.Y:= Trunc(lua_tonumber(L, 3))
  2082             end
  2249             end
  2083         end;
  2250         end;
  2084     lc_setgeartarget:= 0
  2251     lc_setgeartarget:= 0
  2085 end;
  2252 end;
  2086 
  2253 
  2088 var gear: PGear;
  2255 var gear: PGear;
  2089 var t: LongInt;
  2256 var t: LongInt;
  2090 begin
  2257 begin
  2091     if CheckLuaParamCount(L, 1, 'GetGearVelocity', 'gearUid') then
  2258     if CheckLuaParamCount(L, 1, 'GetGearVelocity', 'gearUid') then
  2092         begin
  2259         begin
  2093         gear:= GearByUID(lua_tointeger(L, 1));
  2260         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2094         if gear <> nil then
  2261         if gear <> nil then
  2095             begin
  2262             begin
  2096             t:= hwRound(gear^.dX * 1000000);
  2263             t:= hwRound(gear^.dX * 1000000);
  2097             // gear dX determines hog orientation
  2264             // gear dX determines hog orientation
  2098             if (gear^.dX.isNegative) and (t = 0) then t:= -1;
  2265             if (gear^.dX.isNegative) and (t = 0) then t:= -1;
  2099             lua_pushinteger(L, t);
  2266             lua_pushnumber(L, t);
  2100             lua_pushinteger(L, hwRound(gear^.dY * 1000000))
  2267             lua_pushnumber(L, hwRound(gear^.dY * 1000000))
  2101             end
  2268             end
  2102         end
  2269         end
  2103     else
  2270     else
  2104         begin
  2271         begin
  2105         lua_pushnil(L);
  2272         lua_pushnil(L);
  2111 function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl;
  2278 function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl;
  2112 var gear: PGear;
  2279 var gear: PGear;
  2113 begin
  2280 begin
  2114     if CheckLuaParamCount(L, 3, 'SetGearVelocity', 'gearUid, dx, dy') then
  2281     if CheckLuaParamCount(L, 3, 'SetGearVelocity', 'gearUid, dx, dy') then
  2115         begin
  2282         begin
  2116         gear:= GearByUID(lua_tointeger(L, 1));
  2283         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2117         if gear <> nil then
  2284         if gear <> nil then
  2118             begin
  2285             begin
  2119             gear^.dX:= int2hwFloat(lua_tointeger(L, 2)) / 1000000;
  2286             gear^.dX:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 1000000;
  2120             gear^.dY:= int2hwFloat(lua_tointeger(L, 3)) / 1000000;
  2287             gear^.dY:= int2hwFloat(Trunc(lua_tonumber(L, 3))) / 1000000;
  2121             SetAllToActive;
  2288             SetAllToActive;
  2122             end
  2289             end
  2123         end;
  2290         end;
  2124     lc_setgearvelocity:= 0
  2291     lc_setgearvelocity:= 0
  2125 end;
  2292 end;
  2156         begin
  2323         begin
  2157         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2324         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2158         if at >= 0 then
  2325         if at >= 0 then
  2159             begin
  2326             begin
  2160             if np = 4 then
  2327             if np = 4 then
  2161                 ScriptSetAmmo(TAmmoType(at), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
  2328                 ScriptSetAmmo(TAmmoType(at), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)), 1)
  2162             else
  2329             else
  2163                 ScriptSetAmmo(TAmmoType(at), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
  2330                 ScriptSetAmmo(TAmmoType(at), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)));
  2164             end;
  2331             end;
  2165         end;
  2332         end;
  2166     lc_setammo:= 0
  2333     lc_setammo:= 0
  2167 end;
  2334 end;
  2168 
  2335 
  2174 begin
  2341 begin
  2175     if CheckLuaParamCount(L, 2, call, params) then
  2342     if CheckLuaParamCount(L, 2, call, params) then
  2176         begin
  2343         begin
  2177         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2344         at:= LuaToAmmoTypeOrd(L, 1, call, params);
  2178         if at >= 0 then
  2345         if at >= 0 then
  2179             ScriptSetAmmoDelay(TAmmoType(at), lua_tointeger(L, 2));
  2346             ScriptSetAmmoDelay(TAmmoType(at), Trunc(lua_tonumber(L, 2)));
  2180         end;
  2347         end;
  2181     lc_setammodelay:= 0
  2348     lc_setammodelay:= 0
  2182 end;
       
  2183 
       
  2184 function lc_setammostore(L : Plua_State) : LongInt; Cdecl;
       
  2185 begin
       
  2186     if CheckLuaParamCount(L, 4, 'SetAmmoStore', 'loadouts, probabilities, delays, reinforments') then
       
  2187         begin
       
  2188         ScriptAmmoLoadout:= lua_tostring(L, 1);
       
  2189         ScriptAmmoProbability:= lua_tostring(L, 2);
       
  2190         ScriptAmmoDelay:= lua_tostring(L, 3);
       
  2191         ScriptAmmoReinforcement:= lua_tostring(L, 4);
       
  2192         end;
       
  2193     lc_setammostore:= 0
       
  2194 end;
  2349 end;
  2195 
  2350 
  2196 function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
  2351 function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
  2197 var m : LongInt;
  2352 var m : LongInt;
  2198 begin
  2353 begin
  2199     if CheckLuaParamCount(L, 1, 'GetRandom', 'number') then
  2354     if CheckLuaParamCount(L, 1, 'GetRandom', 'number') then
  2200         begin
  2355         begin
  2201         m:= lua_tointeger(L, 1);
  2356         m:= Trunc(lua_tonumber(L, 1));
  2202         if (m > 0) then
  2357         if (m > 0) then
  2203             lua_pushinteger(L, GetRandom(m))
  2358             lua_pushnumber(L, GetRandom(m))
  2204         else
  2359         else
  2205             begin
  2360             begin
  2206             LuaError('Lua: Tried to pass 0 to GetRandom!');
  2361             LuaError('Lua: Tried to pass 0 to GetRandom!');
  2207             lua_pushnil(L);
  2362             lua_pushnil(L);
  2208             end
  2363             end
  2214 
  2369 
  2215 function lc_setwind(L : Plua_State) : LongInt; Cdecl;
  2370 function lc_setwind(L : Plua_State) : LongInt; Cdecl;
  2216 begin
  2371 begin
  2217     if CheckLuaParamCount(L, 1, 'SetWind', 'windSpeed') then
  2372     if CheckLuaParamCount(L, 1, 'SetWind', 'windSpeed') then
  2218         begin
  2373         begin
  2219         cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed;
  2374         cWindSpeed:= int2hwfloat(Trunc(lua_tonumber(L, 1))) / 100 * cMaxWindSpeed;
  2220         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  2375         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  2221         if cWindSpeed.isNegative then
  2376         if cWindSpeed.isNegative then
  2222             CWindSpeedf := -cWindSpeedf;
  2377             CWindSpeedf := -cWindSpeedf;
  2223         AddVisualGear(0, 0, vgtSmoothWindBar);
  2378         AddVisualGear(0, 0, vgtSmoothWindBar);
  2224         end;
  2379         end;
  2237 function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
  2392 function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
  2238 var gear : PGear;
  2393 var gear : PGear;
  2239 begin
  2394 begin
  2240     if CheckLuaParamCount(L, 1, 'GetGearRadius', 'gearUid') then
  2395     if CheckLuaParamCount(L, 1, 'GetGearRadius', 'gearUid') then
  2241         begin
  2396         begin
  2242         gear:= GearByUID(lua_tointeger(L, 1));
  2397         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2243         if gear <> nil then
  2398         if gear <> nil then
  2244             lua_pushinteger(L, gear^.Radius)
  2399             lua_pushnumber(L, gear^.Radius)
  2245         else
  2400         else
  2246             lua_pushnil(L);
  2401             lua_pushnil(L);
  2247         end
  2402         end
  2248     else
  2403     else
  2249         lua_pushnil(L); // return value on stack (nil)
  2404         lua_pushnil(L); // return value on stack (nil)
  2253 function lc_gethoghat(L : Plua_State): LongInt; Cdecl;
  2408 function lc_gethoghat(L : Plua_State): LongInt; Cdecl;
  2254 var gear : PGear;
  2409 var gear : PGear;
  2255 begin
  2410 begin
  2256     if CheckLuaParamCount(L, 1, 'GetHogHat', 'gearUid') then
  2411     if CheckLuaParamCount(L, 1, 'GetHogHat', 'gearUid') then
  2257         begin
  2412         begin
  2258         gear := GearByUID(lua_tointeger(L, 1));
  2413         gear := GearByUID(Trunc(lua_tonumber(L, 1)));
  2259         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  2414         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  2260             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat))
  2415             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat))
  2261         else
  2416         else
  2262             lua_pushnil(L);
  2417             lua_pushnil(L);
  2263         end
  2418         end
  2270 var gear : PGear;
  2425 var gear : PGear;
  2271     hat: ShortString;
  2426     hat: ShortString;
  2272 begin
  2427 begin
  2273     if CheckLuaParamCount(L, 2, 'SetHogHat', 'gearUid, hat') then
  2428     if CheckLuaParamCount(L, 2, 'SetHogHat', 'gearUid, hat') then
  2274         begin
  2429         begin
  2275         gear:= GearByUID(lua_tointeger(L, 1));
  2430         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2276         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  2431         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  2277             begin
  2432             begin
  2278             hat:= lua_tostring(L, 2);
  2433             hat:= lua_tostring(L, 2);
  2279             gear^.Hedgehog^.Hat:= hat;
  2434             gear^.Hedgehog^.Hat:= hat;
  2280             AddFileLog('Changed hat to: '+hat);
  2435             AddFileLog('Changed hat to: '+hat);
  2299 begin
  2454 begin
  2300     placed:= false;
  2455     placed:= false;
  2301     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2456     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2302         begin
  2457         begin
  2303         if not lua_isnoneornil(L, 5) then
  2458         if not lua_isnoneornil(L, 5) then
  2304             tint := lua_tointeger(L, 5)
  2459             tint := Trunc(lua_tonumber(L, 5))
  2305         else tint := $FFFFFFFF;
  2460         else tint := $FFFFFFFF;
  2306         if not lua_isnoneornil(L, 6) then
  2461         if not lua_isnoneornil(L, 6) then
  2307             behind := lua_toboolean(L, 6)
  2462             behind := lua_toboolean(L, 6)
  2308         else behind := false;
  2463         else behind := false;
  2309         if not lua_isnoneornil(L, 7) then
  2464         if not lua_isnoneornil(L, 7) then
  2314         else flipVert := false;
  2469         else flipVert := false;
  2315         lf:= 0;
  2470         lf:= 0;
  2316 
  2471 
  2317         // accept any amount of landflags, loop is never executed if n<9
  2472         // accept any amount of landflags, loop is never executed if n<9
  2318         for i:= 9 to n do
  2473         for i:= 9 to n do
  2319             lf:= lf or lua_tointeger(L, i);
  2474             lf:= lf or Trunc(lua_tonumber(L, i));
  2320 
  2475 
  2321         n:= LuaToSpriteOrd(L, 3, call, params);
  2476         n:= LuaToSpriteOrd(L, 3, call, params);
  2322         if n >= 0 then
  2477         if n >= 0 then
  2323             begin
  2478             begin
  2324             spr:= TSprite(n);
  2479             spr:= TSprite(n);
  2325             if SpritesData[spr].Surface = nil then
  2480             if SpritesData[spr].Surface = nil then
  2326                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2481                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2327             else
  2482             else
  2328                 placed:= ForcePlaceOnLand(
  2483                 placed:= ForcePlaceOnLand(
  2329                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
  2484                     Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
  2330                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
  2485                     Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
  2331                     spr, lua_tointeger(L, 4), lf, tint, behind, flipHoriz, flipVert);
  2486                     spr, Trunc(lua_tonumber(L, 4)), lf, tint, behind, flipHoriz, flipVert);
  2332             end;
  2487             end;
  2333         end;
  2488         end;
  2334 
  2489 
  2335     lua_pushboolean(L, placed);
  2490     lua_pushboolean(L, placed);
  2336     lc_placesprite:= 1
  2491     lc_placesprite:= 1
  2361         else flipVert := false;
  2516         else flipVert := false;
  2362         lf:= 0;
  2517         lf:= 0;
  2363 
  2518 
  2364         // accept any amount of landflags, loop is never executed if n<9
  2519         // accept any amount of landflags, loop is never executed if n<9
  2365         for i:= 9 to n do
  2520         for i:= 9 to n do
  2366             lf:= lf or lua_tointeger(L, i);
  2521             lf:= lf or Trunc(lua_tonumber(L, i));
  2367 
  2522 
  2368         n:= LuaToSpriteOrd(L, 3, call, params);
  2523         n:= LuaToSpriteOrd(L, 3, call, params);
  2369         if n >= 0 then
  2524         if n >= 0 then
  2370             begin
  2525             begin
  2371             spr:= TSprite(n);
  2526             spr:= TSprite(n);
  2372             if SpritesData[spr].Surface = nil then
  2527             if SpritesData[spr].Surface = nil then
  2373                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2528                 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
  2374             else
  2529             else
  2375                 EraseLand(
  2530                 EraseLand(
  2376                     lua_tointeger(L, 1) - SpritesData[spr].Width div 2,
  2531                     Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
  2377                     lua_tointeger(L, 2) - SpritesData[spr].Height div 2,
  2532                     Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
  2378                     spr, lua_tointeger(L, 4), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
  2533                     spr, Trunc(lua_tonumber(L, 4)), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
  2379             end;
  2534             end;
  2380         end;
  2535         end;
  2381     lc_erasesprite:= 0
  2536     lc_erasesprite:= 0
  2382 end;
  2537 end;
  2383 
  2538 
  2385 var placed: boolean;
  2540 var placed: boolean;
  2386 begin
  2541 begin
  2387     placed:= false;
  2542     placed:= false;
  2388     if CheckLuaParamCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then
  2543     if CheckLuaParamCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then
  2389         placed:= TryPlaceOnLandSimple(
  2544         placed:= TryPlaceOnLandSimple(
  2390             lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2,
  2545             Trunc(lua_tonumber(L, 1)) - SpritesData[sprAmGirder].Width div 2,
  2391             lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2,
  2546             Trunc(lua_tonumber(L, 2)) - SpritesData[sprAmGirder].Height div 2,
  2392             sprAmGirder, lua_tointeger(L, 3), true, false);
  2547             sprAmGirder, Trunc(lua_tonumber(L, 3)), true, false);
  2393 
  2548 
  2394     lua_pushboolean(L, placed);
  2549     lua_pushboolean(L, placed);
  2395     lc_placegirder:= 1
  2550     lc_placegirder:= 1
  2396 end;
  2551 end;
  2397 
  2552 
       
  2553 function lc_placerubber(L : Plua_State) : LongInt; Cdecl;
       
  2554 var placed: boolean;
       
  2555 begin
       
  2556     placed:= false;
       
  2557     if CheckLuaParamCount(L, 3, 'PlaceRubber', 'x, y, frameIdx') then
       
  2558         placed:= TryPlaceOnLand(
       
  2559             Trunc(lua_tonumber(L, 1)) - SpritesData[sprAmRubber].Width div 2,
       
  2560             Trunc(lua_tonumber(L, 2)) - SpritesData[sprAmRubber].Height div 2,
       
  2561             sprAmRubber, Trunc(lua_tonumber(L, 3)), true, lfBouncy);
       
  2562 
       
  2563     lua_pushboolean(L, placed);
       
  2564     lc_placerubber:= 1
       
  2565 end;
       
  2566 
  2398 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
  2567 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
  2399 begin
  2568 begin
  2400     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, 'GetCurAmmoType', '')) then
  2569     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, 'GetCurAmmoType', '')) then
  2401         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType))
  2570         lua_pushnumber(L, ord(CurrentHedgehog^.CurAmmoType))
  2402     else
  2571     else
  2403         lua_pushinteger(L, ord(amNothing));
  2572         lua_pushnumber(L, ord(amNothing));
  2404     lc_getcurammotype := 1;
  2573     lc_getcurammotype := 1;
  2405 end;
  2574 end;
  2406 
  2575 
  2407 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
  2576 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
  2408 begin
  2577 begin
  2422 function lc_hidehog(L: Plua_State): LongInt; Cdecl;
  2591 function lc_hidehog(L: Plua_State): LongInt; Cdecl;
  2423 var gear: PGear;
  2592 var gear: PGear;
  2424 begin
  2593 begin
  2425     if CheckLuaParamCount(L, 1, 'HideHog', 'gearUid') then
  2594     if CheckLuaParamCount(L, 1, 'HideHog', 'gearUid') then
  2426         begin
  2595         begin
  2427         gear:= GearByUID(lua_tointeger(L, 1));
  2596         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2428         HideHog(gear^.hedgehog)
  2597         if (gear <> nil) and (gear^.hedgehog <> nil) then
  2429         end;
  2598             begin
  2430     lc_hidehog := 0;
  2599             HideHog(gear^.hedgehog);
       
  2600             lua_pushboolean(L, true);
       
  2601             end
       
  2602         else
       
  2603             lua_pushboolean(L, false);
       
  2604         end;
       
  2605     lc_hidehog := 1;
  2431 end;
  2606 end;
  2432 
  2607 
  2433 function lc_restorehog(L: Plua_State): LongInt; Cdecl;
  2608 function lc_restorehog(L: Plua_State): LongInt; Cdecl;
  2434 var i, h: LongInt;
  2609 var i, h: LongInt;
  2435     uid: LongWord;
  2610     uid: LongWord;
  2436 begin
  2611 begin
  2437     if CheckLuaParamCount(L, 1, 'RestoreHog', 'gearUid') then
  2612     if CheckLuaParamCount(L, 1, 'RestoreHog', 'gearUid') then
  2438         begin
  2613         begin
  2439         uid:= LongWord(lua_tointeger(L, 1));
  2614         uid:= LongWord(Trunc(lua_tonumber(L, 1)));
  2440         if TeamsCount > 0 then
  2615         if TeamsCount > 0 then
  2441             for i:= 0 to Pred(TeamsCount) do
  2616             for i:= 0 to Pred(TeamsCount) do
  2442                 for h:= 0 to cMaxHHIndex do
  2617                 for h:= 0 to cMaxHHIndex do
  2443                     if (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil) and (TeamsArray[i]^.Hedgehogs[h].GearHidden^.uid = uid) then
  2618                     if (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil) and (TeamsArray[i]^.Hedgehogs[h].GearHidden^.uid = uid) then
  2444                         begin
  2619                         begin
  2454 var rtn: Boolean;
  2629 var rtn: Boolean;
  2455 begin
  2630 begin
  2456     if CheckLuaParamCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then
  2631     if CheckLuaParamCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then
  2457         begin
  2632         begin
  2458         rtn:= TestRectangleForObstacle(
  2633         rtn:= TestRectangleForObstacle(
  2459                     lua_tointeger(L, 1),
  2634                     Trunc(lua_tonumber(L, 1)),
  2460                     lua_tointeger(L, 2),
  2635                     Trunc(lua_tonumber(L, 2)),
  2461                     lua_tointeger(L, 3),
  2636                     Trunc(lua_tonumber(L, 3)),
  2462                     lua_tointeger(L, 4),
  2637                     Trunc(lua_tonumber(L, 4)),
  2463                     lua_toboolean(L, 5)
  2638                     lua_toboolean(L, 5)
  2464                     );
  2639                     );
  2465         lua_pushboolean(L, rtn);
  2640         lua_pushboolean(L, rtn);
  2466         end
  2641         end
  2467     else
  2642     else
  2471 
  2646 
  2472 
  2647 
  2473 function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
  2648 function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
  2474 begin
  2649 begin
  2475     if CheckLuaParamCount(L, 0, 'GetGravity', '') then
  2650     if CheckLuaParamCount(L, 0, 'GetGravity', '') then
  2476         lua_pushinteger(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed)));
  2651         lua_pushnumber(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed)));
  2477     lc_getgravity:= 1
  2652     lc_getgravity:= 1
  2478 end;
  2653 end;
  2479 
  2654 
  2480 function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
  2655 function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
  2481 begin
  2656 begin
  2482     if CheckLuaParamCount(L, 1, 'SetGravity', 'percent') then
  2657     if CheckLuaParamCount(L, 1, 'SetGravity', 'percent') then
  2483         begin
  2658         begin
  2484         cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed;
  2659         cGravity:= _0_02 * Trunc(lua_tonumber(L, 1)) * cMaxWindSpeed;
  2485         cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02
  2660         cGravityf:= 0.00025 * Trunc(lua_tonumber(L, 1)) * 0.02
  2486         end;
  2661         end;
  2487     lc_setgravity:= 0
  2662     lc_setgravity:= 0
  2488 end;
  2663 end;
  2489 
  2664 
  2490 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
  2665 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
  2491 var iterator: PGear;
  2666 var iterator: PGear;
  2492 begin
  2667 begin
  2493     if CheckLuaParamCount(L, 1, 'SetWaterLine', 'waterline') then
  2668     if CheckLuaParamCount(L, 1, 'SetWaterLine', 'waterline') then
  2494         begin
  2669         begin
  2495         cWaterLine:= lua_tointeger(L,1);
  2670         cWaterLine:= Trunc(lua_tonumber(L,1));
  2496         AllInactive:= false;
  2671         AllInactive:= false;
  2497         iterator:= GearsList;
  2672         iterator:= GearsList;
  2498         while iterator <> nil do
  2673         while iterator <> nil do
  2499             begin
  2674             begin
  2500             if not (iterator^.Kind in [gtPortal, gtAirAttack]) and (iterator^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) then
  2675             if not (iterator^.Kind in [gtPortal, gtAirAttack]) and (iterator^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) then
  2513 function lc_setgearaihints(L : Plua_State) : LongInt; Cdecl;
  2688 function lc_setgearaihints(L : Plua_State) : LongInt; Cdecl;
  2514 var gear: PGear;
  2689 var gear: PGear;
  2515 begin
  2690 begin
  2516     if CheckLuaParamCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then
  2691     if CheckLuaParamCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then
  2517         begin
  2692         begin
  2518         gear:= GearByUID(lua_tointeger(L, 1));
  2693         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2519         if gear <> nil then
  2694         if gear <> nil then
  2520             gear^.aihints:= lua_tointeger(L, 2);
  2695             gear^.aihints:= Trunc(lua_tonumber(L, 2));
  2521         end;
  2696         end;
  2522     lc_setgearaihints:= 0
  2697     lc_setgearaihints:= 0
  2523 end;
  2698 end;
  2524 
  2699 
  2525 
  2700 
  2534 
  2709 
  2535 
  2710 
  2536 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  2711 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  2537 begin
  2712 begin
  2538     if CheckLuaParamCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then
  2713     if CheckLuaParamCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then
  2539         declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4));
  2714         declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), Trunc(lua_tonumber(L, 4)));
  2540     lc_declareachievement:= 0
  2715     lc_declareachievement:= 0
  2541 end;
  2716 end;
  2542 
  2717 
       
  2718 function lc_getammoname(L : Plua_state) : LongInt; Cdecl;
       
  2719 var np, at: LongInt;
       
  2720     ignoreOverwrite: Boolean;
       
  2721 const call = 'GetAmmoName';
       
  2722       params = 'ammoType [, ignoreOverwrite ]';
       
  2723 begin
       
  2724     if CheckAndFetchParamCountRange(L, 1, 2, call, params, np) then
       
  2725         begin
       
  2726         at:= LuaToAmmoTypeOrd(L, 1, call, params);
       
  2727         ignoreOverwrite := false;
       
  2728         if np > 1 then
       
  2729             ignoreOverwrite := lua_toboolean(L, 2);
       
  2730         if at >= 0 then
       
  2731             if (not ignoreOverwrite) and (length(trluaammo[Ammoz[TAmmoType(at)].NameId]) > 0) then
       
  2732                 lua_pushstring(L, PChar(trluaammo[Ammoz[TAmmoType(at)].NameId]))
       
  2733             else
       
  2734                 lua_pushstring(L, PChar(trammo[Ammoz[TAmmoType(at)].NameId]));
       
  2735         end
       
  2736     else
       
  2737         lua_pushnil(L);
       
  2738     lc_getammoname:= 1;
       
  2739 end;
       
  2740 
  2543 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
  2741 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
  2544 begin
  2742 begin
  2545     if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
  2743     if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
  2546         startGhostPoints(lua_tointeger(L, 1));
  2744         startGhostPoints(Trunc(lua_tonumber(L, 1)));
  2547     lc_startghostpoints:= 0
  2745     lc_startghostpoints:= 0
  2548 end;
  2746 end;
  2549 
  2747 
  2550 function lc_dumppoint(L : Plua_State) : LongInt; Cdecl;
  2748 function lc_dumppoint(L : Plua_State) : LongInt; Cdecl;
  2551 begin
  2749 begin
  2552     if CheckLuaParamCount(L, 2, 'DumpPoint', 'x, y') then
  2750     if CheckLuaParamCount(L, 2, 'DumpPoint', 'x, y') then
  2553         dumpPoint(lua_tointeger(L, 1), lua_tointeger(L, 2));
  2751         dumpPoint(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)));
  2554     lc_dumppoint:= 0
  2752     lc_dumppoint:= 0
  2555 end;
  2753 end;
  2556 
  2754 
  2557 
  2755 
  2558 procedure ScriptFlushPoints();
  2756 procedure ScriptFlushPoints();
  2566 var np, param: LongInt;
  2764 var np, param: LongInt;
  2567 begin
  2765 begin
  2568     if CheckAndFetchParamCountRange(L, 2, 4, 'AddPoint', 'x, y [, width [, erase] ]', np) then
  2766     if CheckAndFetchParamCountRange(L, 2, 4, 'AddPoint', 'x, y [, width [, erase] ]', np) then
  2569         begin
  2767         begin
  2570         // x
  2768         // x
  2571         param:= LongInt(lua_tointeger(L,1));
  2769         param:= LongInt(Trunc(lua_tonumber(L,1)));
  2572         PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
  2770         PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
  2573         PointsBuffer:= PointsBuffer + char((param and $FF));
  2771         PointsBuffer:= PointsBuffer + char((param and $FF));
  2574         // y
  2772         // y
  2575         param:= LongInt(lua_tointeger(L,2));
  2773         param:= LongInt(Trunc(lua_tonumber(L,2)));
  2576         PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
  2774         PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
  2577         PointsBuffer:= PointsBuffer + char((param and $FF));
  2775         PointsBuffer:= PointsBuffer + char((param and $FF));
  2578         // width
  2776         // width
  2579         if np > 2 then
  2777         if np > 2 then
  2580             begin
  2778             begin
  2581             param:= lua_tointeger(L,3);
  2779             param:= Trunc(lua_tonumber(L,3));
  2582             param:= (param or $80);
  2780             param:= (param or $80);
  2583             // erase
  2781             // erase
  2584             if (np > 3) and lua_toboolean(L, 4) then
  2782             if (np > 3) and lua_toboolean(L, 4) then
  2585                 param:= (param or $40);
  2783                 param:= (param or $40);
  2586             PointsBuffer:= PointsBuffer + char(param);
  2784             PointsBuffer:= PointsBuffer + char(param);
  2613     params = 'TEST_SUCCESSFUL or TEST_FAILED';
  2811     params = 'TEST_SUCCESSFUL or TEST_FAILED';
  2614 begin
  2812 begin
  2615     if CheckLuaParamCount(L, 1, call, params) then
  2813     if CheckLuaParamCount(L, 1, call, params) then
  2616         begin
  2814         begin
  2617 
  2815 
  2618         case lua_tointeger(L, 1) of
  2816         case Trunc(lua_tonumber(L, 1)) of
  2619             HaltTestSuccess : rstring:= 'Success';
  2817             HaltTestSuccess : rstring:= 'Success';
  2620             HaltTestFailed: rstring:= 'FAILED';
  2818             HaltTestFailed: rstring:= 'FAILED';
  2621         else
  2819         else
  2622             begin
  2820             begin
  2623             LuaCallError('Parameter must be either ' + params, call, params);
  2821             LuaCallError('Parameter must be either ' + params, call, params);
  2626         end;
  2824         end;
  2627 
  2825 
  2628         if cTestLua then
  2826         if cTestLua then
  2629             begin
  2827             begin
  2630             WriteLnToConsole('Lua test finished, result: ' + rstring);
  2828             WriteLnToConsole('Lua test finished, result: ' + rstring);
  2631             halt(lua_tointeger(L, 1));
  2829             halt(Trunc(lua_tonumber(L, 1)));
  2632             end
  2830             end
  2633         else LuaError('Not in lua test mode, engine will keep running. Reported test result: ' + rstring);
  2831         else LuaError('Not in lua test mode, engine will keep running. Reported test result: ' + rstring);
  2634 
  2832 
  2635         end;
  2833         end;
  2636 
  2834 
  2663     lua_setglobal(luaState, Str2PChar(name));
  2861     lua_setglobal(luaState, Str2PChar(name));
  2664 end;
  2862 end;
  2665 
  2863 
  2666 procedure ScriptSetInteger(name : shortstring; value : LongInt);
  2864 procedure ScriptSetInteger(name : shortstring; value : LongInt);
  2667 begin
  2865 begin
  2668     lua_pushinteger(luaState, value);
  2866     lua_pushnumber(luaState, value);
  2669     lua_setglobal(luaState, Str2PChar(name));
  2867     lua_setglobal(luaState, Str2PChar(name));
  2670 end;
  2868 end;
  2671 
  2869 
  2672 procedure ScriptSetString(name : shortstring; value : shortstring);
  2870 procedure ScriptSetString(name : shortstring; value : shortstring);
  2673 begin
  2871 begin
  2676 end;
  2874 end;
  2677 
  2875 
  2678 function ScriptGetInteger(name : shortstring) : LongInt;
  2876 function ScriptGetInteger(name : shortstring) : LongInt;
  2679 begin
  2877 begin
  2680     lua_getglobal(luaState, Str2PChar(name));
  2878     lua_getglobal(luaState, Str2PChar(name));
  2681     ScriptGetInteger:= lua_tointeger(luaState, -1);
  2879     ScriptGetInteger:= Trunc(lua_tonumber(luaState, -1));
  2682     lua_pop(luaState, 1);
  2880     lua_pop(luaState, 1);
  2683 end;
  2881 end;
  2684 
  2882 
  2685 function ScriptGetString(name : shortstring) : shortstring;
  2883 function ScriptGetString(name : shortstring) : shortstring;
  2686 begin
  2884 begin
  2687     lua_getglobal(luaState, Str2PChar(name));
  2885     lua_getglobal(luaState, Str2PChar(name));
  2688     ScriptGetString:= lua_tostring(luaState, -1);
  2886     ScriptGetString:= lua_tostring(luaState, -1);
       
  2887     lua_pop(luaState, 1);
       
  2888 end;
       
  2889 
       
  2890 function ScriptGetAnsiString(name : shortstring) : ansistring;
       
  2891 begin
       
  2892     lua_getglobal(luaState, Str2PChar(name));
       
  2893     ScriptGetAnsiString:= lua_tostringa(luaState, -1);
  2689     lua_pop(luaState, 1);
  2894     lua_pop(luaState, 1);
  2690 end;
  2895 end;
  2691 
  2896 
  2692 procedure ScriptOnPreviewInit;
  2897 procedure ScriptOnPreviewInit;
  2693 begin
  2898 begin
  2719     exit;
  2924     exit;
  2720 
  2925 
  2721 // push game variables so they may be modified by the script
  2926 // push game variables so they may be modified by the script
  2722 ScriptSetInteger('CursorX', CursorPoint.X);
  2927 ScriptSetInteger('CursorX', CursorPoint.X);
  2723 ScriptSetInteger('CursorY', CursorPoint.Y);
  2928 ScriptSetInteger('CursorY', CursorPoint.Y);
  2724 ScriptSetInteger('BorderColor', ExplosionBorderColor);
       
  2725 ScriptSetInteger('GameFlags', GameFlags);
  2929 ScriptSetInteger('GameFlags', GameFlags);
       
  2930 ScriptSetInteger('WorldEdge', ord(WorldEdge));
  2726 ScriptSetString('Seed', cSeed);
  2931 ScriptSetString('Seed', cSeed);
  2727 ScriptSetInteger('TemplateFilter', cTemplateFilter);
  2932 ScriptSetInteger('TemplateFilter', cTemplateFilter);
  2728 ScriptSetInteger('TemplateNumber', LuaTemplateNumber);
  2933 ScriptSetInteger('TemplateNumber', LuaTemplateNumber);
  2729 ScriptSetInteger('MapGen', ord(cMapGen));
  2934 ScriptSetInteger('MapGen', ord(cMapGen));
  2730 ScriptSetInteger('MapFeatureSize', cFeatureSize);
  2935 ScriptSetInteger('MapFeatureSize', cFeatureSize);
  2737 ScriptSetInteger('DamagePercent', cDamagePercent);
  2942 ScriptSetInteger('DamagePercent', cDamagePercent);
  2738 ScriptSetInteger('RopePercent', cRopePercent);
  2943 ScriptSetInteger('RopePercent', cRopePercent);
  2739 ScriptSetInteger('MinesNum', cLandMines);
  2944 ScriptSetInteger('MinesNum', cLandMines);
  2740 ScriptSetInteger('MinesTime', cMinesTime);
  2945 ScriptSetInteger('MinesTime', cMinesTime);
  2741 ScriptSetInteger('MineDudPercent', cMineDudPercent);
  2946 ScriptSetInteger('MineDudPercent', cMineDudPercent);
       
  2947 ScriptSetInteger('AirMinesNum', cAirMines);
  2742 ScriptSetInteger('Explosives', cExplosives);
  2948 ScriptSetInteger('Explosives', cExplosives);
  2743 ScriptSetInteger('Delay', cInactDelay);
  2949 ScriptSetInteger('Delay', cInactDelay);
  2744 ScriptSetInteger('Ready', cReadyDelay);
  2950 ScriptSetInteger('Ready', cReadyDelay);
  2745 ScriptSetInteger('SuddenDeathTurns', cSuddenDTurns);
  2951 ScriptSetInteger('SuddenDeathTurns', cSuddenDTurns);
  2746 ScriptSetInteger('WaterRise', cWaterRise);
  2952 ScriptSetInteger('WaterRise', cWaterRise);
  2747 ScriptSetInteger('HealthDecrease', cHealthDecrease);
  2953 ScriptSetInteger('HealthDecrease', cHealthDecrease);
  2748 ScriptSetInteger('GetAwayTime', cGetAwayTime);
  2954 ScriptSetInteger('GetAwayTime', cGetAwayTime);
       
  2955 ScriptSetInteger('AmmoTypeMax', Ord(High(TAmmoType)));
  2749 ScriptSetString('Map', cMapName);
  2956 ScriptSetString('Map', cMapName);
  2750 ScriptSetString('Theme', Theme);
  2957 ScriptSetString('Theme', Theme);
  2751 ScriptSetString('Goals', '');
  2958 ScriptSetString('Goals', '');
  2752 
  2959 
  2753 ScriptCall('onGameInit');
  2960 ScriptCall('onGameInit');
  2757 cTemplateFilter  := ScriptGetInteger('TemplateFilter');
  2964 cTemplateFilter  := ScriptGetInteger('TemplateFilter');
  2758 LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
  2965 LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
  2759 cMapGen          := TMapGen(ScriptGetInteger('MapGen'));
  2966 cMapGen          := TMapGen(ScriptGetInteger('MapGen'));
  2760 cFeatureSize     := ScriptGetInteger('MapFeatureSize');
  2967 cFeatureSize     := ScriptGetInteger('MapFeatureSize');
  2761 GameFlags        := ScriptGetInteger('GameFlags');
  2968 GameFlags        := ScriptGetInteger('GameFlags');
       
  2969 WorldEdge        := TWorldEdge(ScriptGetInteger('WorldEdge'));
  2762 cHedgehogTurnTime:= ScriptGetInteger('TurnTime');
  2970 cHedgehogTurnTime:= ScriptGetInteger('TurnTime');
  2763 cCaseFactor      := ScriptGetInteger('CaseFreq');
  2971 cCaseFactor      := ScriptGetInteger('CaseFreq');
  2764 cHealthCaseProb  := ScriptGetInteger('HealthCaseProb');
  2972 cHealthCaseProb  := ScriptGetInteger('HealthCaseProb');
  2765 cHealthCaseAmount:= ScriptGetInteger('HealthCaseAmount');
  2973 cHealthCaseAmount:= ScriptGetInteger('HealthCaseAmount');
  2766 cDamagePercent   := ScriptGetInteger('DamagePercent');
  2974 cDamagePercent   := ScriptGetInteger('DamagePercent');
  2767 cRopePercent     := ScriptGetInteger('RopePercent');
  2975 cRopePercent     := ScriptGetInteger('RopePercent');
  2768 cLandMines       := ScriptGetInteger('MinesNum');
  2976 cLandMines       := ScriptGetInteger('MinesNum');
  2769 cMinesTime       := ScriptGetInteger('MinesTime');
  2977 cMinesTime       := ScriptGetInteger('MinesTime');
  2770 cMineDudPercent  := ScriptGetInteger('MineDudPercent');
  2978 cMineDudPercent  := ScriptGetInteger('MineDudPercent');
       
  2979 cAirMines        := ScriptGetInteger('AirMinesNum');
  2771 cExplosives      := ScriptGetInteger('Explosives');
  2980 cExplosives      := ScriptGetInteger('Explosives');
  2772 cInactDelay      := ScriptGetInteger('Delay');
  2981 cInactDelay      := ScriptGetInteger('Delay');
  2773 cReadyDelay      := ScriptGetInteger('Ready');
  2982 cReadyDelay      := ScriptGetInteger('Ready');
  2774 cSuddenDTurns    := ScriptGetInteger('SuddenDeathTurns');
  2983 cSuddenDTurns    := ScriptGetInteger('SuddenDeathTurns');
  2775 cWaterRise       := ScriptGetInteger('WaterRise');
  2984 cWaterRise       := ScriptGetInteger('WaterRise');
  2778 
  2987 
  2779 if cMapName <> ScriptGetString('Map') then
  2988 if cMapName <> ScriptGetString('Map') then
  2780     ParseCommand('map ' + ScriptGetString('Map'), true, true);
  2989     ParseCommand('map ' + ScriptGetString('Map'), true, true);
  2781 if ScriptGetString('Theme') <> '' then
  2990 if ScriptGetString('Theme') <> '' then
  2782     ParseCommand('theme ' + ScriptGetString('Theme'), true, true);
  2991     ParseCommand('theme ' + ScriptGetString('Theme'), true, true);
  2783 LuaGoals:= ScriptGetString('Goals');
  2992 LuaGoals:= ScriptGetAnsiString('Goals');
  2784 
  2993 
  2785 // Support lua changing the ammo layout - assume all hogs have same ammo, note this might leave a few ammo stores lying around.
  2994 // Support lua changing the ammo layout - assume all hogs have same ammo, note this might leave a few ammo stores lying around.
  2786 k:= 0;
  2995 k:= 0;
  2787 if (GameFlags and gfSharedAmmo) <> 0 then
  2996 if (GameFlags and gfSharedAmmo) <> 0 then
  2788     for i:= 0 to Pred(ClansCount) do
  2997     for i:= 0 to Pred(ClansCount) do
  2837 end;
  3046 end;
  2838 
  3047 
  2839 // custom script loader via physfs, passed to lua_load
  3048 // custom script loader via physfs, passed to lua_load
  2840 const BUFSIZE = 1024;
  3049 const BUFSIZE = 1024;
  2841 
  3050 
       
  3051 var inComment: boolean;
       
  3052 var inQuote: boolean;
       
  3053 var locSum: LongWord;
       
  3054 var braceCount: LongWord;
       
  3055 var wordCount: LongWord;
       
  3056 var lastChar: char;
       
  3057 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧
       
  3058 function  ScriptReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; Cdecl;
       
  3059 var mybuf: PChar;
       
  3060     i: LongInt;
       
  3061 begin
       
  3062     SetRandomSeed(cSeed,true);
       
  3063     mybuf := physfsReader(L, f, sz);
       
  3064     if (mybuf <> nil) and ((sz^) > 0) then
       
  3065         begin
       
  3066             for i:= 0 to sz^-1 do
       
  3067                 begin
       
  3068                     if (lastChar = '-') and (mybuf[i] = '-') then
       
  3069                         inComment := true
       
  3070                     // gonna add any non-magic whitespace and skip - just to make comment avoidance easier
       
  3071                     else if not inComment and (byte(mybuf[i]) > $20) and (byte(mybuf[i]) < $7F) and (mybuf[i]<>'-') then
       
  3072                         begin
       
  3073                         AddRandomness(byte(mybuf[i]));  // wish I had the seed...
       
  3074                         CheckSum := CheckSum xor GetRandom($FFFFFFFF);
       
  3075                         end;
       
  3076                     lastChar := mybuf[i];
       
  3077                     if (byte(mybuf[i]) = $0D) or (byte(mybuf[i]) = $0A) then
       
  3078                         inComment := false
       
  3079                 end;
       
  3080         end;
       
  3081     ScriptReader:= mybuf
       
  3082 end;
       
  3083 function  ScriptLocaleReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; Cdecl;
       
  3084 var mybuf: PChar;
       
  3085     i: LongInt;
       
  3086 begin
       
  3087     mybuf := physfsReader(L, f, sz);
       
  3088     if (mybuf <> nil) and ((sz^) > 0) then
       
  3089         begin
       
  3090             for i:= 0 to sz^-1 do
       
  3091                 begin
       
  3092                     if not inComment and (mybuf[i] = '"') and (lastChar <> '\') then
       
  3093                         inQuote := not inQuote;
       
  3094                     if not inQuote and (lastChar = '-') and (mybuf[i] = '-') then
       
  3095                         inComment := true;
       
  3096                     if not inComment and (not inQuote) then
       
  3097                        locSum := locSum xor (byte(mybuf[i]) shl (i mod 4));
       
  3098                     if not inComment and (not inQuote) and
       
  3099                         ((mybuf[i] = '(') or
       
  3100                         (mybuf[i] = ')') or
       
  3101                         (mybuf[i] = '+') or
       
  3102                         (mybuf[i] = '#') or
       
  3103                         (braceCount > 2) or
       
  3104                         (wordCount > 6)) then
       
  3105                        CheckSum := locSum;
       
  3106                     if not inComment and (not inQuote) and ((mybuf[i] = '{') or (mybuf[i] = '}')) then
       
  3107                         inc(braceCount);
       
  3108                     if not inComment and (not inQuote) and
       
  3109                         (((byte(mybuf[i]) > $40) and (byte(mybuf[i]) < $5B)) or
       
  3110                         ((byte(mybuf[i]) > $60) and (byte(mybuf[i]) < $7B)) or
       
  3111                         ((byte(mybuf[i]) >= $30) and (byte(mybuf[i]) < $3A))) then
       
  3112                         inc(wordCount);
       
  3113                     lastChar := mybuf[i];
       
  3114                     if (byte(mybuf[i]) = $0D) or (byte(mybuf[i]) = $0A) then
       
  3115                         inComment := false
       
  3116                 end;
       
  3117         end;
       
  3118     ScriptLocaleReader:= mybuf
       
  3119 end;
       
  3120 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧
       
  3121 
  2842 procedure ScriptLoad(name : shortstring);
  3122 procedure ScriptLoad(name : shortstring);
  2843 var ret : LongInt;
  3123 var ret : LongInt;
  2844       s : shortstring;
  3124       s : shortstring;
  2845       f : PFSFile;
  3125       f : PFSFile;
  2846     buf : array[0..Pred(BUFSIZE)] of byte;
  3126     buf : array[0..Pred(BUFSIZE)] of byte;
  2847 begin
  3127 begin
       
  3128 inComment:= false;
       
  3129 inQuote:= false;
       
  3130 lastChar:= 'X';
       
  3131 braceCount:= 0;
       
  3132 wordCount:= 0;
       
  3133 locSum:= 0;
  2848 s:= cPathz[ptData] + name;
  3134 s:= cPathz[ptData] + name;
  2849 if not pfsExists(s) then
  3135 if not pfsExists(s) then
  2850     begin
  3136     begin
  2851     AddFileLog('[LUA] Script not found: ' + name);
  3137     AddFileLog('[LUA] Script not found: ' + name);
  2852     exit;
  3138     exit;
  2854 
  3140 
  2855 f:= pfsOpenRead(s);
  3141 f:= pfsOpenRead(s);
  2856 if f = nil then
  3142 if f = nil then
  2857     exit;
  3143     exit;
  2858 
  3144 
       
  3145 hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp'));
       
  3146 
  2859 physfsReaderSetBuffer(@buf);
  3147 physfsReaderSetBuffer(@buf);
  2860 ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s));
  3148 if Pos('Locale/',s) <> 0 then
       
  3149      ret:= lua_load(luaState, @ScriptLocaleReader, f, Str2PChar(s))
       
  3150 else ret:= lua_load(luaState, @ScriptReader, f, Str2PChar(s));
  2861 pfsClose(f);
  3151 pfsClose(f);
  2862 
  3152 
  2863 if ret <> 0 then
  3153 if ret <> 0 then
  2864     begin
  3154     begin
  2865     LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
  3155     LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
  2870     WriteLnToConsole('Lua: ' + name + ' loaded');
  3160     WriteLnToConsole('Lua: ' + name + ' loaded');
  2871     // call the script file
  3161     // call the script file
  2872     lua_pcall(luaState, 0, 0, 0);
  3162     lua_pcall(luaState, 0, 0, 0);
  2873     ScriptLoaded:= true
  3163     ScriptLoaded:= true
  2874     end;
  3164     end;
  2875 hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp'));
       
  2876 end;
  3165 end;
  2877 
  3166 
  2878 procedure SetGlobals;
  3167 procedure SetGlobals;
  2879 begin
  3168 begin
  2880 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
  3169 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
       
  3170 ScriptSetInteger('ReadyTimeLeft', ReadyTimeLeft);
  2881 ScriptSetInteger('GameTime', GameTicks);
  3171 ScriptSetInteger('GameTime', GameTicks);
  2882 ScriptSetInteger('TotalRounds', TotalRounds);
  3172 ScriptSetInteger('TotalRounds', TotalRounds);
  2883 ScriptSetInteger('WaterLine', cWaterLine);
  3173 ScriptSetInteger('WaterLine', cWaterLine);
  2884 if isCursorVisible and (not bShowAmmoMenu) then
  3174 if isCursorVisible and (not bShowAmmoMenu) then
  2885     begin
  3175     begin
  2922 // Otherwise globals might be changed by Lua, but then unexpectatly overwritten by engine when a ScriptCall is triggered by whatever Lua is doing!
  3212 // Otherwise globals might be changed by Lua, but then unexpectatly overwritten by engine when a ScriptCall is triggered by whatever Lua is doing!
  2923 // Sure, one could work around that in engine (e.g. by setting writable globals in SetGlobals only when their engine-side value has actually changed since SetGlobals was called the last time...), but things just get messier and messier then.
  3213 // Sure, one could work around that in engine (e.g. by setting writable globals in SetGlobals only when their engine-side value has actually changed since SetGlobals was called the last time...), but things just get messier and messier then.
  2924 // It is inconsistent anyway to have some globals be read-only and others not with no indication whatsoever.
  3214 // It is inconsistent anyway to have some globals be read-only and others not with no indication whatsoever.
  2925 // -- sheepluva
  3215 // -- sheepluva
  2926 TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft');
  3216 TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft');
       
  3217 ReadyTimeLeft:= ScriptGetInteger('ReadyTimeLeft');
  2927 end;
  3218 end;
  2928 
  3219 
  2929 procedure ScriptCall(fname : shortstring);
  3220 procedure ScriptCall(fname : shortstring);
  2930 begin
  3221 begin
  2931 if (not ScriptLoaded) or (not ScriptExists(fname)) then
  3222 if (not ScriptLoaded) or (not ScriptExists(fname)) then
  2981 begin
  3272 begin
  2982 if (not ScriptLoaded) or (not ScriptExists(fname)) then
  3273 if (not ScriptLoaded) or (not ScriptExists(fname)) then
  2983     exit(0);
  3274     exit(0);
  2984 SetGlobals;
  3275 SetGlobals;
  2985 lua_getglobal(luaState, Str2PChar(fname));
  3276 lua_getglobal(luaState, Str2PChar(fname));
  2986 lua_pushinteger(luaState, par1);
  3277 lua_pushnumber(luaState, par1);
  2987 lua_pushinteger(luaState, par2);
  3278 lua_pushnumber(luaState, par2);
  2988 lua_pushinteger(luaState, par3);
  3279 lua_pushnumber(luaState, par3);
  2989 lua_pushinteger(luaState, par4);
  3280 lua_pushnumber(luaState, par4);
  2990 ScriptCall:= 0;
  3281 ScriptCall:= 0;
  2991 if lua_pcall(luaState, 4, 1, 0) <> 0 then
  3282 if lua_pcall(luaState, 4, 1, 0) <> 0 then
  2992     begin
  3283     begin
  2993     LuaError('Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
  3284     LuaError('Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
  2994     lua_pop(luaState, 1)
  3285     lua_pop(luaState, 1)
  2995     end
  3286     end
  2996 else
  3287 else
  2997     begin
  3288     begin
  2998     ScriptCall:= lua_tointeger(luaState, -1);
  3289     ScriptCall:= Trunc(lua_tonumber(luaState, -1));
  2999     lua_pop(luaState, 1)
  3290     lua_pop(luaState, 1)
  3000     end;
  3291     end;
  3001 GetGlobals;
  3292 GetGlobals;
  3002 end;
  3293 end;
  3003 
  3294 
  3008     ScriptExists:= false;
  3299     ScriptExists:= false;
  3009     exit
  3300     exit
  3010     end;
  3301     end;
  3011 lua_getglobal(luaState, Str2PChar(fname));
  3302 lua_getglobal(luaState, Str2PChar(fname));
  3012 ScriptExists:= not lua_isnoneornil(luaState, -1);
  3303 ScriptExists:= not lua_isnoneornil(luaState, -1);
  3013 lua_pop(luaState, -1)
  3304 lua_pop(luaState, 1)
  3014 end;
  3305 end;
  3015 
  3306 
  3016 procedure ScriptPrepareAmmoStore;
  3307 procedure ScriptPrepareAmmoStore;
  3017 var i: ShortInt;
  3308 var i: ShortInt;
  3018 begin
  3309 begin
  3115     st : TSound;
  3406     st : TSound;
  3116     he : THogEffect;
  3407     he : THogEffect;
  3117     cg : TCapGroup;
  3408     cg : TCapGroup;
  3118     spr: TSprite;
  3409     spr: TSprite;
  3119     mg : TMapGen;
  3410     mg : TMapGen;
       
  3411     we : TWorldEdge;
  3120 begin
  3412 begin
  3121 // initialize lua
  3413 // initialize lua
  3122 luaState:= lua_open;
  3414 luaState:= lua_open;
  3123 if checkFails(luaState <> nil, 'lua_open failed', true) then exit;
  3415 if checkFails(luaState <> nil, 'lua_open failed', true) then exit;
  3124 
  3416 
  3210     ScriptSetInteger(EnumToStr(spr), ord(spr));
  3502     ScriptSetInteger(EnumToStr(spr), ord(spr));
  3211 
  3503 
  3212 for mg:= Low(TMapGen) to High(TMapGen) do
  3504 for mg:= Low(TMapGen) to High(TMapGen) do
  3213     ScriptSetInteger(EnumToStr(mg), ord(mg));
  3505     ScriptSetInteger(EnumToStr(mg), ord(mg));
  3214 
  3506 
       
  3507 for we:= Low(TWorldEdge) to High(TWorldEdge) do
       
  3508     ScriptSetInteger(EnumToStr(we), ord(we));
       
  3509 
  3215 ScriptSetInteger('gstDrowning'      , gstDrowning);
  3510 ScriptSetInteger('gstDrowning'      , gstDrowning);
  3216 ScriptSetInteger('gstHHDriven'      , gstHHDriven);
  3511 ScriptSetInteger('gstHHDriven'      , gstHHDriven);
  3217 ScriptSetInteger('gstMoving'        , gstMoving);
  3512 ScriptSetInteger('gstMoving'        , gstMoving);
  3218 ScriptSetInteger('gstAttacked'      , gstAttacked);
  3513 ScriptSetInteger('gstAttacked'      , gstAttacked);
  3219 ScriptSetInteger('gstAttacking'     , gstAttacking);
  3514 ScriptSetInteger('gstAttacking'     , gstAttacking);
  3263 lua_register(luaState, _P'ClearGameFlags', @lc_cleargameflags);
  3558 lua_register(luaState, _P'ClearGameFlags', @lc_cleargameflags);
  3264 lua_register(luaState, _P'GetGameFlag', @lc_getgameflag);
  3559 lua_register(luaState, _P'GetGameFlag', @lc_getgameflag);
  3265 lua_register(luaState, _P'DeleteGear', @lc_deletegear);
  3560 lua_register(luaState, _P'DeleteGear', @lc_deletegear);
  3266 lua_register(luaState, _P'AddVisualGear', @lc_addvisualgear);
  3561 lua_register(luaState, _P'AddVisualGear', @lc_addvisualgear);
  3267 lua_register(luaState, _P'DeleteVisualGear', @lc_deletevisualgear);
  3562 lua_register(luaState, _P'DeleteVisualGear', @lc_deletevisualgear);
       
  3563 lua_register(luaState, _P'GetVisualGearType', @lc_getvisualgeartype);
  3268 lua_register(luaState, _P'GetVisualGearValues', @lc_getvisualgearvalues);
  3564 lua_register(luaState, _P'GetVisualGearValues', @lc_getvisualgearvalues);
  3269 lua_register(luaState, _P'SetVisualGearValues', @lc_setvisualgearvalues);
  3565 lua_register(luaState, _P'SetVisualGearValues', @lc_setvisualgearvalues);
  3270 lua_register(luaState, _P'GetGearValues', @lc_getgearvalues);
  3566 lua_register(luaState, _P'GetGearValues', @lc_getgearvalues);
  3271 lua_register(luaState, _P'SetGearValues', @lc_setgearvalues);
  3567 lua_register(luaState, _P'SetGearValues', @lc_setgearvalues);
  3272 lua_register(luaState, _P'SpawnHealthCrate', @lc_spawnhealthcrate);
  3568 lua_register(luaState, _P'SpawnHealthCrate', @lc_spawnhealthcrate);
  3276 lua_register(luaState, _P'SpawnFakeAmmoCrate', @lc_spawnfakeammocrate);
  3572 lua_register(luaState, _P'SpawnFakeAmmoCrate', @lc_spawnfakeammocrate);
  3277 lua_register(luaState, _P'SpawnFakeUtilityCrate', @lc_spawnfakeutilitycrate);
  3573 lua_register(luaState, _P'SpawnFakeUtilityCrate', @lc_spawnfakeutilitycrate);
  3278 lua_register(luaState, _P'WriteLnToConsole', @lc_writelntoconsole);
  3574 lua_register(luaState, _P'WriteLnToConsole', @lc_writelntoconsole);
  3279 lua_register(luaState, _P'GetGearType', @lc_getgeartype);
  3575 lua_register(luaState, _P'GetGearType', @lc_getgeartype);
  3280 lua_register(luaState, _P'EndGame', @lc_endgame);
  3576 lua_register(luaState, _P'EndGame', @lc_endgame);
       
  3577 lua_register(luaState, _P'EndTurn', @lc_endturn);
       
  3578 lua_register(luaState, _P'GetTeamStats', @lc_getteamstats);
  3281 lua_register(luaState, _P'SendStat', @lc_sendstat);
  3579 lua_register(luaState, _P'SendStat', @lc_sendstat);
       
  3580 lua_register(luaState, _P'SendGameResultOff', @lc_sendgameresultoff);
       
  3581 lua_register(luaState, _P'SendRankingStatsOff', @lc_sendrankingstatsoff);
       
  3582 lua_register(luaState, _P'SendAchievementsStatsOff', @lc_sendachievementsstatsoff);
  3282 lua_register(luaState, _P'SendHealthStatsOff', @lc_sendhealthstatsoff);
  3583 lua_register(luaState, _P'SendHealthStatsOff', @lc_sendhealthstatsoff);
  3283 lua_register(luaState, _P'FindPlace', @lc_findplace);
  3584 lua_register(luaState, _P'FindPlace', @lc_findplace);
  3284 lua_register(luaState, _P'SetGearPosition', @lc_setgearposition);
  3585 lua_register(luaState, _P'SetGearPosition', @lc_setgearposition);
  3285 lua_register(luaState, _P'GetGearPosition', @lc_getgearposition);
  3586 lua_register(luaState, _P'GetGearPosition', @lc_getgearposition);
  3286 lua_register(luaState, _P'SetGearTarget', @lc_setgeartarget);
  3587 lua_register(luaState, _P'SetGearTarget', @lc_setgeartarget);
  3288 lua_register(luaState, _P'SetGearVelocity', @lc_setgearvelocity);
  3589 lua_register(luaState, _P'SetGearVelocity', @lc_setgearvelocity);
  3289 lua_register(luaState, _P'GetGearVelocity', @lc_getgearvelocity);
  3590 lua_register(luaState, _P'GetGearVelocity', @lc_getgearvelocity);
  3290 lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
  3591 lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
  3291 lua_register(luaState, _P'ShowMission', @lc_showmission);
  3592 lua_register(luaState, _P'ShowMission', @lc_showmission);
  3292 lua_register(luaState, _P'HideMission', @lc_hidemission);
  3593 lua_register(luaState, _P'HideMission', @lc_hidemission);
       
  3594 lua_register(luaState, _P'SetAmmoTexts', @lc_setammotexts);
       
  3595 lua_register(luaState, _P'SetAmmoDescriptionAppendix', @lc_setammodescriptionappendix);
  3293 lua_register(luaState, _P'AddCaption', @lc_addcaption);
  3596 lua_register(luaState, _P'AddCaption', @lc_addcaption);
  3294 lua_register(luaState, _P'SetAmmo', @lc_setammo);
  3597 lua_register(luaState, _P'SetAmmo', @lc_setammo);
  3295 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
  3598 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
  3296 lua_register(luaState, _P'SetAmmoStore', @lc_setammostore);
       
  3297 lua_register(luaState, _P'PlaySound', @lc_playsound);
  3599 lua_register(luaState, _P'PlaySound', @lc_playsound);
  3298 lua_register(luaState, _P'AddTeam', @lc_addteam);
  3600 lua_register(luaState, _P'AddTeam', @lc_addteam);
  3299 lua_register(luaState, _P'AddHog', @lc_addhog);
  3601 lua_register(luaState, _P'AddHog', @lc_addhog);
  3300 lua_register(luaState, _P'AddAmmo', @lc_addammo);
  3602 lua_register(luaState, _P'AddAmmo', @lc_addammo);
  3301 lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
  3603 lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
  3306 lua_register(luaState, _P'GetHogClan', @lc_gethogclan);
  3608 lua_register(luaState, _P'GetHogClan', @lc_gethogclan);
  3307 lua_register(luaState, _P'GetClanColor', @lc_getclancolor);
  3609 lua_register(luaState, _P'GetClanColor', @lc_getclancolor);
  3308 lua_register(luaState, _P'SetClanColor', @lc_setclancolor);
  3610 lua_register(luaState, _P'SetClanColor', @lc_setclancolor);
  3309 lua_register(luaState, _P'GetHogVoicepack', @lc_gethogvoicepack);
  3611 lua_register(luaState, _P'GetHogVoicepack', @lc_gethogvoicepack);
  3310 lua_register(luaState, _P'GetHogFlag', @lc_gethogflag);
  3612 lua_register(luaState, _P'GetHogFlag', @lc_gethogflag);
       
  3613 lua_register(luaState, _P'GetHogFort', @lc_gethogfort);
  3311 lua_register(luaState, _P'GetHogGrave', @lc_gethoggrave);
  3614 lua_register(luaState, _P'GetHogGrave', @lc_gethoggrave);
       
  3615 lua_register(luaState, _P'IsHogLocal', @lc_ishoglocal);
  3312 lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);
  3616 lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);
  3313 lua_register(luaState, _P'SetHogTeamName', @lc_sethogteamname);
  3617 lua_register(luaState, _P'SetHogTeamName', @lc_sethogteamname);
  3314 lua_register(luaState, _P'GetHogName', @lc_gethogname);
  3618 lua_register(luaState, _P'GetHogName', @lc_gethogname);
  3315 lua_register(luaState, _P'SetHogName', @lc_sethogname);
  3619 lua_register(luaState, _P'SetHogName', @lc_sethogname);
  3316 lua_register(luaState, _P'GetHogLevel', @lc_gethoglevel);
  3620 lua_register(luaState, _P'GetHogLevel', @lc_gethoglevel);
  3352 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
  3656 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
  3353 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
  3657 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
  3354 lua_register(luaState, _P'EraseSprite', @lc_erasesprite);
  3658 lua_register(luaState, _P'EraseSprite', @lc_erasesprite);
  3355 lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
  3659 lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
  3356 lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
  3660 lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
       
  3661 lua_register(luaState, _P'PlaceRubber', @lc_placerubber);
  3357 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
  3662 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
  3358 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
  3663 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
  3359 lua_register(luaState, _P'GetGravity', @lc_getgravity);
  3664 lua_register(luaState, _P'GetGravity', @lc_getgravity);
  3360 lua_register(luaState, _P'SetGravity', @lc_setgravity);
  3665 lua_register(luaState, _P'SetGravity', @lc_setgravity);
  3361 lua_register(luaState, _P'SetWaterLine', @lc_setwaterline);
  3666 lua_register(luaState, _P'SetWaterLine', @lc_setwaterline);
  3362 lua_register(luaState, _P'SetNextWeapon', @lc_setnextweapon);
  3667 lua_register(luaState, _P'SetNextWeapon', @lc_setnextweapon);
  3363 lua_register(luaState, _P'SetWeapon', @lc_setweapon);
  3668 lua_register(luaState, _P'SetWeapon', @lc_setweapon);
  3364 lua_register(luaState, _P'SetCinematicMode', @lc_setcinematicmode);
  3669 lua_register(luaState, _P'SetCinematicMode', @lc_setcinematicmode);
  3365 lua_register(luaState, _P'SetMaxBuildDistance', @lc_setmaxbuilddistance);
  3670 lua_register(luaState, _P'SetMaxBuildDistance', @lc_setmaxbuilddistance);
       
  3671 lua_register(luaState, _P'GetAmmoName', @lc_getammoname);
  3366 // drawn map functions
  3672 // drawn map functions
  3367 lua_register(luaState, _P'AddPoint', @lc_addPoint);
  3673 lua_register(luaState, _P'AddPoint', @lc_addPoint);
  3368 lua_register(luaState, _P'FlushPoints', @lc_flushPoints);
  3674 lua_register(luaState, _P'FlushPoints', @lc_flushPoints);
  3369 
  3675 
  3370 lua_register(luaState, _P'SetGearAIHints', @lc_setgearaihints);
  3676 lua_register(luaState, _P'SetGearAIHints', @lc_setgearaihints);