hedgewars/uGearsUtils.pas
changeset 6803 0e70f3ea3bf8
parent 6769 44ad49a3a126
child 6804 06bedc419d04
equal deleted inserted replaced
6802:8701007d58c0 6803:0e70f3ea3bf8
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uGearsUtils;
    21 unit uGearsUtils;
    22 interface
    22 interface
    23 uses uTypes;
    23 uses uTypes, math;
    24 
    24 
    25 procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord = $FFFFFFFF); 
    25 procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord = $FFFFFFFF); 
    26 function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
    26 function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
    27 procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
    27 procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
    28 procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
    28 procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
   325 function CheckGearDrowning(Gear: PGear): boolean;
   325 function CheckGearDrowning(Gear: PGear): boolean;
   326 var 
   326 var 
   327     skipSpeed, skipAngle, skipDecay: hwFloat;
   327     skipSpeed, skipAngle, skipDecay: hwFloat;
   328     i, maxDrops, X, Y: LongInt;
   328     i, maxDrops, X, Y: LongInt;
   329     vdX, vdY: real;
   329     vdX, vdY: real;
   330     particle: PVisualGear;
   330     particle, splash: PVisualGear;
   331     isSubmersible: boolean;
   331     isSubmersible: boolean;
   332 begin
   332 begin
   333     // probably needs tweaking. might need to be in a case statement based upon gear type
   333     // probably needs tweaking. might need to be in a case statement based upon gear type
   334     Y:= hwRound(Gear^.Y);
   334     Y:= hwRound(Gear^.Y);
   335     if cWaterLine < Y + Gear^.Radius then
   335     if cWaterLine < Y + Gear^.Radius then
   386         if ((cReducedQuality and rqPlainSplash) = 0)
   386         if ((cReducedQuality and rqPlainSplash) = 0)
   387         and (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius))
   387         and (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius))
   388         or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0)
   388         or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0)
   389         and (CurAmmoGear^.dY < _0_01)))) then
   389         and (CurAmmoGear^.dY < _0_01)))) then
   390             begin
   390             begin
   391             AddVisualGear(X, cWaterLine, vgtSplash);
   391             splash:= AddVisualGear(X, cWaterLine, vgtSplash);
   392 
   392             if splash <> nil then 
   393             maxDrops := (Gear^.Radius div 2) + round(vdX * Gear^.Radius * 2) + round(vdY * Gear^.Radius * 2);
   393                 begin
       
   394                 splash^.Scale:= hwFloat2Float(Gear^.Density / _3);
       
   395                 if splash^.Scale > 1 then splash^.Scale:= power(splash^.Scale,0.3333)
       
   396                 else splash^.Scale:= splash^.Scale + ((1-splash^.Scale) / 2);
       
   397                 end;
       
   398 
       
   399             maxDrops := (hwRound(Gear^.Density) * 3) div 2 + round(vdX * hwRound(Gear^.Density) * 6) + round(vdY * hwRound(Gear^.Density) * 6);
   394             for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
   400             for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
   395                 begin
   401                 begin
   396                 particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet);
   402                 particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet);
   397                 if particle <> nil then
   403                 if particle <> nil then
   398                     begin
   404                     begin
   399                     particle^.dX := particle^.dX - vdX / 10;
   405                     particle^.dX := particle^.dX - vdX / 10;
   400                     particle^.dY := particle^.dY - vdY / 5;
   406                     particle^.dY := particle^.dY - vdY / 5;
       
   407                     if splash <> nil then
       
   408                         begin
       
   409                         if splash^.Scale > 1 then 
       
   410                             begin
       
   411                             particle^.dX:= particle^.dX * power(splash^.Scale,0.3333); // tone down the droplet height further
       
   412                             particle^.dY:= particle^.dY * power(splash^.Scale, 0.3333)
       
   413                             end
       
   414                         else 
       
   415                             begin
       
   416                             particle^.dX:= particle^.dX * splash^.Scale;
       
   417                             particle^.dY:= particle^.dY * splash^.Scale
       
   418                             end
       
   419                         end
   401                     end
   420                     end
   402                 end
   421                 end
   403             end;
   422             end;
   404         if isSubmersible and (CurAmmoGear^.Pos = 0) then
   423         if isSubmersible and (CurAmmoGear^.Pos = 0) then
   405             CurAmmoGear^.Pos := 1000
   424             CurAmmoGear^.Pos := 1000