280 lua_pushnil(L); |
280 lua_pushnil(L); |
281 end |
281 end |
282 else begin |
282 else begin |
283 if lua_gettop(L) = 3 then health:= lua_tointeger(L, 3) |
283 if lua_gettop(L) = 3 then health:= lua_tointeger(L, 3) |
284 else health:= cHealthCaseAmount; |
284 else health:= cHealthCaseAmount; |
285 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
285 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health); |
286 HealthCrate, health); |
286 if gear <> nil then lua_pushinteger(L, gear^.uid) |
287 lua_pushinteger(L, gear^.uid); |
287 else lua_pushnil(L); |
288 end; |
288 end; |
289 lc_spawnhealthcrate := 1; |
289 lc_spawnhealthcrate := 1; |
290 end; |
290 end; |
291 |
291 |
292 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; |
292 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; |
295 if lua_gettop(L) <> 3 then begin |
295 if lua_gettop(L) <> 3 then begin |
296 LuaError('Lua: Wrong number of parameters passed to SpawnAmmoCrate!'); |
296 LuaError('Lua: Wrong number of parameters passed to SpawnAmmoCrate!'); |
297 lua_pushnil(L); |
297 lua_pushnil(L); |
298 end |
298 end |
299 else begin |
299 else begin |
300 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
300 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3)); |
301 AmmoCrate, lua_tointeger(L, 3)); |
301 if gear <> nil then lua_pushinteger(L, gear^.uid) |
302 lua_pushinteger(L, gear^.uid); |
302 else lua_pushnil(L); |
303 end; |
303 end; |
304 lc_spawnammocrate := 1; |
304 lc_spawnammocrate := 1; |
305 end; |
305 end; |
306 |
306 |
307 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; |
307 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; |
312 lua_pushnil(L); |
312 lua_pushnil(L); |
313 end |
313 end |
314 else begin |
314 else begin |
315 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
315 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
316 UtilityCrate, lua_tointeger(L, 3)); |
316 UtilityCrate, lua_tointeger(L, 3)); |
317 lua_pushinteger(L, gear^.uid); |
317 if gear <> nil then lua_pushinteger(L, gear^.uid) |
|
318 else lua_pushnil(L); |
318 end; |
319 end; |
319 lc_spawnutilitycrate := 1; |
320 lc_spawnutilitycrate := 1; |
320 end; |
321 end; |
321 |
322 |
322 function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
323 function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
941 end |
942 end |
942 else LuaError('Lua: Wrong number of parameters passed to AddAmmo!'); |
943 else LuaError('Lua: Wrong number of parameters passed to AddAmmo!'); |
943 lc_addammo:= 0 |
944 lc_addammo:= 0 |
944 end; |
945 end; |
945 |
946 |
|
947 function lc_getammocount(L : Plua_State) : LongInt; Cdecl; |
|
948 var gear : PGear; |
|
949 ammo : PAmmo; |
|
950 begin |
|
951 if (lua_gettop(L) = 2) then |
|
952 begin |
|
953 gear:= GearByUID(lua_tointeger(L, 1)); |
|
954 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
|
955 begin |
|
956 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))); |
|
957 if ammo^.AmmoType = amNothing then lua_pushinteger(L, 0) |
|
958 else lua_pushinteger(L, ammo^.Count) |
|
959 end |
|
960 else lua_pushinteger(L, 0) |
|
961 end |
|
962 else LuaError('Lua: Wrong number of parameters passed to GetAmmoCount!'); |
|
963 lc_getammocount:= 0 |
|
964 end; |
|
965 |
946 function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
966 function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
947 var gear : PGear; |
967 var gear : PGear; |
948 begin |
968 begin |
949 if lua_gettop(L) <> 2 then |
969 if lua_gettop(L) <> 2 then |
950 begin |
970 begin |
1545 exit; |
1565 exit; |
1546 |
1566 |
1547 // push game variables so they may be modified by the script |
1567 // push game variables so they may be modified by the script |
1548 ScriptSetInteger('GameFlags', GameFlags); |
1568 ScriptSetInteger('GameFlags', GameFlags); |
1549 ScriptSetString('Seed', cSeed); |
1569 ScriptSetString('Seed', cSeed); |
|
1570 ScriptSetInteger('TemplateFilter', cTemplateFilter); |
|
1571 ScriptSetInteger('MapGen', cMapGen); |
1550 ScriptSetInteger('ScreenHeight', cScreenHeight); |
1572 ScriptSetInteger('ScreenHeight', cScreenHeight); |
1551 ScriptSetInteger('ScreenWidth', cScreenWidth); |
1573 ScriptSetInteger('ScreenWidth', cScreenWidth); |
1552 ScriptSetInteger('TurnTime', cHedgehogTurnTime); |
1574 ScriptSetInteger('TurnTime', cHedgehogTurnTime); |
1553 ScriptSetInteger('CaseFreq', cCaseFactor); |
1575 ScriptSetInteger('CaseFreq', cCaseFactor); |
1554 ScriptSetInteger('HealthCaseProb', cHealthCaseProb); |
1576 ScriptSetInteger('HealthCaseProb', cHealthCaseProb); |
1569 |
1591 |
1570 ScriptCall('onGameInit'); |
1592 ScriptCall('onGameInit'); |
1571 |
1593 |
1572 // pop game variables |
1594 // pop game variables |
1573 ParseCommand('seed ' + ScriptGetString('Seed'), true); |
1595 ParseCommand('seed ' + ScriptGetString('Seed'), true); |
|
1596 ParseCommand('template_filter ' + IntToStr(ScriptGetInteger('TemplateFilter')), true); |
|
1597 ParseCommand('mapgen ' + IntToStr(ScriptGetInteger('MapGen')), true); |
1574 ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true); |
1598 ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true); |
1575 ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true); |
1599 ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true); |
1576 ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true); |
1600 ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true); |
1577 ParseCommand('$healthprob ' + ScriptGetString('HealthCaseProb'), true); |
1601 ParseCommand('$healthprob ' + ScriptGetString('HealthCaseProb'), true); |
1578 ParseCommand('$hcaseamount ' + ScriptGetString('HealthCaseAmount'), true); |
1602 ParseCommand('$hcaseamount ' + ScriptGetString('HealthCaseAmount'), true); |
1628 begin |
1652 begin |
1629 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft); |
1653 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft); |
1630 ScriptSetInteger('GameTime', GameTicks); |
1654 ScriptSetInteger('GameTime', GameTicks); |
1631 ScriptSetInteger('RealTime', RealTicks); |
1655 ScriptSetInteger('RealTime', RealTicks); |
1632 ScriptSetInteger('TotalRounds', TotalRounds); |
1656 ScriptSetInteger('TotalRounds', TotalRounds); |
|
1657 ScriptSetInteger('WaterLine', cWaterLine); |
1633 if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then |
1658 if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then |
1634 ScriptSetInteger('CurrentHedgehog', CurrentHedgehog^.Gear^.UID) |
1659 ScriptSetInteger('CurrentHedgehog', CurrentHedgehog^.Gear^.UID) |
1635 else |
1660 else |
1636 ScriptSetNil('CurrentHedgehog'); |
1661 ScriptSetNil('CurrentHedgehog'); |
1637 end; |
1662 end; |
1924 lua_register(luaState, 'SetAmmo', @lc_setammo); |
1949 lua_register(luaState, 'SetAmmo', @lc_setammo); |
1925 lua_register(luaState, 'PlaySound', @lc_playsound); |
1950 lua_register(luaState, 'PlaySound', @lc_playsound); |
1926 lua_register(luaState, 'AddTeam', @lc_addteam); |
1951 lua_register(luaState, 'AddTeam', @lc_addteam); |
1927 lua_register(luaState, 'AddHog', @lc_addhog); |
1952 lua_register(luaState, 'AddHog', @lc_addhog); |
1928 lua_register(luaState, 'AddAmmo', @lc_addammo); |
1953 lua_register(luaState, 'AddAmmo', @lc_addammo); |
|
1954 lua_register(luaState, 'GetAmmoCount', @lc_getammocount); |
1929 lua_register(luaState, 'SetHealth', @lc_sethealth); |
1955 lua_register(luaState, 'SetHealth', @lc_sethealth); |
1930 lua_register(luaState, 'GetHealth', @lc_gethealth); |
1956 lua_register(luaState, 'GetHealth', @lc_gethealth); |
1931 lua_register(luaState, 'SetEffect', @lc_seteffect); |
1957 lua_register(luaState, 'SetEffect', @lc_seteffect); |
1932 lua_register(luaState, 'GetEffect', @lc_geteffect); |
1958 lua_register(luaState, 'GetEffect', @lc_geteffect); |
1933 lua_register(luaState, 'GetHogClan', @lc_gethogclan); |
1959 lua_register(luaState, 'GetHogClan', @lc_gethogclan); |