# HG changeset patch # User sheepluva # Date 1390264045 -3600 # Node ID f40fdc566e94b961b55c5f1f95a9cd6d0ef1c7d2 # Parent 3b3d3e465e6a8c16b34594c65b078841260b3d73 * fix divbyzero found by GetGravity test (cWindSpeed was used where cMaxWindSpeed should have been) * make GetGravity return same integer value that was given by SetGravity (by rounding away precision errors rather than just truncate) - a problem also identified by the test :P diff -r 3b3d3e465e6a -r f40fdc566e94 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Tue Jan 21 01:23:57 2014 +0100 +++ b/hedgewars/uScript.pas Tue Jan 21 01:27:25 2014 +0100 @@ -1907,18 +1907,20 @@ begin if lua_gettop(L) <> 0 then LuaParameterCountError('GetGravity', '', lua_gettop(L)) + else if cGravity.isNegative then + lua_pushinteger(L, hwRound(-_0_5 + (cGravity * 50 / cMaxWindSpeed))) else - lua_pushinteger(L, hwRound(cGravity * 50 / cWindSpeed)); + lua_pushinteger(L, hwRound( _0_5 + (cGravity * 50 / cMaxWindSpeed))); lc_getgravity:= 1 end; function lc_setgravity(L : Plua_State) : LongInt; Cdecl; begin if lua_gettop(L) <> 1 then - LuaParameterCountError('SetGravity', 'gravity', lua_gettop(L)) + LuaParameterCountError('SetGravity', 'percent', lua_gettop(L)) else begin - cGravity:= cMaxWindSpeed * lua_tointeger(L, 1) * _0_02; + cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed; cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02 end; lc_setgravity:= 0