hedgewars/uGears.pas
changeset 3259 a29ccf4aed82
parent 3255 6d6f4241debe
child 3261 fa7086253e83
equal deleted inserted replaced
3258:3fc081d348fe 3259:a29ccf4aed82
  2149     end;
  2149     end;
  2150 CountGears:= count;
  2150 CountGears:= count;
  2151 end;
  2151 end;
  2152 
  2152 
  2153 procedure SpawnBoxOfSmth;
  2153 procedure SpawnBoxOfSmth;
  2154 var t: LongInt;
  2154 var t, aTot, uTot, a, h: LongInt;
  2155     i: TAmmoType;
  2155     i: TAmmoType;
  2156 begin
  2156 begin
  2157 if (PlacingHogs) or
  2157 if (PlacingHogs) or
  2158    (cCaseFactor = 0) or
  2158    (cCaseFactor = 0) or
  2159    (CountGears(gtCase) >= 5) or
  2159    (CountGears(gtCase) >= 5) or
  2160    (getrandom(cCaseFactor) <> 0) then exit;
  2160    (GetRandom(cCaseFactor) <> 0) then exit;
  2161 
  2161 
  2162 FollowGear:= nil;
  2162 FollowGear:= nil;
  2163 
  2163 aTot:= 0;
  2164 t:= getrandom(20);
  2164 uTot:= 0;
  2165 
  2165 for i:= Low(TAmmoType) to High(TAmmoType) do
  2166 // FIXME - shoppa is TEMPORARY REMOVE WHEN CRATE PROBABILITY ALLOWS DISABLING OF HEALTH CRATES                               
  2166     if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then
  2167 // avoid health crates if all hogs are invulnerable                                                                          
  2167         inc(aTot, Ammoz[i].Probability)
  2168 if (t < 13) and (shoppa or ((GameFlags and gfInvulnerable) <> 0)) then t:= t * 13 div 20 + 7;                                
  2168     else
       
  2169         inc(uTot, Ammoz[i].Probability);
       
  2170 
       
  2171 t:=0;
       
  2172 a:=aTot;
       
  2173 h:= 0;
       
  2174 // FIXME - shoppa is TEMPORARY REMOVE WHEN CRATE PROBABILITY ALLOWS DISABLING OF HEALTH CRATES
       
  2175 // Preserving health crate distribution of 35% until that happens
       
  2176 if not shoppa and ((GameFlags and gfInvulnerable) = 0) and ((aTot+uTot)<>0) then 
       
  2177     begin
       
  2178     h:= 3500;
       
  2179     t:= GetRandom(10000);
       
  2180     a:= 6500*aTot div (aTot+uTot)
       
  2181     end
       
  2182 else t:= GetRandom(aTot+uTot);
       
  2183 
  2169     
  2184     
  2170 //case getrandom(20) of
  2185 if not shoppa and ((GameFlags and gfInvulnerable) = 0) and (t<h) then
  2171 case t of
  2186     begin
  2172      0..6: begin
  2187     FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0);
       
  2188     FollowGear^.Health:= 25;
       
  2189     FollowGear^.Pos:= posCaseHealth;
       
  2190     AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpGameState);
       
  2191     end
       
  2192 else if (t<a+h) then
       
  2193     begin
       
  2194     t:= aTot;
       
  2195     if (t > 0) then
       
  2196         begin
  2173         FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0);
  2197         FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0);
  2174         FollowGear^.Health:= 25;
  2198         t:= GetRandom(t);
  2175         FollowGear^.Pos:= posCaseHealth;
  2199         i:= Low(TAmmoType);
  2176         AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpGameState);
  2200         if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then
  2177         end;
  2201             dec(t, Ammoz[i].Probability);
  2178      7..13: begin
  2202         while t >= 0 do
  2179         t:= 0;
  2203           begin
  2180         for i:= Low(TAmmoType) to High(TAmmoType) do
  2204           inc(i);
  2181             if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then
  2205           if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then
  2182                 inc(t, Ammoz[i].Probability);
  2206               dec(t, Ammoz[i].Probability)
  2183         if (t > 0) then
  2207           end;
  2184             begin
  2208         FollowGear^.Pos:= posCaseAmmo;
  2185             FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0);
  2209         FollowGear^.State:= Longword(i);
  2186             t:= GetRandom(t);
  2210         AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpGameState);
  2187             i:= Low(TAmmoType);
  2211         end
  2188             if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then
  2212     end
  2189                 dec(t, Ammoz[i].Probability);
  2213 else
  2190             while t >= 0 do
  2214     begin
  2191               begin
  2215     t:= uTot;
  2192               inc(i);
  2216     if (t > 0) then
  2193               if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then
  2217         begin
  2194                   dec(t, Ammoz[i].Probability)
  2218         FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0);
  2195               end;
  2219         t:= GetRandom(t);
  2196             FollowGear^.Pos:= posCaseAmmo;
  2220         i:= Low(TAmmoType);
  2197             FollowGear^.State:= Longword(i);
  2221         if (Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0 then
  2198             AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpGameState);
  2222             dec(t, Ammoz[i].Probability);
  2199             end
  2223         while t >= 0 do
  2200         end;
  2224           begin
  2201      14..19: begin
  2225           inc(i);
  2202         t:= 0;
  2226           if (Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0 then
  2203         for i:= Low(TAmmoType) to High(TAmmoType) do
  2227               dec(t, Ammoz[i].Probability)
  2204             if (Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0 then
  2228           end;
  2205                 inc(t, Ammoz[i].Probability);
  2229         FollowGear^.Pos:= posCaseUtility;
  2206         if (t > 0) then
  2230         FollowGear^.State:= Longword(i);
  2207             begin
  2231         AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpGameState);
  2208             FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0);
  2232         end
  2209             t:= GetRandom(t);
  2233     end;
  2210             i:= Low(TAmmoType);
  2234 
  2211             if (Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0 then
       
  2212                 dec(t, Ammoz[i].Probability);
       
  2213             while t >= 0 do
       
  2214               begin
       
  2215               inc(i);
       
  2216               if (Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0 then
       
  2217                   dec(t, Ammoz[i].Probability)
       
  2218               end;
       
  2219             FollowGear^.Pos:= posCaseUtility;
       
  2220             FollowGear^.State:= Longword(i);
       
  2221             AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpGameState);
       
  2222             end
       
  2223         end;
       
  2224      end;
       
  2225 // handles case of no ammo or utility crates - considered also placing booleans in uAmmos and altering probabilities
  2235 // handles case of no ammo or utility crates - considered also placing booleans in uAmmos and altering probabilities
  2226 if (FollowGear <> nil) then
  2236 if (FollowGear <> nil) then
  2227     begin
  2237     begin
  2228     FindPlace(FollowGear, true, 0, LAND_WIDTH);
  2238     FindPlace(FollowGear, true, 0, LAND_WIDTH);
  2229 
  2239