# HG changeset patch # User nemo # Date 1313550147 14400 # Node ID e0b9722bd6530d8228300b87da474b07ca501e01 # Parent 63b274a4fb012b26049d34c9aed432b0f9fd943c Make it a lot harder to cheat with typical random crates. This also means that crates will vary even if map has the same seed (hog positions of course will be unchanged). diff -r 63b274a4fb01 -r e0b9722bd653 hedgewars/HHHandlers.inc --- a/hedgewars/HHHandlers.inc Tue Aug 16 21:37:10 2011 -0400 +++ b/hedgewars/HHHandlers.inc Tue Aug 16 23:02:27 2011 -0400 @@ -551,7 +551,13 @@ case Gear^.Pos of posCaseUtility, posCaseAmmo: begin - a:= Gear^.AmmoType; + if Gear^.AmmoType <> amNothing then a:= Gear^.AmmoType + else + begin + for i:= 0 to GameTicks and $7F do GetRandom(2); // Burn some random numbers + if Gear^.Pos = posCaseUtility then a:= GetUtility + else a:= GetAmmo + end; 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 diff -r 63b274a4fb01 -r e0b9722bd653 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Tue Aug 16 21:37:10 2011 -0400 +++ b/hedgewars/uGears.pas Tue Aug 16 23:02:27 2011 -0400 @@ -40,6 +40,8 @@ function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content: Longword ): PGear; function SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean ): PGear; +function GetAmmo: TAmmoType; +function GetUtility: TAmmoType; procedure ResurrectHedgehog(gear: PGear); procedure ProcessGears; procedure EndTurnCleanup; @@ -1693,6 +1695,59 @@ SpawnFakeCrateAt := FollowGear; end; +function GetAmmo: TAmmoType; +var t, aTot: LongInt; + i: TAmmoType; +begin + +aTot:= 0; +for i:= Low(TAmmoType) to High(TAmmoType) do + if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then + inc(aTot, Ammoz[i].Probability); + +t:= aTot; +i:= Low(TAmmoType); +if (t > 0) then + begin + t:= GetRandom(t); + AddFileLog(inttostr(t)+' --------------'); + while t >= 0 do + begin + inc(i); + if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then + dec(t, Ammoz[i].Probability) + end + end; +GetAmmo:= i +end; + +function GetUtility: TAmmoType; +var t, uTot: LongInt; + i: TAmmoType; +begin + +uTot:= 0; +for i:= Low(TAmmoType) to High(TAmmoType) do + if (Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0 then + inc(uTot, Ammoz[i].Probability); + +t:= uTot; +i:= Low(TAmmoType); +if (t > 0) then + begin + t:= GetRandom(t); + while t >= 0 do + begin + inc(i); + if (Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0 then + dec(t, Ammoz[i].Probability) + end + end; +GetUtility:= i +end; + + + procedure SpawnBoxOfSmth; var t, aTot, uTot, a, h: LongInt; i: TAmmoType; @@ -1744,12 +1799,6 @@ FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); t:= GetRandom(t); i:= Low(TAmmoType); - while t >= 0 do - begin - inc(i); - if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then - dec(t, Ammoz[i].Probability) - end; FollowGear^.Pos:= posCaseAmmo; FollowGear^.AmmoType:= i; AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo); @@ -1763,12 +1812,6 @@ FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); t:= GetRandom(t); i:= Low(TAmmoType); - while t >= 0 do - begin - inc(i); - if (Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0 then - dec(t, Ammoz[i].Probability) - end; FollowGear^.Pos:= posCaseUtility; FollowGear^.AmmoType:= i; AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo);