# HG changeset patch # User Wuzzy # Date 1531006213 -7200 # Node ID 794dcf69a5aae10b900738901333daad22ff6384 # Parent 8f746b6a477cf74ced83ae95197ece3bf3a1a7c3 New Lua API function: GetAmmo, to get ammo config diff -r 8f746b6a477c -r 794dcf69a5aa ChangeLog.txt --- a/ChangeLog.txt Sun Jul 08 00:16:33 2018 +0200 +++ b/ChangeLog.txt Sun Jul 08 01:30:13 2018 +0200 @@ -33,6 +33,7 @@ + New call: Retreat(time [, respectGetAwayTimeFactor): Force current turn into retreating mode + New call: GetAmmoTimer(gearUid, ammoType): Returns current set timer for given ammoType and hog gear in ms. Returns nil for non-timerable ammo + New call: EnableSwitchHog(): Enable hog switching + + New call: GetAmmo(ammoType): Returns ammo configuration (corresponds to SetAmmo) + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available” * Fixed variable: TotalRounds was -1 (instead of 0) in first real round after hog placement phase diff -r 8f746b6a477c -r 794dcf69a5aa hedgewars/uAmmos.pas --- a/hedgewars/uAmmos.pas Sun Jul 08 00:16:33 2018 +0200 +++ b/hedgewars/uAmmos.pas Sun Jul 08 01:30:13 2018 +0200 @@ -79,7 +79,6 @@ end; procedure AddAmmoStore; -const probability: array [0..8] of LongWord = (0,20,30,60,100,200,400,600,800); var cnt: Longword; a: TAmmoType; ammos: TAmmoCounts; @@ -99,7 +98,7 @@ begin if a <> amNothing then begin - Ammoz[a].Probability:= probability[byte(ammoProbability[ord(a)]) - byte('0')]; + Ammoz[a].Probability:= probabilityLevels[byte(ammoProbability[ord(a)]) - byte('0')]; Ammoz[a].SkipTurns:= (byte(ammoDelay[ord(a)]) - byte('0')); Ammoz[a].NumberInCase:= (byte(ammoReinforcement[ord(a)]) - byte('0')); cnt:= byte(ammoLoadout[ord(a)]) - byte('0'); diff -r 8f746b6a477c -r 794dcf69a5aa hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Sun Jul 08 00:16:33 2018 +0200 +++ b/hedgewars/uConsts.pas Sun Jul 08 01:30:13 2018 +0200 @@ -315,6 +315,8 @@ AMMO_INFINITE = 100; AMMO_FINITE_MAX = 99; + probabilityLevels: array [0..8] of LongWord = (0,20,30,60,100,200,400,600,800); + // explosion flags //EXPLAllDamageInRadius = $00000001; Completely unused for ages EXPLAutoSound = $00000002; diff -r 8f746b6a477c -r 794dcf69a5aa hedgewars/uScript.pas --- a/hedgewars/uScript.pas Sun Jul 08 00:16:33 2018 +0200 +++ b/hedgewars/uScript.pas Sun Jul 08 01:30:13 2018 +0200 @@ -2591,6 +2591,42 @@ lc_setammo:= 0 end; + +function lc_getammo(L : Plua_State) : LongInt; Cdecl; +var i, at, rawProb, probLevel: LongInt; +const + call = 'GetAmmo'; + params = 'ammoType'; +begin + if CheckLuaParamCount(L, 1, call, params) then + begin + at:= LuaToAmmoTypeOrd(L, 1, call, params); + if at >= 0 then + begin + // Ammo count + i:= Ammoz[TAmmoType(at)].Ammo.Count; + if i = AMMO_INFINITE then + i:= 9; + lua_pushnumber(L, i); + // Probability + rawProb:= Ammoz[TAmmoType(at)].Probability; + probLevel:= -1; + for i := 0 to High(probabilityLevels) do + if rawProb = probabilityLevels[i] then + probLevel:= i; + lua_pushnumber(L, probLevel); + // Delay in turns + lua_pushnumber(L, Ammoz[TAmmoType(at)].SkipTurns); + // Number in case + lua_pushnumber(L, Ammoz[TAmmoType(at)].NumberInCase); + lc_getammo:= 4 + end + else + lc_getammo:= 0 + end; +end; + + function lc_setammodelay(L : Plua_State) : LongInt; Cdecl; var at: LongInt; const @@ -3959,6 +3995,7 @@ lua_register(luaState, _P'SetAmmoDescriptionAppendix', @lc_setammodescriptionappendix); lua_register(luaState, _P'AddCaption', @lc_addcaption); lua_register(luaState, _P'SetAmmo', @lc_setammo); +lua_register(luaState, _P'GetAmmo', @lc_getammo); lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay); lua_register(luaState, _P'PlaySound', @lc_playsound); lua_register(luaState, _P'SetSoundMask', @lc_setsoundmask);