hedgewars/GSHandlers.inc
changeset 5336 174734adc06b
parent 5313 5e18eaef65d0
child 5340 6963e37f2dd2
equal deleted inserted replaced
5334:ce404661aac6 5336:174734adc06b
   108 forward;
   108 forward;
   109 
   109 
   110 function CheckGearDrowning(Gear: PGear): boolean;
   110 function CheckGearDrowning(Gear: PGear): boolean;
   111 var 
   111 var 
   112     skipSpeed, skipAngle, skipDecay: hwFloat;
   112     skipSpeed, skipAngle, skipDecay: hwFloat;
   113     i, maxDrops: LongInt;
   113     i, maxDrops, X, Y: LongInt;
       
   114     vdX, vdY: real;
   114     particle: PVisualGear;
   115     particle: PVisualGear;
   115     isSubmersible: boolean;
   116     isSubmersible: boolean;
   116 begin
   117 begin
   117     isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack);
   118     isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack);
   118     // probably needs tweaking. might need to be in a case statement based upon gear type
   119     // probably needs tweaking. might need to be in a case statement based upon gear type
   119     if cWaterLine < hwRound(Gear^.Y) + Gear^.Radius then
   120     Y:= hwRound(Gear^.Y);
       
   121     if cWaterLine < Y + Gear^.Radius then
   120         begin
   122         begin
   121         skipSpeed := _0_25;
   123         skipSpeed := _0_25;
   122         skipAngle := _1_9;
   124         skipAngle := _1_9;
   123         skipDecay := _0_87;
   125         skipDecay := _0_87;
       
   126         X:= hwRound(Gear^.X);
       
   127         vdX:= hwFloat2Float(Gear^.dX);
       
   128         vdY:= hwFloat2Float(Gear^.dY);
   124         // this could perhaps be a tiny bit higher.
   129         // this could perhaps be a tiny bit higher.
   125         if  (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) and
   130         if  (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) and
   126            (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then
   131            (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then
   127             begin
   132             begin
   128             Gear^.dY.isNegative := true;
   133             Gear^.dY.isNegative := true;
   155                         begin
   160                         begin
   156                         DeleteGear(Gear);
   161                         DeleteGear(Gear);
   157                         exit
   162                         exit
   158                         end
   163                         end
   159                     else Gear^.doStep := @doStepDrowningGear
   164                     else Gear^.doStep := @doStepDrowningGear
   160             end;
   165                 end;
   161             if ((not isSubmersible) and (hwRound(Gear^.Y) < cWaterLine + 64 + Gear^.Radius)) or
   166             if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) or
   162                (isSubmersible and (hwRound(Gear^.Y) < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01))) then
   167                (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01))) then
   163                 // don't play splash if they are already way past the surface
   168                 // don't play splash if they are already way past the surface
   164                 PlaySound(sndSplash)
   169                 PlaySound(sndSplash)
   165         end;
   170             end;
   166 
   171 
   167         if ((cReducedQuality and rqPlainSplash) = 0) and 
   172         if ((cReducedQuality and rqPlainSplash) = 0) and 
   168            (((not isSubmersible) and (hwRound(Gear^.Y) < cWaterLine + 64 + Gear^.Radius)) or
   173            (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) or
   169              (isSubmersible and (hwRound(Gear^.Y) < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01)))) then
   174              (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01)))) then
   170             begin
   175             begin
   171             AddVisualGear(hwRound(Gear^.X), cWaterLine, vgtSplash);
   176             AddVisualGear(X, cWaterLine, vgtSplash);
   172 
   177 
   173             maxDrops := (Gear^.Radius div 2) + hwRound(Gear^.dX * Gear^.Radius * 2) + hwRound(Gear^.
   178             maxDrops := (Gear^.Radius div 2) + round(vdX * Gear^.Radius * 2) + round(vdY * Gear^.Radius * 2);
   174                         dY * Gear^.Radius * 2);
       
   175             for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
   179             for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
   176                 begin
   180                 begin
   177                 particle := AddVisualGear(hwRound(Gear^.X) - 3 + Random(6), cWaterLine, vgtDroplet);
   181                 particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet);
   178                 if particle <> nil then
   182                 if particle <> nil then
   179                     begin
   183                     begin
   180                     particle^.dX := particle^.dX - hwFloat2Float(Gear^.dX) / 10;
   184                     particle^.dX := particle^.dX - vdX / 10;
   181                     particle^.dY := particle^.dY - hwFloat2Float(Gear^.dY) / 5;
   185                     particle^.dY := particle^.dY - vdY / 5;
   182                     end
   186                     end
   183                 end
   187                 end
   184             end;
   188             end;
   185         if isSubmersible and (CurAmmoGear^.Pos = 0) then CurAmmoGear^.Pos := 1000
   189         if isSubmersible and (CurAmmoGear^.Pos = 0) then CurAmmoGear^.Pos := 1000
   186     end
   190         end
   187     else
   191     else
   188         CheckGearDrowning := false;
   192         CheckGearDrowning := false;
   189 end;
   193 end;
   190 
   194 
   191 procedure CheckCollision(Gear: PGear); inline;
   195 procedure CheckCollision(Gear: PGear); inline;