--- a/hedgewars/uGears.pas Fri Aug 06 11:53:28 2010 +0200
+++ b/hedgewars/uGears.pas Sat Aug 07 01:45:31 2010 +0200
@@ -81,6 +81,7 @@
procedure initModule;
procedure freeModule;
function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
+procedure SpawnHealthCrate(x, y: LongInt);
procedure ProcessGears;
procedure EndTurnCleanup;
procedure ApplyDamage(Gear: PGear; Damage: Longword; Source: TDamageSource);
@@ -1538,6 +1539,14 @@
CountGears:= count;
end;
+procedure SpawnHealthCrate(x, y: LongInt);
+begin
+ FollowGear:= AddGear(x, y, gtCase, 0, _0, _0, 0);
+ FollowGear^.Health:= 25;
+ FollowGear^.Pos:= posCaseHealth;
+ AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo);
+end;
+
procedure SpawnBoxOfSmth;
var t, aTot, uTot, a, h: LongInt;
i: TAmmoType;
--- a/hedgewars/uScript.pas Fri Aug 06 11:53:28 2010 +0200
+++ b/hedgewars/uScript.pas Sat Aug 07 01:45:31 2010 +0200
@@ -117,6 +117,22 @@
lc_hidemission:= 0;
end;
+function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl;
+var x, y: LongInt;
+begin
+ if lua_gettop(L) <> 2 then begin
+ LuaError('Lua: Wrong number of parameters passed to SpawnHealthCrate!');
+ lua_pushnil(L);
+ end
+ else begin
+ x:= lua_tointeger(L, 1);
+ y:= lua_tointeger(L, 2);
+ cCaseFactor := 0;
+ SpawnHealthCrate(x, y);
+ end;
+ lc_spawnhealthCrate := 1;
+end;
+
function lc_addgear(L : Plua_State) : LongInt; Cdecl;
var gear : PGear;
x, y, s, t: LongInt;
@@ -862,6 +878,7 @@
// register functions
lua_register(luaState, 'AddGear', @lc_addgear);
+lua_register(luaState, 'SpawnHealthCrate', @lc_spawnhealthcrate);
lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole);
lua_register(luaState, 'GetGearType', @lc_getgeartype);
lua_register(luaState, 'EndGame', @lc_endgame);
--- a/share/hedgewars/Data/Maps/FlightJoust/map.lua Fri Aug 06 11:53:28 2010 +0200
+++ b/share/hedgewars/Data/Maps/FlightJoust/map.lua Sat Aug 07 01:45:31 2010 +0200
@@ -1,53 +1,71 @@
-local hogs = {}
-
-function mapM_(func, tbl)
- for i,v in pairs(tbl) do
- func(v)
- end
-end
-
-function map(func, tbl)
- local newtbl = {}
- for i,v in pairs(tbl) do
- newtbl[i] = func(v)
- end
- return newtbl
-end
-
-function onGameInit()
- GameFlags = gfSolidLand + gfDivideTeams
- TurnTime = 10000
- CaseFreq = 0
- LandAdds = 0
- Explosives = 0
- Delay = 500
- SuddenDeathTurns = 99999 -- "disable" sudden death
- Theme = Compost
-end
-
-function setHogPositions(gear)
- if GetHogClan(gear) == 0 then
- SetGearPosition(gear, 250, 1000)
- end
- if GetHogClan(gear) == 1 then
- SetGearPosition(gear, 3500, 1000)
- end
-end
-
-function onGameStart()
- mapM_(setHogPositions, hogs)
-end
-
-function onAmmoStoreInit()
- SetAmmo(amRCPlane, 9, 0, 0, 0)
- SetAmmo(amSkip, 9, 0, 0, 0)
-end
-
-function onGearAdd(gear)
- if GetGearType(gear) == gtRCPlane then
- SetTimer(gear,60000)
- end
- if GetGearType(gear) == gtHedgehog then
- table.insert(hogs, gear)
- end
-end
\ No newline at end of file
+local hogs = {}
+
+function mapM_(func, tbl)
+ for i,v in pairs(tbl) do
+ func(v)
+ end
+end
+
+function map(func, tbl)
+ local newtbl = {}
+ for i,v in pairs(tbl) do
+ newtbl[i] = func(v)
+ end
+ return newtbl
+end
+
+function filter(func, tbl)
+ local newtbl = {}
+ for i,v in pairs(tbl) do
+ if func(v) then
+ table.insert(newtbl, v)
+ end
+ end
+ return newtbl
+end
+
+function onGameInit()
+ GameFlags = gfSolidLand + gfDivideTeams
+ TurnTime = 10000
+ CaseFreq = 0
+ LandAdds = 0
+ Explosives = 0
+ Delay = 500
+ SuddenDeathTurns = 99999 -- "disable" sudden death
+ Theme = Compost
+end
+
+function onGameStart()
+ local offset = 50
+ local team1hh = filter(function(h) return GetHogClan(h) == 0 end, hogs)
+ local team2hh = filter(function(h) return GetHogClan(h) == 1 end, hogs)
+
+ for i,h in ipairs(team1hh) do
+ SetGearPosition(h, 250+(i-1)*offset, 1000)
+ end
+ for i,h in ipairs(team2hh) do
+ SetGearPosition(h, 3500-(i-1)*offset, 1000)
+ end
+
+ SpawnHealthCrate(1800, 1200)
+end
+
+function onAmmoStoreInit()
+ SetAmmo(amRCPlane, 9, 0, 0, 0)
+ SetAmmo(amSkip, 9, 0, 0, 0)
+end
+
+function onGearAdd(gear)
+ if GetGearType(gear) == gtRCPlane then
+ SetTimer(gear,60000)
+ end
+ if GetGearType(gear) == gtHedgehog then
+ table.insert(hogs, gear)
+ end
+end
+
+function onGearDelete(gear)
+ if GetGearType(gear) == gtCase then
+ SpawnHealthCrate(1600 + math.random(550), 1150)
+ end
+end