diff -r ba4c3a4c8b09 -r e27100a0e2d0 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Thu Sep 01 14:55:31 2011 +0200 +++ b/hedgewars/uScript.pas Thu Sep 01 17:03:19 2011 +0200 @@ -282,9 +282,9 @@ else begin if lua_gettop(L) = 3 then health:= lua_tointeger(L, 3) else health:= cHealthCaseAmount; - gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), - HealthCrate, health); - lua_pushinteger(L, gear^.uid); + gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health); + if gear <> nil then lua_pushinteger(L, gear^.uid) + else lua_pushnil(L); end; lc_spawnhealthcrate := 1; end; @@ -297,9 +297,9 @@ lua_pushnil(L); end else begin - gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), - AmmoCrate, lua_tointeger(L, 3)); - lua_pushinteger(L, gear^.uid); + gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3)); + if gear <> nil then lua_pushinteger(L, gear^.uid) + else lua_pushnil(L); end; lc_spawnammocrate := 1; end; @@ -314,7 +314,8 @@ else begin gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3)); - lua_pushinteger(L, gear^.uid); + if gear <> nil then lua_pushinteger(L, gear^.uid) + else lua_pushnil(L); end; lc_spawnutilitycrate := 1; end; @@ -943,6 +944,25 @@ lc_addammo:= 0 end; +function lc_getammocount(L : Plua_State) : LongInt; Cdecl; +var gear : PGear; + ammo : PAmmo; +begin + if (lua_gettop(L) = 2) then + begin + gear:= GearByUID(lua_tointeger(L, 1)); + if (gear <> nil) and (gear^.Hedgehog <> nil) then + begin + ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))); + if ammo^.AmmoType = amNothing then lua_pushinteger(L, 0) + else lua_pushinteger(L, ammo^.Count) + end + else lua_pushinteger(L, 0) + end + else LuaError('Lua: Wrong number of parameters passed to GetAmmoCount!'); + lc_getammocount:= 0 +end; + function lc_sethealth(L : Plua_State) : LongInt; Cdecl; var gear : PGear; begin @@ -1547,6 +1567,8 @@ // push game variables so they may be modified by the script ScriptSetInteger('GameFlags', GameFlags); ScriptSetString('Seed', cSeed); +ScriptSetInteger('TemplateFilter', cTemplateFilter); +ScriptSetInteger('MapGen', cMapGen); ScriptSetInteger('ScreenHeight', cScreenHeight); ScriptSetInteger('ScreenWidth', cScreenWidth); ScriptSetInteger('TurnTime', cHedgehogTurnTime); @@ -1571,6 +1593,8 @@ // pop game variables ParseCommand('seed ' + ScriptGetString('Seed'), true); +ParseCommand('template_filter ' + IntToStr(ScriptGetInteger('TemplateFilter')), true); +ParseCommand('mapgen ' + IntToStr(ScriptGetInteger('MapGen')), true); ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true); ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true); ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true); @@ -1630,6 +1654,7 @@ ScriptSetInteger('GameTime', GameTicks); ScriptSetInteger('RealTime', RealTicks); ScriptSetInteger('TotalRounds', TotalRounds); +ScriptSetInteger('WaterLine', cWaterLine); if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then ScriptSetInteger('CurrentHedgehog', CurrentHedgehog^.Gear^.UID) else @@ -1926,6 +1951,7 @@ lua_register(luaState, 'AddTeam', @lc_addteam); lua_register(luaState, 'AddHog', @lc_addhog); lua_register(luaState, 'AddAmmo', @lc_addammo); +lua_register(luaState, 'GetAmmoCount', @lc_getammocount); lua_register(luaState, 'SetHealth', @lc_sethealth); lua_register(luaState, 'GetHealth', @lc_gethealth); lua_register(luaState, 'SetEffect', @lc_seteffect);