Lua API: Add GetWind function to get current wind
authorWuzzy <Wuzzy2@mail.ru>
Thu, 08 Feb 2018 19:02:51 +0100
changeset 12930 330b6c353093
parent 12929 1d7d7d21914a
child 12931 c27dd59a3ffe
Lua API: Add GetWind function to get current wind
ChangeLog.txt
hedgewars/uScript.pas
--- 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
--- 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);