Allow script to set number of ammo in a crate. untested.
--- a/hedgewars/uAmmos.pas Tue Jul 03 22:44:50 2012 +0400
+++ b/hedgewars/uAmmos.pas Wed Jul 04 10:56:42 2012 -0400
@@ -32,6 +32,7 @@
procedure SetAmmoReinforcement(var s: shortstring);
procedure AssignStores;
procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
+procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; amt: LongWord);
procedure SetAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
function HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): LongWord;
procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
@@ -188,7 +189,7 @@
end
end;
-procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
+procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; amt: LongWord);
var cnt: LongWord;
a: PAmmo;
begin
@@ -199,11 +200,16 @@
cnt:= 0;
if (cnt <> AMMO_INFINITE) then
begin
- inc(cnt, Ammoz[ammo].NumberInCase);
+ inc(cnt, amt);
SetAmmo(Hedgehog, ammo, cnt)
end
end;
+procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
+begin
+ AddAmmo(Hedgehog, ammo, Ammoz[ammo].NumberInCase);
+end;
+
procedure SetAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
var ammos: TAmmoCounts;
slot, ami: LongInt;
--- a/hedgewars/uGears.pas Tue Jul 03 22:44:50 2012 +0400
+++ b/hedgewars/uGears.pas Wed Jul 04 10:56:42 2012 -0400
@@ -37,7 +37,7 @@
procedure initModule;
procedure freeModule;
-function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content: Longword ): PGear;
+function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content, cnt: Longword): PGear;
function SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean ): PGear;
function GetAmmo(Hedgehog: PHedgehog): TAmmoType;
function GetUtility(Hedgehog: PHedgehog): TAmmoType;
@@ -933,7 +933,7 @@
CountGears:= count;
end;
-function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content: Longword): PGear;
+function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content, cnt: Longword): PGear;
begin
FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0);
cCaseFactor := 0;
@@ -941,6 +941,8 @@
if (crate <> HealthCrate) and (content > ord(High(TAmmoType))) then
content := ord(High(TAmmoType));
+ FollowGear^.Power:= cnt;
+
case crate of
HealthCrate:
begin
--- a/hedgewars/uGearsHedgehog.pas Tue Jul 03 22:44:50 2012 +0400
+++ b/hedgewars/uGearsHedgehog.pas Wed Jul 04 10:56:42 2012 -0400
@@ -596,7 +596,8 @@
else
a:= GetAmmo(HH^.Hedgehog)
end;
- AddAmmo(HH^.Hedgehog^, a);
+ if Gear^.Power <> 0 then AddAmmo(HH^.Hedgehog^, a, Gear^.Power)
+ else AddAmmo(HH^.Hedgehog^, a);
// Possibly needs to check shared clan ammo game flag once added.
// On the other hand, no obvious reason that clan members shouldn't know what ammo another clan member picked up
if (not (HH^.Hedgehog^.Team^.ExtDriven
--- a/hedgewars/uGearsList.pas Tue Jul 03 22:44:50 2012 +0400
+++ b/hedgewars/uGearsList.pas Wed Jul 04 10:56:42 2012 -0400
@@ -101,6 +101,7 @@
// Define ammo association, if any.
gear^.AmmoType:= GearKindAmmoTypeMap[Kind];
gear^.CollisionMask:= $FFFF;
+gear^.Power:= 0;
if CurrentHedgehog <> nil then gear^.Hedgehog:= CurrentHedgehog;
--- a/hedgewars/uGearsRender.pas Tue Jul 03 22:44:50 2012 +0400
+++ b/hedgewars/uGearsRender.pas Wed Jul 04 10:56:42 2012 -0400
@@ -1015,7 +1015,7 @@
DrawSprite(sprUtility, x - 24, y - 24, i);
end;
end;
- if Gear^.Timer <= 1833 then
+ if Gear^.Timer < 1833 then
begin
DrawTextureRotatedF(SpritesData[sprPortal].texture, min(abs(1.25 - (Gear^.Timer mod 1333) / 400), 1.25), 0, 0,
Gear^.Angle+WorldDx, Gear^.Power+WorldDy-16, 4+Gear^.Tag, 1, 32, 32, 270);
--- a/hedgewars/uScript.pas Tue Jul 03 22:44:50 2012 +0400
+++ b/hedgewars/uScript.pas Wed Jul 04 10:56:42 2012 -0400
@@ -322,7 +322,7 @@
health:= lua_tointeger(L, 3)
else
health:= cHealthCaseAmount;
- gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health);
+ gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0);
if gear <> nil then
lua_pushinteger(L, gear^.uid)
else
@@ -334,14 +334,16 @@
function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl;
var gear: PGear;
begin
- if lua_gettop(L) <> 3 then
+ if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
begin
LuaError('Lua: Wrong number of parameters passed to SpawnAmmoCrate!');
lua_pushnil(L);
end
else
begin
- gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3));
+ if (lua_gettop(L) <> 3) then
+ gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0)
+ else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
if gear <> nil then
lua_pushinteger(L, gear^.uid)
else
@@ -353,15 +355,16 @@
function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl;
var gear: PGear;
begin
- if lua_gettop(L) <> 3 then
+ if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
begin
LuaError('Lua: Wrong number of parameters passed to SpawnUtilityCrate!');
lua_pushnil(L);
end
else
- begin
- gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
- UtilityCrate, lua_tointeger(L, 3));
+ begin
+ if (lua_gettop(L) <> 3) then
+ gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0)
+ else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
if gear <> nil then
lua_pushinteger(L, gear^.uid)
else