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).
authornemo
Tue, 16 Aug 2011 23:02:27 -0400
changeset 5584 e0b9722bd653
parent 5583 63b274a4fb01
child 5585 c09f5b41644a
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).
hedgewars/HHHandlers.inc
hedgewars/uGears.pas
--- 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
--- 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);