# HG changeset patch # User Wuzzy # Date 1518112971 -3600 # Node ID 330b6c3530933ba63add61c83d96bbf175e63929 # Parent 1d7d7d21914ae1e11e21fa980035937b93189bff Lua API: Add GetWind function to get current wind diff -r 1d7d7d21914a -r 330b6c353093 ChangeLog.txt --- a/ChangeLog.txt Thu Feb 08 18:42:07 2018 +0100 +++ b/ChangeLog.txt Thu Feb 08 19:02:51 2018 +0100 @@ -31,6 +31,7 @@ + New call: WriteLnToChat(string): Add a line in the chat + New call: SetVampiric(bool): Toggle vampirism + New call: SetLaserSight(bool): Toggle laser sight + + New call: GetWind(): Returns current wind (approximation) from -100 to 100 + New callback: onEndTurn(): Called at the end of a turn (when gears have settled) * Fix call: SetWeapon(amNothing) now unselects weapon * Fix global: TotalRounds was stuck at -1 for several turns diff -r 1d7d7d21914a -r 330b6c353093 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Thu Feb 08 18:42:07 2018 +0100 +++ b/hedgewars/uScript.pas Thu Feb 08 19:02:51 2018 +0100 @@ -2387,6 +2387,23 @@ lc_setwind:= 0 end; +function lc_getwind(L : Plua_State) : LongInt; Cdecl; +var wind: extended; +begin + if CheckLuaParamCount(L, 0, 'GetWind', '') then + begin + wind:= hwFloat2float((cWindSpeed / cMaxWindSpeed) * 100); + if wind < -100 then + wind:= -100 + else if wind > 100 then + wind:= 100; + lua_pushnumber(L, wind); + end + else + lua_pushnil(L); + lc_getwind:= 1 +end; + function lc_maphasborder(L : Plua_State) : LongInt; Cdecl; begin if CheckLuaParamCount(L, 0, 'MapHasBorder', '') then @@ -3674,6 +3691,7 @@ lua_register(luaState, _P'SetGearCollisionMask', @lc_setgearcollisionmask); lua_register(luaState, _P'GetRandom', @lc_getrandom); lua_register(luaState, _P'SetWind', @lc_setwind); +lua_register(luaState, _P'GetWind', @lc_getwind); lua_register(luaState, _P'MapHasBorder', @lc_maphasborder); lua_register(luaState, _P'GetHogHat', @lc_gethoghat); lua_register(luaState, _P'SetHogHat', @lc_sethoghat);