hedgewars/uScript.pas
branchios-develop
changeset 13418 ba39a1d396c0
parent 13399 7b4726ef2308
child 13439 745e9174038e
equal deleted inserted replaced
13416:6e8b807bda4b 13418:ba39a1d396c0
    98     ScriptAmmoDelay : shortstring;
    98     ScriptAmmoDelay : shortstring;
    99     ScriptAmmoReinforcement : shortstring;
    99     ScriptAmmoReinforcement : shortstring;
   100     ScriptLoaded : boolean;
   100     ScriptLoaded : boolean;
   101     mapDims : boolean;
   101     mapDims : boolean;
   102     PointsBuffer: shortstring;
   102     PointsBuffer: shortstring;
   103     prevCursorPoint: TPoint;  // why is tpoint still in sdlh...
   103     PrevCursorX, PrevCursorY: LongInt;
   104 
   104 
   105 {$IFDEF USE_LUA_SCRIPT}
   105 {$IFDEF USE_LUA_SCRIPT}
   106 procedure ScriptPrepareAmmoStore; forward;
   106 procedure ScriptPrepareAmmoStore; forward;
   107 procedure ScriptApplyAmmoStore; forward;
   107 procedure ScriptApplyAmmoStore; forward;
   108 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward;
   108 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward;
   400 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
   400 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
   401 begin
   401 begin
   402     if CheckLuaParamCount(L, 1, 'WriteLnToConsole', 'string') then
   402     if CheckLuaParamCount(L, 1, 'WriteLnToConsole', 'string') then
   403         WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
   403         WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
   404     lc_writelntoconsole:= 0;
   404     lc_writelntoconsole:= 0;
       
   405 end;
       
   406 
       
   407 function lc_writelntochat(L : Plua_State) : LongInt; Cdecl;
       
   408 begin
       
   409     if CheckLuaParamCount(L, 1, 'WriteLnToChat', 'string') then
       
   410         AddChatString(#2 + lua_tostring(L, 1));
       
   411     lc_writelntochat:= 0;
   405 end;
   412 end;
   406 
   413 
   407 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
   414 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
   408 var t: PChar;
   415 var t: PChar;
   409     i,c: LongWord;
   416     i,c: LongWord;
   551 end;
   558 end;
   552 
   559 
   553 function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
   560 function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
   554 const
   561 const
   555     call = 'SetAmmoTexts';
   562     call = 'SetAmmoTexts';
   556     params = 'ammoType, name, caption, description';
   563     params = 'ammoType, name, caption, description [, showExtra]';
   557 begin
   564 var n: integer;
   558     if CheckLuaParamCount(L, 4, call, params) then
   565     showExtra: boolean;
   559         SetAmmoTexts(TAmmoType(LuaToAmmoTypeOrd(L, 1, call, params)), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tostringA(L, 4));
   566 begin
       
   567     if CheckAndFetchParamCount(L, 4, 5, call, params, n) then
       
   568         begin
       
   569         if n = 5 then
       
   570             showExtra:= lua_toboolean(L, 5)
       
   571         else
       
   572             showExtra:= true;
       
   573         SetAmmoTexts(TAmmoType(LuaToAmmoTypeOrd(L, 1, call, params)), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tostringA(L, 4), showExtra);
       
   574         end;
   560     lc_setammotexts:= 0;
   575     lc_setammotexts:= 0;
   561 end;
   576 end;
   562 
   577 
   563 function lc_setammodescriptionappendix(L : Plua_State) : LongInt; Cdecl;
   578 function lc_setammodescriptionappendix(L : Plua_State) : LongInt; Cdecl;
   564 const
   579 const
   640             end
   655             end
   641         end;
   656         end;
   642     lc_addcaption:= 0;
   657     lc_addcaption:= 0;
   643 end;
   658 end;
   644 
   659 
   645 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl;
       
   646 begin
       
   647     if CheckLuaParamCount(L, 1, 'CampaignLock', 'TODO') then
       
   648         begin
       
   649         // TODO
       
   650         end;
       
   651     lc_campaignlock:= 0;
       
   652 end;
       
   653 
       
   654 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl;
       
   655 begin
       
   656     if CheckLuaParamCount(L, 1, 'CampaignUnlock', 'TODO') then
       
   657         begin
       
   658         // TODO
       
   659         end;
       
   660     lc_campaignunlock:= 0;
       
   661 end;
       
   662 
       
   663 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   660 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   664 var gear: PGear;
   661 var gear: PGear;
   665 begin
   662 begin
   666     if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   663     if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   667         begin
   664         begin
   760         else lua_pushnil(L);
   757         else lua_pushnil(L);
   761        end
   758        end
   762     else
   759     else
   763         lua_pushnil(L);
   760         lua_pushnil(L);
   764     lc_spawnutilitycrate := 1;
   761     lc_spawnutilitycrate := 1;
       
   762 end;
       
   763 
       
   764 function lc_spawnsupplycrate(L: PLua_State): LongInt; Cdecl;
       
   765 var gear: PGear;
       
   766     n, at:LongInt;
       
   767     t:    TCrateType;
       
   768 begin
       
   769     if CheckAndFetchParamCount(L, 3, 4, 'SpawnSupplyCrate', 'x, y, content [, amount]', n) then
       
   770         begin
       
   771         // Get crate type (ammo or utility)
       
   772         at:= Trunc(lua_tonumber(L, 3));
       
   773         if (Ammoz[TAmmoType(at)].Ammo.Propz and ammoprop_Utility) <> 0 then
       
   774             t:= UtilityCrate
       
   775         else
       
   776             t:= AmmoCrate;
       
   777         if n = 3 then
       
   778              gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), t, at, 0)
       
   779         else gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), t, at, Trunc(lua_tonumber(L, 4)));
       
   780         if gear <> nil then
       
   781              lua_pushnumber(L, gear^.uid)
       
   782         else lua_pushnil(L);
       
   783         end
       
   784     else
       
   785         lua_pushnil(L);
       
   786     lc_spawnsupplycrate := 1;
   765 end;
   787 end;
   766 
   788 
   767 function lc_addgear(L : Plua_State) : LongInt; Cdecl;
   789 function lc_addgear(L : Plua_State) : LongInt; Cdecl;
   768 var gear : PGear;
   790 var gear : PGear;
   769     x, y, s, t: LongInt;
   791     x, y, s, t: LongInt;
  1653             end
  1675             end
  1654         end;
  1676         end;
  1655     lc_switchhog:= 0
  1677     lc_switchhog:= 0
  1656 end;
  1678 end;
  1657 
  1679 
       
  1680 function lc_enableswitchhog(L : Plua_State) : LongInt; Cdecl;
       
  1681 var gear, iterator: PGear;
       
  1682     alreadySwitching: boolean;
       
  1683 begin
       
  1684     if CheckLuaParamCount(L, 0, 'EnableSwitchHog', '') then
       
  1685         if ((CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil)) then
       
  1686             begin
       
  1687             alreadySwitching:= false;
       
  1688             iterator:= GearsList;
       
  1689             // Check if there's already a switcher gear
       
  1690             while (iterator <> nil) do
       
  1691                 begin
       
  1692                 if (iterator^.Kind = gtSwitcher) then
       
  1693                     begin
       
  1694                     alreadySwitching:= true;
       
  1695                     lua_pushnumber(L, iterator^.Uid);
       
  1696                     break;
       
  1697                     end;
       
  1698                 iterator:= iterator^.NextGear;
       
  1699                 end;
       
  1700             if (not alreadySwitching) then
       
  1701                 begin
       
  1702                 // Enable switching and return gear UID
       
  1703                 gear:= AddGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), gtSwitcher, 0, _0, _0, 0);
       
  1704                 CurAmmoGear:= gear;
       
  1705                 lastGearByUID:= gear;
       
  1706                 bShowFinger:= false;
       
  1707                 lua_pushnumber(L, gear^.Uid);
       
  1708                 end;
       
  1709             end
       
  1710     // Return nil on failure
       
  1711         else
       
  1712             lua_pushnil(L)
       
  1713     else
       
  1714         lua_pushnil(L);
       
  1715     lc_enableswitchhog:= 1;
       
  1716 end;
       
  1717 
  1658 function lc_addammo(L : Plua_State) : LongInt; Cdecl;
  1718 function lc_addammo(L : Plua_State) : LongInt; Cdecl;
  1659 var gear : PGear;
  1719 var gear : PGear;
  1660     at, n: LongInt;
  1720     at, n, c: LongInt;
  1661 const
  1721 const
  1662     call = 'AddAmmo';
  1722     call = 'AddAmmo';
  1663     params = 'gearUid, ammoType [, ammoCount]';
  1723     params = 'gearUid, ammoType [, ammoCount]';
  1664 begin
  1724 begin
  1665     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1725     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1666         begin
  1726         begin
  1667         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1727         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1668         if at >= 0 then
  1728         if (at >= 0) and (TAmmoType(at) <> amNothing) then
  1669             begin
  1729             begin
  1670             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1730             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1671             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1731             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1672                 if n = 2 then
  1732                 if n = 2 then
  1673                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
  1733                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
  1674                 else
  1734                 else
  1675                     SetAmmo(gear^.Hedgehog^, TAmmoType(at), Trunc(lua_tonumber(L, 3)))
  1735                     begin
       
  1736                     c:= Trunc(lua_tonumber(L, 3));
       
  1737                     if (c = 0) and (CurrentHedgehog = gear^.Hedgehog) and (gear^.Hedgehog^.CurAmmoType = TAmmoType(at)) then
       
  1738                         ParseCommand('setweap ' + char(0), true, true);
       
  1739                     SetAmmo(gear^.Hedgehog^, TAmmoType(at), c);
       
  1740                     end;
  1676             end;
  1741             end;
  1677         end;
  1742         end;
  1678     lc_addammo:= 0
  1743     lc_addammo:= 0
  1679 end;
  1744 end;
  1680 
  1745 
  1730             end
  1795             end
  1731         end;
  1796         end;
  1732     lc_sethealth:= 0
  1797     lc_sethealth:= 0
  1733 end;
  1798 end;
  1734 
  1799 
       
  1800 function lc_healhog(L : Plua_State) : LongInt; Cdecl;
       
  1801 var gear : PGear;
       
  1802     healthBoost, n: LongInt;
       
  1803 begin
       
  1804     if CheckAndFetchParamCountRange(L, 2, 4, 'HealHog', 'gearUid, healthBoost [, showMessage [, tint]]', n) then
       
  1805         begin
       
  1806         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
       
  1807         healthBoost:= Trunc(lua_tonumber(L, 2));
       
  1808         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (healthBoost >= 1) then
       
  1809             begin
       
  1810             gear^.Health:= gear^.Health + healthBoost;
       
  1811 
       
  1812             RenderHealth(gear^.Hedgehog^);
       
  1813             RecountTeamHealth(gear^.Hedgehog^.Team);
       
  1814             if n = 4 then
       
  1815                 HHHeal(gear^.Hedgehog, healthBoost, lua_toboolean(L, 3), Trunc(lua_tonumber(L, 4)))
       
  1816             else if n = 3 then
       
  1817                 HHHeal(gear^.Hedgehog, healthBoost, lua_toboolean(L, 3))
       
  1818             else if n = 2 then
       
  1819                 HHHeal(gear^.Hedgehog, healthBoost, true);
       
  1820             Gear^.Active:= true;
       
  1821             AllInactive:= false
       
  1822             end
       
  1823         end;
       
  1824     lc_healhog:= 0
       
  1825 end;
       
  1826 
  1735 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
  1827 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
  1736 var gear : PGear;
  1828 var gear : PGear;
  1737 begin
  1829 begin
  1738     if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then
  1830     if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then
  1739         begin
  1831         begin
  1876     if CheckAndFetchParamCount(L, 0, 1, call, params, n) then
  1968     if CheckAndFetchParamCount(L, 0, 1, call, params, n) then
  1877         if n >= 1 then
  1969         if n >= 1 then
  1878             LuaNoEndTurnTaunts:= lua_toboolean(L, 1);
  1970             LuaNoEndTurnTaunts:= lua_toboolean(L, 1);
  1879     LuaEndTurnRequested:= true;
  1971     LuaEndTurnRequested:= true;
  1880     lc_endturn:= 0
  1972     lc_endturn:= 0
       
  1973 end;
       
  1974 
       
  1975 function lc_retreat(L : Plua_State) : LongInt; Cdecl;
       
  1976 var n, time: LongInt;
       
  1977     respectFactor: Boolean;
       
  1978 const
       
  1979     call = 'Retreat';
       
  1980     params = 'time [, respectGetAwayTimeFactor]';
       
  1981 begin
       
  1982     if CheckAndFetchParamCount(L, 1, 2, call, params, n) then
       
  1983         begin
       
  1984         IsGetAwayTime:= true;
       
  1985         AttackBar:= 0;
       
  1986         time:= Trunc(lua_tonumber(L, 1));
       
  1987         if n = 2 then
       
  1988             respectFactor:= lua_toboolean(L, 2)
       
  1989         else
       
  1990             respectFactor:= True;
       
  1991         if respectFactor then
       
  1992             TurnTimeLeft:= (time * cGetAwayTime) div 100
       
  1993         else
       
  1994             TurnTimeLeft:= time;
       
  1995         if ((CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil)) then
       
  1996             begin
       
  1997             CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstAttacked;
       
  1998             CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and (not gstAttacking);
       
  1999             end;
       
  2000         end;
       
  2001     lc_retreat:= 0
       
  2002 end;
       
  2003 
       
  2004 function lc_skipturn(L : Plua_State): LongInt; Cdecl;
       
  2005 begin
       
  2006     L:= L; // avoid compiler hint
       
  2007     ParseCommand('skip', true, true);
       
  2008     lc_skipturn:= 0;
  1881 end;
  2009 end;
  1882 
  2010 
  1883 function lc_sendstat(L : Plua_State) : LongInt; Cdecl;
  2011 function lc_sendstat(L : Plua_State) : LongInt; Cdecl;
  1884 var statInfo : TStatInfoType;
  2012 var statInfo : TStatInfoType;
  1885     i, n     : LongInt;
  2013     i, n     : LongInt;
  2000 end;
  2128 end;
  2001 
  2129 
  2002 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
  2130 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
  2003 var gear: PGear;
  2131 var gear: PGear;
  2004     n, s: LongInt;
  2132     n, s: LongInt;
       
  2133     instaVoice: boolean;
  2005 const
  2134 const
  2006     call = 'PlaySound';
  2135     call = 'PlaySound';
  2007     params = 'soundId [, hhGearUid]';
  2136     params = 'soundId [, hhGearUid [, instaVoice]]';
  2008 begin
  2137 begin
  2009     if CheckAndFetchParamCount(L, 1, 2, call, params, n) then
  2138     if CheckAndFetchParamCountRange(L, 1, 3, call, params, n) then
  2010         begin
  2139         begin
  2011         s:= LuaToSoundOrd(L, 1, call, params);
  2140         s:= LuaToSoundOrd(L, 1, call, params);
  2012         if s >= 0 then
  2141         if s >= 0 then
  2013             begin
  2142             begin
  2014             // no gear specified
  2143             // no gear specified
  2015             if n = 1 then
  2144             if n = 1 then
  2016                 PlaySound(TSound(s))
  2145                 PlaySound(TSound(s), false, true)
  2017             else
  2146             else
  2018                 begin
  2147                 begin
  2019                 gear:= GearByUID(Trunc(lua_tonumber(L, 2)));
  2148                 gear:= GearByUID(Trunc(lua_tonumber(L, 2)));
  2020                 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  2149                 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  2021                     AddVoice(TSound(s),gear^.Hedgehog^.Team^.Voicepack)
  2150                     begin
       
  2151                     instaVoice:= false;
       
  2152                     if n = 3 then
       
  2153                         instaVoice:= lua_toboolean(L, 3);
       
  2154                     if instaVoice then
       
  2155                         PlaySoundV(TSound(s), gear^.Hedgehog^.Team^.Voicepack, false, true)
       
  2156                     else
       
  2157                         AddVoice(TSound(s), gear^.Hedgehog^.Team^.Voicepack, true);
       
  2158                     end;
  2022                 end;
  2159                 end;
  2023             end;
  2160             end;
  2024         end;
  2161         end;
  2025     lc_playsound:= 0;
  2162     lc_playsound:= 0;
       
  2163 end;
       
  2164 
       
  2165 function lc_setsoundmask(L : Plua_State) : LongInt; Cdecl;
       
  2166 var s: LongInt;
       
  2167     soundState: boolean;
       
  2168 const
       
  2169     call = 'SetSoundMasked';
       
  2170     params = 'soundId, isMasked]';
       
  2171 begin
       
  2172     if CheckLuaParamCount(L, 2, call, params) then
       
  2173         begin
       
  2174         s:= LuaToSoundOrd(L, 1, call, params);
       
  2175         if s <> Ord(sndNone) then
       
  2176             begin
       
  2177             soundState:= lua_toboolean(L, 2);
       
  2178             MaskedSounds[TSound(s)]:= soundState;
       
  2179             end;
       
  2180         end;
       
  2181     lc_setsoundmask:= 0;
  2026 end;
  2182 end;
  2027 
  2183 
  2028 function lc_addteam(L : Plua_State) : LongInt; Cdecl;
  2184 function lc_addteam(L : Plua_State) : LongInt; Cdecl;
  2029 var np: LongInt;
  2185 var np: LongInt;
  2030 begin
  2186 begin
  2040         //lua_pushnumber(L, LongInt(CurrentTeam));
  2196         //lua_pushnumber(L, LongInt(CurrentTeam));
  2041         end;
  2197         end;
  2042     //else
  2198     //else
  2043         //lua_pushnil(L)
  2199         //lua_pushnil(L)
  2044     lc_addteam:= 0;//1;
  2200     lc_addteam:= 0;//1;
       
  2201 end;
       
  2202 
       
  2203 function lc_setteamlabel(L : Plua_State) : LongInt; Cdecl;
       
  2204 var teamValue: ansistring;
       
  2205     i, n: LongInt;
       
  2206     success: boolean;
       
  2207 begin
       
  2208     if CheckAndFetchParamCount(L, 1, 2, 'SetTeamLabel', 'teamname[, label]', n) then
       
  2209         begin
       
  2210         success:= false;
       
  2211         // fetch team
       
  2212         if TeamsCount > 0 then
       
  2213             for i:= 0 to Pred(TeamsCount) do
       
  2214                 begin
       
  2215                 // skip teams that don't have matching name
       
  2216                 if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
       
  2217                     continue;
       
  2218 
       
  2219                 // value of type nil? Then let's clear the team value
       
  2220                 if (n < 2) or lua_isnil(L, 2) then
       
  2221                     begin
       
  2222                     FreeAndNilTexture(TeamsArray[i]^.LuaTeamValueTex);
       
  2223                     TeamsArray[i]^.hasLuaTeamValue:= false;
       
  2224                     success:= true;
       
  2225                     end
       
  2226                 // value of type string? Then let's set the team value
       
  2227                 else if (lua_isstring(L, 2)) then
       
  2228                     begin
       
  2229                     teamValue:= lua_tostring(L, 2);
       
  2230                     TeamsArray[i]^.LuaTeamValue:= teamValue;
       
  2231                     FreeAndNilTexture(TeamsArray[i]^.LuaTeamValueTex);
       
  2232                     TeamsArray[i]^.LuaTeamValueTex := RenderStringTex(teamValue, TeamsArray[i]^.Clan^.Color, fnt16);
       
  2233                     TeamsArray[i]^.hasLuaTeamValue:= true;
       
  2234                     success:= true;
       
  2235                     end;
       
  2236                 // don't change more than one team
       
  2237                 break;
       
  2238                 end;
       
  2239         end;
       
  2240     // return true if operation was successful, false otherwise
       
  2241     lua_pushboolean(L, success);
       
  2242     lc_setteamlabel:= 1;
       
  2243 end;
       
  2244 
       
  2245 function lc_getteamname(L : Plua_State) : LongInt; Cdecl;
       
  2246 var t: LongInt;
       
  2247 begin
       
  2248     if CheckLuaParamCount(L, 1, 'GetTeamName', 'teamIdx') then
       
  2249         begin
       
  2250         t:= Trunc(lua_tonumber(L, 1));
       
  2251         if (t < 0) or (t >= TeamsCount) then
       
  2252             lua_pushnil(L)
       
  2253         else
       
  2254             lua_pushstring(L, str2pchar(TeamsArray[t]^.TeamName));
       
  2255         end
       
  2256     else
       
  2257         lua_pushnil(L);
       
  2258     lc_getteamname:= 1;
       
  2259 end;
       
  2260 
       
  2261 function lc_getteamindex(L : Plua_state) : LongInt; Cdecl;
       
  2262 var i: LongInt;
       
  2263     found: boolean;
       
  2264 begin
       
  2265     found:= false;
       
  2266     if CheckLuaParamCount(L, 1, 'GetTeamIndex', 'teamname') then
       
  2267         if TeamsCount > 0 then
       
  2268             for i:= 0 to Pred(TeamsCount) do
       
  2269                 begin
       
  2270                 // skip teams that don't have matching name
       
  2271                 if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
       
  2272                     continue;
       
  2273                 lua_pushnumber(L, i);
       
  2274                 found:= true;
       
  2275                 break;
       
  2276                 end;
       
  2277     if (not found) then
       
  2278         lua_pushnil(L);
       
  2279     lc_getteamindex:= 1;
       
  2280 end;
       
  2281 
       
  2282 function lc_getteamclan(L : Plua_state) : LongInt; Cdecl;
       
  2283 var i: LongInt;
       
  2284     found: boolean;
       
  2285 begin
       
  2286     found:= false;
       
  2287     if CheckLuaParamCount(L, 1, 'GetTeamClan', 'teamname') then
       
  2288         if TeamsCount > 0 then
       
  2289             for i:= 0 to Pred(TeamsCount) do
       
  2290                 begin
       
  2291                 // skip teams that don't have matching name
       
  2292                 if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
       
  2293                     continue;
       
  2294                 lua_pushnumber(L, TeamsArray[i]^.Clan^.ClanIndex);
       
  2295                 found:= true;
       
  2296                 break;
       
  2297                 end;
       
  2298     if (not found) then
       
  2299         lua_pushnil(L);
       
  2300     lc_getteamclan:= 1;
  2045 end;
  2301 end;
  2046 
  2302 
  2047 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl;
  2303 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl;
  2048 var HHGear: PGear;
  2304 var HHGear: PGear;
  2049     i, h  : LongInt;
  2305     i, h  : LongInt;
  2366         lua_pushnil(L); // return value on stack (nil)
  2622         lua_pushnil(L); // return value on stack (nil)
  2367     lc_getrandom:= 1
  2623     lc_getrandom:= 1
  2368 end;
  2624 end;
  2369 
  2625 
  2370 function lc_setwind(L : Plua_State) : LongInt; Cdecl;
  2626 function lc_setwind(L : Plua_State) : LongInt; Cdecl;
       
  2627 var vg: PVisualGear;
  2371 begin
  2628 begin
  2372     if CheckLuaParamCount(L, 1, 'SetWind', 'windSpeed') then
  2629     if CheckLuaParamCount(L, 1, 'SetWind', 'windSpeed') then
  2373         begin
  2630         begin
  2374         cWindSpeed:= int2hwfloat(Trunc(lua_tonumber(L, 1))) / 100 * cMaxWindSpeed;
  2631         cWindSpeed:= int2hwfloat(Trunc(lua_tonumber(L, 1))) / 100 * cMaxWindSpeed;
  2375         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  2632         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  2376         if cWindSpeed.isNegative then
  2633         if cWindSpeed.isNegative then
  2377             CWindSpeedf := -cWindSpeedf;
  2634             cWindSpeedf := -cWindSpeedf;
  2378         AddVisualGear(0, 0, vgtSmoothWindBar);
  2635         vg:= AddVisualGear(0, 0, vgtSmoothWindBar);
       
  2636         if vg <> nil then vg^.dAngle:= hwFloat2Float(cWindSpeed);
       
  2637             AddFileLog('Wind = '+FloatToStr(cWindSpeed));
  2379         end;
  2638         end;
  2380     lc_setwind:= 0
  2639     lc_setwind:= 0
       
  2640 end;
       
  2641 
       
  2642 function lc_getwind(L : Plua_State) : LongInt; Cdecl;
       
  2643 var wind: extended;
       
  2644 begin
       
  2645     if CheckLuaParamCount(L, 0, 'GetWind', '') then
       
  2646         begin
       
  2647         wind:= hwFloat2float((cWindSpeed / cMaxWindSpeed) * 100);
       
  2648         if wind < -100 then
       
  2649             wind:= -100
       
  2650         else if wind > 100 then
       
  2651             wind:= 100;
       
  2652         lua_pushnumber(L, wind);
       
  2653         end
       
  2654     else
       
  2655         lua_pushnil(L);
       
  2656     lc_getwind:= 1
  2381 end;
  2657 end;
  2382 
  2658 
  2383 function lc_maphasborder(L : Plua_State) : LongInt; Cdecl;
  2659 function lc_maphasborder(L : Plua_State) : LongInt; Cdecl;
  2384 begin
  2660 begin
  2385     if CheckLuaParamCount(L, 0, 'MapHasBorder', '') then
  2661     if CheckLuaParamCount(L, 0, 'MapHasBorder', '') then
  2686 end;
  2962 end;
  2687 
  2963 
  2688 function lc_setgearaihints(L : Plua_State) : LongInt; Cdecl;
  2964 function lc_setgearaihints(L : Plua_State) : LongInt; Cdecl;
  2689 var gear: PGear;
  2965 var gear: PGear;
  2690 begin
  2966 begin
  2691     if CheckLuaParamCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then
  2967     if CheckLuaParamCount(L, 2, 'SetGearAIHints', 'gearUid, aiHints') then
  2692         begin
  2968         begin
  2693         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2969         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  2694         if gear <> nil then
  2970         if gear <> nil then
  2695             gear^.aihints:= Trunc(lua_tonumber(L, 2));
  2971             gear^.aihints:= Trunc(lua_tonumber(L, 2));
  2696         end;
  2972         end;
  2734                 lua_pushstring(L, PChar(trammo[Ammoz[TAmmoType(at)].NameId]));
  3010                 lua_pushstring(L, PChar(trammo[Ammoz[TAmmoType(at)].NameId]));
  2735         end
  3011         end
  2736     else
  3012     else
  2737         lua_pushnil(L);
  3013         lua_pushnil(L);
  2738     lc_getammoname:= 1;
  3014     lc_getammoname:= 1;
       
  3015 end;
       
  3016 
       
  3017 function lc_getammotimer(L : Plua_state) : LongInt; Cdecl;
       
  3018 var at: LongInt;
       
  3019     weapon: PAmmo;
       
  3020     gear: PGear;
       
  3021 const call = 'GetAmmoTimer';
       
  3022       params = 'gearUid, ammoType';
       
  3023 begin
       
  3024     if CheckLuaParamCount(L, 2, call, params) then
       
  3025         begin
       
  3026         gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
       
  3027         if (gear <> nil) and (gear^.Hedgehog <> nil) then
       
  3028             begin
       
  3029             at:= LuaToAmmoTypeOrd(L, 2, call, params);
       
  3030             weapon:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
       
  3031             if (Ammoz[TAmmoType(at)].Ammo.Propz and ammoprop_Timerable) <> 0 then
       
  3032                 lua_pushnumber(L, weapon^.Timer)
       
  3033             else
       
  3034                 lua_pushnil(L);
       
  3035             end
       
  3036         else
       
  3037             lua_pushnil(L);
       
  3038         end
       
  3039     else
       
  3040         lua_pushnil(L);
       
  3041     lc_getammotimer:= 1;
       
  3042 end;
       
  3043 
       
  3044 function lc_setvampiric(L : Plua_state) : LongInt; Cdecl;
       
  3045 begin
       
  3046     if CheckLuaParamCount(L, 1, 'SetVampiric', 'bool') then
       
  3047         cVampiric := lua_toboolean(L, 1);
       
  3048     lc_setvampiric := 0;
       
  3049 end;
       
  3050 
       
  3051 function lc_setlasersight(L : Plua_state) : LongInt; Cdecl;
       
  3052 begin
       
  3053     if CheckLuaParamCount(L, 1, 'SetLaserSight', 'bool') then
       
  3054         cLaserSighting:= lua_toboolean(L, 1);
       
  3055     lc_setlasersight:= 0;
       
  3056 end;
       
  3057 
       
  3058 function lc_explode(L : Plua_state) : LongInt; Cdecl;
       
  3059 var mask: LongWord;
       
  3060     n: LongInt;
       
  3061 begin
       
  3062     if CheckAndFetchParamCount(L, 3, 4, 'Explode', 'x, y, radius[, options]', n) then
       
  3063         if CurrentHedgehog <> nil then
       
  3064             begin
       
  3065             mask:= EXPLAutoSound;
       
  3066             if (n = 4) then
       
  3067                 mask:= Trunc(lua_tonumber(L, 4));
       
  3068             doMakeExplosion(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), CurrentHedgehog, mask);
       
  3069             lua_pushboolean(L, true);
       
  3070             end
       
  3071         else
       
  3072             lua_pushboolean(L, false)
       
  3073     else
       
  3074         lua_pushboolean(L, false);
       
  3075     lc_explode:= 1;
  2739 end;
  3076 end;
  2740 
  3077 
  2741 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
  3078 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
  2742 begin
  3079 begin
  2743     if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
  3080     if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
  2922 // not required if there is no script to run
  3259 // not required if there is no script to run
  2923 if not ScriptLoaded then
  3260 if not ScriptLoaded then
  2924     exit;
  3261     exit;
  2925 
  3262 
  2926 // push game variables so they may be modified by the script
  3263 // push game variables so they may be modified by the script
  2927 ScriptSetInteger('CursorX', CursorPoint.X);
  3264 ScriptSetInteger('CursorX', NoPointX);
  2928 ScriptSetInteger('CursorY', CursorPoint.Y);
  3265 ScriptSetInteger('CursorY', NoPointX);
  2929 ScriptSetInteger('GameFlags', GameFlags);
  3266 ScriptSetInteger('GameFlags', GameFlags);
  2930 ScriptSetInteger('WorldEdge', ord(WorldEdge));
  3267 ScriptSetInteger('WorldEdge', ord(WorldEdge));
  2931 ScriptSetString('Seed', cSeed);
  3268 ScriptSetString('Seed', cSeed);
  2932 ScriptSetInteger('TemplateFilter', cTemplateFilter);
  3269 ScriptSetInteger('TemplateFilter', cTemplateFilter);
  2933 ScriptSetInteger('TemplateNumber', LuaTemplateNumber);
  3270 ScriptSetInteger('TemplateNumber', LuaTemplateNumber);
  3139 
  3476 
  3140 f:= pfsOpenRead(s);
  3477 f:= pfsOpenRead(s);
  3141 if f = nil then
  3478 if f = nil then
  3142     exit;
  3479     exit;
  3143 
  3480 
  3144 hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp'));
  3481 hedgewarsMountPackage(Str2PChar(copy(s, 3, length(s)-6)+'.hwp'));
  3145 
  3482 
  3146 physfsReaderSetBuffer(@buf);
  3483 physfsReaderSetBuffer(@buf);
  3147 if Pos('Locale/',s) <> 0 then
  3484 if Pos('Locale/',s) <> 0 then
  3148      ret:= lua_load(luaState, @ScriptLocaleReader, f, Str2PChar(s))
  3485      ret:= lua_load(luaState, @ScriptLocaleReader, f, Str2PChar(s))
  3149 else ret:= lua_load(luaState, @ScriptReader, f, Str2PChar(s));
  3486 else
       
  3487 	begin
       
  3488     SetRandomSeed(cSeed,true);
       
  3489 	ret:= lua_load(luaState, @ScriptReader, f, Str2PChar(s))
       
  3490 	end;
  3150 pfsClose(f);
  3491 pfsClose(f);
  3151 
  3492 
  3152 if ret <> 0 then
  3493 if ret <> 0 then
  3153     begin
  3494     begin
  3154     LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
  3495     LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
  3162     ScriptLoaded:= true
  3503     ScriptLoaded:= true
  3163     end;
  3504     end;
  3164 end;
  3505 end;
  3165 
  3506 
  3166 procedure SetGlobals;
  3507 procedure SetGlobals;
       
  3508 var x, y: LongInt;
  3167 begin
  3509 begin
  3168 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
  3510 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
  3169 ScriptSetInteger('ReadyTimeLeft', ReadyTimeLeft);
  3511 ScriptSetInteger('ReadyTimeLeft', ReadyTimeLeft);
  3170 ScriptSetInteger('GameTime', GameTicks);
  3512 ScriptSetInteger('GameTime', GameTicks);
  3171 ScriptSetInteger('TotalRounds', TotalRounds);
  3513 ScriptSetInteger('TotalRounds', TotalRounds);
  3172 ScriptSetInteger('WaterLine', cWaterLine);
  3514 ScriptSetInteger('WaterLine', cWaterLine);
  3173 if isCursorVisible and (not bShowAmmoMenu) then
  3515 if isCursorVisible and (not bShowAmmoMenu) then
  3174     begin
  3516     begin
  3175     if (prevCursorPoint.X <> CursorPoint.X) or
  3517     x:= CursorPoint.X - WorldDx;
  3176        (prevCursorPoint.Y <> CursorPoint.Y) then
  3518     y:= cScreenHeight - CursorPoint.Y - WorldDy;
  3177         begin
  3519     if (PrevCursorX <> x) or
  3178         ScriptSetInteger('CursorX', CursorPoint.X - WorldDx);
  3520        (PrevCursorY <> y) then
  3179         ScriptSetInteger('CursorY', cScreenHeight - CursorPoint.Y- WorldDy);
  3521         begin
  3180         prevCursorPoint.X:= CursorPoint.X;
  3522         ScriptSetInteger('CursorX', x);
  3181         prevCursorPoint.Y:= CursorPoint.Y;
  3523         ScriptSetInteger('CursorY', y);
       
  3524         PrevCursorX:= x;
       
  3525         PrevCursorY:= y;
  3182         end
  3526         end
  3183     end
  3527     end
  3184 else
  3528 else
  3185     begin
  3529     begin
  3186     ScriptSetInteger('CursorX', NoPointX);
  3530     ScriptSetInteger('CursorX', NoPointX);
  3187     ScriptSetInteger('CursorY', NoPointX);
  3531     ScriptSetInteger('CursorY', NoPointX);
  3188     prevCursorPoint.X:= NoPointX;
  3532     PrevCursorX:= NoPointX;
  3189     prevCursorPoint.Y:= NoPointX
  3533     PrevCursorY:= NoPointX
  3190     end;
  3534     end;
  3191 
  3535 
  3192 if not mapDims then
  3536 if not mapDims then
  3193     begin
  3537     begin
  3194     mapDims:= true;
  3538     mapDims:= true;
  3418 luaopen_string(luaState);
  3762 luaopen_string(luaState);
  3419 luaopen_math(luaState);
  3763 luaopen_math(luaState);
  3420 luaopen_table(luaState);
  3764 luaopen_table(luaState);
  3421 
  3765 
  3422 // import some variables
  3766 // import some variables
  3423 ScriptSetString(_S'L', cLocale);
  3767 ScriptSetString(_S'LOCALE', cLocale);
  3424 
  3768 
  3425 // import game flags
  3769 // import game flags
  3426 ScriptSetInteger('gfForts', gfForts);
  3770 ScriptSetInteger('gfSwitchHog', gfSwitchHog);
  3427 ScriptSetInteger('gfMultiWeapon', gfMultiWeapon);
  3771 ScriptSetInteger('gfMultiWeapon', gfMultiWeapon);
  3428 ScriptSetInteger('gfSolidLand', gfSolidLand);
  3772 ScriptSetInteger('gfSolidLand', gfSolidLand);
  3429 ScriptSetInteger('gfBorder', gfBorder);
  3773 ScriptSetInteger('gfBorder', gfBorder);
  3430 ScriptSetInteger('gfBottomBorder', gfBottomBorder);
  3774 ScriptSetInteger('gfBottomBorder', gfBottomBorder);
  3431 ScriptSetInteger('gfDivideTeams', gfDivideTeams);
  3775 ScriptSetInteger('gfDivideTeams', gfDivideTeams);
  3532 
  3876 
  3533 // ai hints
  3877 // ai hints
  3534 ScriptSetInteger('aihUsualProcessing', aihUsualProcessing);
  3878 ScriptSetInteger('aihUsualProcessing', aihUsualProcessing);
  3535 ScriptSetInteger('aihDoesntMatter'   , aihDoesntMatter);
  3879 ScriptSetInteger('aihDoesntMatter'   , aihDoesntMatter);
  3536 
  3880 
  3537 // land flags
  3881 // land flags (partial)
  3538 ScriptSetInteger('lfIndestructible', lfIndestructible);
  3882 ScriptSetInteger('lfIndestructible', lfIndestructible);
  3539 ScriptSetInteger('lfIce'           , lfIce);
  3883 ScriptSetInteger('lfIce'           , lfIce);
  3540 ScriptSetInteger('lfBouncy'        , lfBouncy);
  3884 ScriptSetInteger('lfBouncy'        , lfBouncy);
       
  3885 
       
  3886 ScriptSetInteger('lfLandMask'      , lfLandMask);
       
  3887 ScriptSetInteger('lfCurrentHog'    , lfCurrentHog);
       
  3888 ScriptSetInteger('lfHHMask'        , lfHHMask);
       
  3889 ScriptSetInteger('lfNotHHObjMask'  , lfNotHHObjMask);
       
  3890 ScriptSetInteger('lfAllObjMask'    , lfAllObjMask);
       
  3891 
       
  3892 // explosion constants
       
  3893 ScriptSetInteger('EXPLAutoSound'    , EXPLAutoSound);
       
  3894 ScriptSetInteger('EXPLNoDamage'     , EXPLNoDamage);
       
  3895 ScriptSetInteger('EXPLDoNotTouchHH' , EXPLDoNotTouchHH);
       
  3896 ScriptSetInteger('EXPLDontDraw'     , EXPLDontDraw);
       
  3897 ScriptSetInteger('EXPLNoGfx'        , EXPLNoGfx);
       
  3898 ScriptSetInteger('EXPLPoisoned'     , EXPLPoisoned);
       
  3899 ScriptSetInteger('EXPLDoNotTouchAny', EXPLDoNotTouchAny);
  3541 
  3900 
  3542 // register functions
  3901 // register functions
  3543 lua_register(luaState, _P'HideHog', @lc_hidehog);
  3902 lua_register(luaState, _P'HideHog', @lc_hidehog);
  3544 lua_register(luaState, _P'RestoreHog', @lc_restorehog);
  3903 lua_register(luaState, _P'RestoreHog', @lc_restorehog);
  3545 lua_register(luaState, _P'SaveCampaignVar', @lc_savecampaignvar);
  3904 lua_register(luaState, _P'SaveCampaignVar', @lc_savecampaignvar);
  3565 lua_register(luaState, _P'GetGearValues', @lc_getgearvalues);
  3924 lua_register(luaState, _P'GetGearValues', @lc_getgearvalues);
  3566 lua_register(luaState, _P'SetGearValues', @lc_setgearvalues);
  3925 lua_register(luaState, _P'SetGearValues', @lc_setgearvalues);
  3567 lua_register(luaState, _P'SpawnHealthCrate', @lc_spawnhealthcrate);
  3926 lua_register(luaState, _P'SpawnHealthCrate', @lc_spawnhealthcrate);
  3568 lua_register(luaState, _P'SpawnAmmoCrate', @lc_spawnammocrate);
  3927 lua_register(luaState, _P'SpawnAmmoCrate', @lc_spawnammocrate);
  3569 lua_register(luaState, _P'SpawnUtilityCrate', @lc_spawnutilitycrate);
  3928 lua_register(luaState, _P'SpawnUtilityCrate', @lc_spawnutilitycrate);
       
  3929 lua_register(luaState, _P'SpawnSupplyCrate', @lc_spawnsupplycrate);
  3570 lua_register(luaState, _P'SpawnFakeHealthCrate', @lc_spawnfakehealthcrate);
  3930 lua_register(luaState, _P'SpawnFakeHealthCrate', @lc_spawnfakehealthcrate);
  3571 lua_register(luaState, _P'SpawnFakeAmmoCrate', @lc_spawnfakeammocrate);
  3931 lua_register(luaState, _P'SpawnFakeAmmoCrate', @lc_spawnfakeammocrate);
  3572 lua_register(luaState, _P'SpawnFakeUtilityCrate', @lc_spawnfakeutilitycrate);
  3932 lua_register(luaState, _P'SpawnFakeUtilityCrate', @lc_spawnfakeutilitycrate);
  3573 lua_register(luaState, _P'WriteLnToConsole', @lc_writelntoconsole);
  3933 lua_register(luaState, _P'WriteLnToConsole', @lc_writelntoconsole);
       
  3934 lua_register(luaState, _P'WriteLnToChat', @lc_writelntochat);
  3574 lua_register(luaState, _P'GetGearType', @lc_getgeartype);
  3935 lua_register(luaState, _P'GetGearType', @lc_getgeartype);
  3575 lua_register(luaState, _P'EndGame', @lc_endgame);
  3936 lua_register(luaState, _P'EndGame', @lc_endgame);
  3576 lua_register(luaState, _P'EndTurn', @lc_endturn);
  3937 lua_register(luaState, _P'EndTurn', @lc_endturn);
       
  3938 lua_register(luaState, _P'Retreat', @lc_retreat);
       
  3939 lua_register(luaState, _P'SkipTurn', @lc_skipturn);
  3577 lua_register(luaState, _P'GetTeamStats', @lc_getteamstats);
  3940 lua_register(luaState, _P'GetTeamStats', @lc_getteamstats);
  3578 lua_register(luaState, _P'SendStat', @lc_sendstat);
  3941 lua_register(luaState, _P'SendStat', @lc_sendstat);
  3579 lua_register(luaState, _P'SendGameResultOff', @lc_sendgameresultoff);
  3942 lua_register(luaState, _P'SendGameResultOff', @lc_sendgameresultoff);
  3580 lua_register(luaState, _P'SendRankingStatsOff', @lc_sendrankingstatsoff);
  3943 lua_register(luaState, _P'SendRankingStatsOff', @lc_sendrankingstatsoff);
  3581 lua_register(luaState, _P'SendAchievementsStatsOff', @lc_sendachievementsstatsoff);
  3944 lua_register(luaState, _P'SendAchievementsStatsOff', @lc_sendachievementsstatsoff);
  3594 lua_register(luaState, _P'SetAmmoDescriptionAppendix', @lc_setammodescriptionappendix);
  3957 lua_register(luaState, _P'SetAmmoDescriptionAppendix', @lc_setammodescriptionappendix);
  3595 lua_register(luaState, _P'AddCaption', @lc_addcaption);
  3958 lua_register(luaState, _P'AddCaption', @lc_addcaption);
  3596 lua_register(luaState, _P'SetAmmo', @lc_setammo);
  3959 lua_register(luaState, _P'SetAmmo', @lc_setammo);
  3597 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
  3960 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
  3598 lua_register(luaState, _P'PlaySound', @lc_playsound);
  3961 lua_register(luaState, _P'PlaySound', @lc_playsound);
       
  3962 lua_register(luaState, _P'SetSoundMask', @lc_setsoundmask);
       
  3963 lua_register(luaState, _P'GetTeamName', @lc_getteamname);
       
  3964 lua_register(luaState, _P'GetTeamIndex', @lc_getteamindex);
       
  3965 lua_register(luaState, _P'GetTeamClan', @lc_getteamclan);
  3599 lua_register(luaState, _P'AddTeam', @lc_addteam);
  3966 lua_register(luaState, _P'AddTeam', @lc_addteam);
       
  3967 lua_register(luaState, _P'SetTeamLabel', @lc_setteamlabel);
  3600 lua_register(luaState, _P'AddHog', @lc_addhog);
  3968 lua_register(luaState, _P'AddHog', @lc_addhog);
  3601 lua_register(luaState, _P'AddAmmo', @lc_addammo);
  3969 lua_register(luaState, _P'AddAmmo', @lc_addammo);
  3602 lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
  3970 lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
       
  3971 lua_register(luaState, _P'HealHog', @lc_healhog);
  3603 lua_register(luaState, _P'SetHealth', @lc_sethealth);
  3972 lua_register(luaState, _P'SetHealth', @lc_sethealth);
  3604 lua_register(luaState, _P'GetHealth', @lc_gethealth);
  3973 lua_register(luaState, _P'GetHealth', @lc_gethealth);
  3605 lua_register(luaState, _P'SetEffect', @lc_seteffect);
  3974 lua_register(luaState, _P'SetEffect', @lc_seteffect);
  3606 lua_register(luaState, _P'GetEffect', @lc_geteffect);
  3975 lua_register(luaState, _P'GetEffect', @lc_geteffect);
  3607 lua_register(luaState, _P'GetHogClan', @lc_gethogclan);
  3976 lua_register(luaState, _P'GetHogClan', @lc_gethogclan);
  3633 lua_register(luaState, _P'GetFlightTime', @lc_getflighttime);
  4002 lua_register(luaState, _P'GetFlightTime', @lc_getflighttime);
  3634 lua_register(luaState, _P'SetZoom', @lc_setzoom);
  4003 lua_register(luaState, _P'SetZoom', @lc_setzoom);
  3635 lua_register(luaState, _P'GetZoom', @lc_getzoom);
  4004 lua_register(luaState, _P'GetZoom', @lc_getzoom);
  3636 lua_register(luaState, _P'HogSay', @lc_hogsay);
  4005 lua_register(luaState, _P'HogSay', @lc_hogsay);
  3637 lua_register(luaState, _P'SwitchHog', @lc_switchhog);
  4006 lua_register(luaState, _P'SwitchHog', @lc_switchhog);
       
  4007 lua_register(luaState, _P'EnableSwitchHog', @lc_enableswitchhog);
  3638 lua_register(luaState, _P'HogTurnLeft', @lc_hogturnleft);
  4008 lua_register(luaState, _P'HogTurnLeft', @lc_hogturnleft);
  3639 lua_register(luaState, _P'CampaignLock', @lc_campaignlock);
       
  3640 lua_register(luaState, _P'CampaignUnlock', @lc_campaignunlock);
       
  3641 lua_register(luaState, _P'GetGearElasticity', @lc_getgearelasticity);
  4009 lua_register(luaState, _P'GetGearElasticity', @lc_getgearelasticity);
  3642 lua_register(luaState, _P'SetGearElasticity', @lc_setgearelasticity);
  4010 lua_register(luaState, _P'SetGearElasticity', @lc_setgearelasticity);
  3643 lua_register(luaState, _P'GetGearFriction', @lc_getgearfriction);
  4011 lua_register(luaState, _P'GetGearFriction', @lc_getgearfriction);
  3644 lua_register(luaState, _P'SetGearFriction', @lc_setgearfriction);
  4012 lua_register(luaState, _P'SetGearFriction', @lc_setgearfriction);
  3645 lua_register(luaState, _P'GetGearRadius', @lc_getgearradius);
  4013 lua_register(luaState, _P'GetGearRadius', @lc_getgearradius);
  3649 lua_register(luaState, _P'SetGearPos', @lc_setgearpos);
  4017 lua_register(luaState, _P'SetGearPos', @lc_setgearpos);
  3650 lua_register(luaState, _P'GetGearCollisionMask', @lc_getgearcollisionmask);
  4018 lua_register(luaState, _P'GetGearCollisionMask', @lc_getgearcollisionmask);
  3651 lua_register(luaState, _P'SetGearCollisionMask', @lc_setgearcollisionmask);
  4019 lua_register(luaState, _P'SetGearCollisionMask', @lc_setgearcollisionmask);
  3652 lua_register(luaState, _P'GetRandom', @lc_getrandom);
  4020 lua_register(luaState, _P'GetRandom', @lc_getrandom);
  3653 lua_register(luaState, _P'SetWind', @lc_setwind);
  4021 lua_register(luaState, _P'SetWind', @lc_setwind);
       
  4022 lua_register(luaState, _P'GetWind', @lc_getwind);
  3654 lua_register(luaState, _P'MapHasBorder', @lc_maphasborder);
  4023 lua_register(luaState, _P'MapHasBorder', @lc_maphasborder);
  3655 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
  4024 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
  3656 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
  4025 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
  3657 lua_register(luaState, _P'EraseSprite', @lc_erasesprite);
  4026 lua_register(luaState, _P'EraseSprite', @lc_erasesprite);
  3658 lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
  4027 lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
  3666 lua_register(luaState, _P'SetNextWeapon', @lc_setnextweapon);
  4035 lua_register(luaState, _P'SetNextWeapon', @lc_setnextweapon);
  3667 lua_register(luaState, _P'SetWeapon', @lc_setweapon);
  4036 lua_register(luaState, _P'SetWeapon', @lc_setweapon);
  3668 lua_register(luaState, _P'SetCinematicMode', @lc_setcinematicmode);
  4037 lua_register(luaState, _P'SetCinematicMode', @lc_setcinematicmode);
  3669 lua_register(luaState, _P'SetMaxBuildDistance', @lc_setmaxbuilddistance);
  4038 lua_register(luaState, _P'SetMaxBuildDistance', @lc_setmaxbuilddistance);
  3670 lua_register(luaState, _P'GetAmmoName', @lc_getammoname);
  4039 lua_register(luaState, _P'GetAmmoName', @lc_getammoname);
       
  4040 lua_register(luaState, _P'GetAmmoTimer', @lc_getammotimer);
       
  4041 lua_register(luaState, _P'SetVampiric', @lc_setvampiric);
       
  4042 lua_register(luaState, _P'SetLaserSight', @lc_setlasersight);
       
  4043 lua_register(luaState, _P'Explode', @lc_explode);
  3671 // drawn map functions
  4044 // drawn map functions
  3672 lua_register(luaState, _P'AddPoint', @lc_addPoint);
  4045 lua_register(luaState, _P'AddPoint', @lc_addPoint);
  3673 lua_register(luaState, _P'FlushPoints', @lc_flushPoints);
  4046 lua_register(luaState, _P'FlushPoints', @lc_flushPoints);
  3674 
  4047 
  3675 lua_register(luaState, _P'SetGearAIHints', @lc_setgearaihints);
  4048 lua_register(luaState, _P'SetGearAIHints', @lc_setgearaihints);
  3789 
  4162 
  3790 procedure initModule;
  4163 procedure initModule;
  3791 begin
  4164 begin
  3792 mapDims:= false;
  4165 mapDims:= false;
  3793 PointsBuffer:= '';
  4166 PointsBuffer:= '';
  3794 prevCursorPoint.X:= NoPointX;
  4167 PrevCursorX:= NoPointX;
  3795 prevCursorPoint.Y:= 0;
  4168 PrevCursorY:= NoPointX;
  3796 end;
  4169 end;
  3797 
  4170 
  3798 procedure freeModule;
  4171 procedure freeModule;
  3799 begin
  4172 begin
  3800 end;
  4173 end;