hedgewars/uScript.pas
changeset 6780 166ee5275915
parent 6779 ccd8aecaff6d
child 6789 bed473d0aa7d
equal deleted inserted replaced
6779:ccd8aecaff6d 6780:166ee5275915
  1383     lc_setgeartarget:= 0
  1383     lc_setgeartarget:= 0
  1384 end;
  1384 end;
  1385 
  1385 
  1386 function lc_getgearvelocity(L : Plua_State) : LongInt; Cdecl;
  1386 function lc_getgearvelocity(L : Plua_State) : LongInt; Cdecl;
  1387 var gear: PGear;
  1387 var gear: PGear;
       
  1388 var t: LongInt;
  1388 begin
  1389 begin
  1389     if lua_gettop(L) <> 1 then
  1390     if lua_gettop(L) <> 1 then
  1390         begin
  1391         begin
  1391         LuaError('Lua: Wrong number of parameters passed to GetGearVelocity!');
  1392         LuaError('Lua: Wrong number of parameters passed to GetGearVelocity!');
  1392         lua_pushnil(L);
  1393         lua_pushnil(L);
  1395     else
  1396     else
  1396         begin
  1397         begin
  1397         gear:= GearByUID(lua_tointeger(L, 1));
  1398         gear:= GearByUID(lua_tointeger(L, 1));
  1398         if gear <> nil then
  1399         if gear <> nil then
  1399             begin
  1400             begin
       
  1401             t:= hwRound(gear^.dX * 1000000);
  1400             // gear dX determines hog orientation
  1402             // gear dX determines hog orientation
  1401             if (gear^.dX.isNegative) and (gear^.dX = _0) then lua_pushinteger(L, -1)
  1403             if (gear^.dX.isNegative) and (t = 0) then t:= -1;
  1402             else lua_pushinteger(L, hwRound(gear^.dX * 1000000));
  1404             lua_pushinteger(L, t);
  1403             lua_pushinteger(L, hwRound(gear^.dY * 1000000))
  1405             lua_pushinteger(L, hwRound(gear^.dY * 1000000))
  1404             end
  1406             end
  1405         end;
  1407         end;
  1406     lc_getgearvelocity:= 2;
  1408     lc_getgearvelocity:= 2;
  1407 end;
  1409 end;