# HG changeset patch # User sheepluva # Date 1386150435 -3600 # Node ID 7a6038c3faa21c3635819ae4b6a5bd1d4afe147d # Parent 8963312df207e772b898b165f4f205e1db6b6657 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior) diff -r 8963312df207 -r 7a6038c3faa2 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Wed Dec 04 09:54:16 2013 +0100 +++ b/hedgewars/uScript.pas Wed Dec 04 10:47:15 2013 +0100 @@ -99,6 +99,7 @@ procedure ScriptPrepareAmmoStore; forward; procedure ScriptApplyAmmoStore; forward; procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward; +procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward; procedure LuaError(s: shortstring); begin @@ -1606,6 +1607,17 @@ lc_setammo:= 0 end; +function lc_setammodelay(L : Plua_State) : LongInt; Cdecl; +var np: LongInt; +begin + np:= lua_gettop(L); + if (np <> 2) then + LuaError('Lua: Wrong number of parameters passed to SetAmmoDelay!') + else + ScriptSetAmmoDelay(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2)); + lc_setammodelay:= 0 +end; + function lc_setammostore(L : Plua_State) : LongInt; Cdecl; var np: LongInt; begin @@ -2238,10 +2250,23 @@ exit; ScriptAmmoLoadout[ord(ammo)]:= inttostr(count)[1]; ScriptAmmoProbability[ord(ammo)]:= inttostr(probability)[1]; -ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1]; +ScriptSetAmmoDelay(ammo, delay); ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1]; end; +procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); +begin +// change loadout string if ammo store hasn't been initialized yet +if (StoreCnt = 0) then +begin + if (delay <= 9) then + ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1]; +end +// change "live" delay values +else if (CurrentTeam <> nil) then + ammoz[ammo].SkipTurns:= CurrentTeam^.Clan^.TurnNumber + delay; +end; + procedure ScriptApplyAmmoStore; var i, j, k : LongInt; begin @@ -2461,6 +2486,7 @@ lua_register(luaState, _P'HideMission', @lc_hidemission); lua_register(luaState, _P'AddCaption', @lc_addcaption); lua_register(luaState, _P'SetAmmo', @lc_setammo); +lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay); lua_register(luaState, _P'SetAmmoStore', @lc_setammostore); lua_register(luaState, _P'PlaySound', @lc_playsound); lua_register(luaState, _P'AddTeam', @lc_addteam);