Add PlaceRubber to Lua API
authorWuzzy <almikes@aol.com>
Sun, 27 Nov 2016 05:33:26 +0100
changeset 12095 fac17dd2bc2f
parent 12094 0183b4c448bf
child 12096 db5e12d623cc
Add PlaceRubber to Lua API
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Sun Nov 27 03:18:20 2016 +0100
+++ b/ChangeLog.txt	Sun Nov 27 05:33:26 2016 +0100
@@ -192,6 +192,7 @@
  + New call: SetAmmoTexts(ammoType, name, caption, description) -- Overwrite displayed name and description of an ammo type
  + New call: SetAmmoDescriptionAppendix(ammoType, descAppend) -- Append a custom text to the description of an ammo type without overwriting it
  + New call: GetHogFort(gearUid) -- Returns the name of the fort of the hog's team
+ + New call: PlaceRubber(x, y, frameIdx) -- Places a rubber
  + New hook: onVisualGearAdd(vgUid) -- called when a visual gear is added
  + New hook: onVisualGearDelete(vgUid) -- called when a visual gear is deleted
  + New variable: AirMinesNum -- Number of air mines being placed on a medium-sized map
--- a/hedgewars/uScript.pas	Sun Nov 27 03:18:20 2016 +0100
+++ b/hedgewars/uScript.pas	Sun Nov 27 05:33:26 2016 +0100
@@ -2475,6 +2475,20 @@
     lc_placegirder:= 1
 end;
 
+function lc_placerubber(L : Plua_State) : LongInt; Cdecl;
+var placed: boolean;
+begin
+    placed:= false;
+    if CheckLuaParamCount(L, 3, 'PlaceRubber', 'x, y, frameIdx') then
+        placed:= TryPlaceOnLand(
+            lua_tointeger(L, 1) - SpritesData[sprAmRubber].Width div 2,
+            lua_tointeger(L, 2) - SpritesData[sprAmRubber].Height div 2,
+            sprAmRubber, lua_tointeger(L, 3), true, lfBouncy);
+
+    lua_pushboolean(L, placed);
+    lc_placerubber:= 1
+end;
+
 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
 begin
     if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, 'GetCurAmmoType', '')) then
@@ -3470,6 +3484,7 @@
 lua_register(luaState, _P'EraseSprite', @lc_erasesprite);
 lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
 lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
+lua_register(luaState, _P'PlaceRubber', @lc_placerubber);
 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
 lua_register(luaState, _P'GetGravity', @lc_getgravity);