hedgewars/uGearsHandlersMess.pas
changeset 9706 5178d2263521
parent 9698 fc849dd48ae6
child 9721 1833dadcebf0
equal deleted inserted replaced
9704:055fee9da6a0 9706:5178d2263521
   284     collV, collH: LongInt;
   284     collV, collH: LongInt;
   285     land: word;
   285     land: word;
   286 begin
   286 begin
   287     tX:= Gear^.X;
   287     tX:= Gear^.X;
   288     if (Gear^.Kind <> gtGenericFaller) and WorldWrap(Gear) and (WorldEdge = weWrap) and (Gear^.AdvBounce <> 0) and
   288     if (Gear^.Kind <> gtGenericFaller) and WorldWrap(Gear) and (WorldEdge = weWrap) and (Gear^.AdvBounce <> 0) and
   289       (TestCollisionXwithGear(Gear, 1) or TestCollisionXwithGear(Gear, -1))  then
   289       ((TestCollisionXwithGear(Gear, 1) <> 0) or (TestCollisionXwithGear(Gear, -1) <> 0))  then
   290         begin
   290         begin
   291         Gear^.X:= tX;
   291         Gear^.X:= tX;
   292         Gear^.dX.isNegative:= (hwRound(tX) > leftX+Gear^.Radius*2)
   292         Gear^.dX.isNegative:= (hwRound(tX) > leftX+Gear^.Radius*2)
   293         end;
   293         end;
   294 
   294 
   355                 collV := -1
   355                 collV := -1
   356             end
   356             end
   357         end;
   357         end;
   358 
   358 
   359 
   359 
   360     if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   360     if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then
   361         begin
   361         begin
   362         collH := hwSign(Gear^.dX);
   362         collH := hwSign(Gear^.dX);
   363         Gear^.dX := - Gear^.dX * Gear^.Elasticity;
   363         Gear^.dX := - Gear^.dX * Gear^.Elasticity;
   364         Gear^.dY :=   Gear^.dY * Gear^.Elasticity;
   364         Gear^.dY :=   Gear^.dY * Gear^.Elasticity;
   365         Gear^.State := Gear^.State or gstCollision
   365         Gear^.State := Gear^.State or gstCollision
   366         end
   366         end
   367     else if (Gear^.AdvBounce=1) and TestCollisionXwithGear(Gear, -hwSign(Gear^.dX)) then
   367     else if (Gear^.AdvBounce =1) and (TestCollisionXwithGear(Gear, -hwSign(Gear^.dX)) <> 0) then
   368         collH := -hwSign(Gear^.dX);
   368         collH := -hwSign(Gear^.dX);
   369     //if Gear^.AdvBounce and (collV <>0) and (collH <> 0) and (hwSqr(tdX) + hwSqr(tdY) > _0_08) then
   369     //if Gear^.AdvBounce and (collV <>0) and (collH <> 0) and (hwSqr(tdX) + hwSqr(tdY) > _0_08) then
   370     if (Gear^.AdvBounce=1) and (collV <>0) and (collH <> 0) and ((collV=-1)
   370     if (Gear^.AdvBounce=1) and (collV <>0) and (collH <> 0) and ((collV=-1)
   371     or ((tdX.QWordValue + tdY.QWordValue) > _0_2.QWordValue)) then
   371     or ((tdX.QWordValue + tdY.QWordValue) > _0_2.QWordValue)) then
   372         begin
   372         begin
   869         end;
   869         end;
   870 
   870 
   871     AllInactive := false;
   871     AllInactive := false;
   872 
   872 
   873     if Gear^.dY.isNegative then
   873     if Gear^.dY.isNegative then
   874         if TestCollisionY(Gear, -1) then
   874         if TestCollisionY(Gear, -1) <> 0 then
   875             Gear^.dY := _0;
   875             Gear^.dY := _0;
   876 
   876 
   877     if not Gear^.dY.isNegative then
   877     if not Gear^.dY.isNegative then
   878         if TestCollisionY(Gear, 1) then
   878         if TestCollisionY(Gear, 1) <> 0 then
   879         begin
   879         begin
   880             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   880             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   881             if Gear^.dY > - _1div1024 then
   881             if Gear^.dY > - _1div1024 then
   882             begin
   882             begin
   883                 Gear^.Active := false;
   883                 Gear^.Active := false;
  1656 
  1656 
  1657 ////////////////////////////////////////////////////////////////////////////////
  1657 ////////////////////////////////////////////////////////////////////////////////
  1658 procedure doStepSMine(Gear: PGear);
  1658 procedure doStepSMine(Gear: PGear);
  1659 begin
  1659 begin
  1660     // TODO: do real calculation?
  1660     // TODO: do real calculation?
  1661     if TestCollisionXwithGear(Gear, 2)
  1661     if (TestCollisionXwithGear(Gear, 2) <> 0)
  1662     or (TestCollisionYwithGear(Gear, -2) <> 0)
  1662     or (TestCollisionYwithGear(Gear,-2) <> 0)
  1663     or TestCollisionXwithGear(Gear, -2)
  1663     or (TestCollisionXwithGear(Gear,-2) <> 0)
  1664     or (TestCollisionYwithGear(Gear, 2) <> 0) then
  1664     or (TestCollisionYwithGear(Gear, 2) <> 0) then
  1665         begin
  1665         begin
  1666         if (not isZero(Gear^.dX)) or (not isZero(Gear^.dY)) then
  1666         if (not isZero(Gear^.dX)) or (not isZero(Gear^.dY)) then
  1667             begin
  1667             begin
  1668             PlaySound(sndRopeAttach);
  1668             PlaySound(sndRopeAttach);
  2295 
  2295 
  2296     else if (Gear^.Message and gmDown) <> 0 then
  2296     else if (Gear^.Message and gmDown) <> 0 then
  2297         HHGear^.Y := HHGear^.Y + cGravity * 40;
  2297         HHGear^.Y := HHGear^.Y + cGravity * 40;
  2298 
  2298 
  2299     // don't drift into obstacles
  2299     // don't drift into obstacles
  2300     if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
  2300     if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) <> 0 then
  2301         HHGear^.X := HHGear^.X - int2hwFloat(hwSign(HHGear^.dX));
  2301         HHGear^.X := HHGear^.X - int2hwFloat(hwSign(HHGear^.dX));
  2302     HHGear^.Y := HHGear^.Y + cGravity * 100;
  2302     HHGear^.Y := HHGear^.Y + cGravity * 100;
  2303     Gear^.X := HHGear^.X;
  2303     Gear^.X := HHGear^.X;
  2304     Gear^.Y := HHGear^.Y
  2304     Gear^.Y := HHGear^.Y
  2305 end;
  2305 end;
  3075         exit
  3075         exit
  3076     end;
  3076     end;
  3077 
  3077 
  3078     tempColl:= Gear^.CollisionMask;
  3078     tempColl:= Gear^.CollisionMask;
  3079     Gear^.CollisionMask:= $007F;
  3079     Gear^.CollisionMask:= $007F;
  3080     if (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) <> 0) or TestCollisionXWithGear(Gear, hwSign(Gear^.dX)) or (GameTicks > Gear^.FlightTime) then
  3080     if (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) <> 0) or (TestCollisionXWithGear(Gear, hwSign(Gear^.dX)) <> 0) or (GameTicks > Gear^.FlightTime) then
  3081         t := CheckGearsCollision(Gear)
  3081         t := CheckGearsCollision(Gear)
  3082     else t := nil;
  3082     else t := nil;
  3083     Gear^.CollisionMask:= tempColl;
  3083     Gear^.CollisionMask:= tempColl;
  3084     //fixes drill not exploding when touching HH bug
  3084     //fixes drill not exploding when touching HH bug
  3085 
  3085 
  3086     if (Gear^.Timer = 0) or ((t <> nil) and (t^.Count <> 0))
  3086     if (Gear^.Timer = 0) or ((t <> nil) and (t^.Count <> 0))
  3087     or ( ((Gear^.State and gsttmpFlag) = 0) and (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and (not TestCollisionXWithGear(Gear, hwSign(Gear^.dX))))
  3087     or ( ((Gear^.State and gsttmpFlag) = 0) and (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and (TestCollisionXWithGear(Gear, hwSign(Gear^.dX)) = 0))
  3088 // CheckLandValue returns true if the type isn't matched
  3088 // CheckLandValue returns true if the type isn't matched
  3089     or (not CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y), lfIndestructible)) then
  3089     or (not CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y), lfIndestructible)) then
  3090         begin
  3090         begin
  3091         //out of time or exited ground
  3091         //out of time or exited ground
  3092         StopSoundChan(Gear^.SoundChannel);
  3092         StopSoundChan(Gear^.SoundChannel);
  3096             doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound);
  3096             doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound);
  3097         DeleteGear(Gear);
  3097         DeleteGear(Gear);
  3098         exit
  3098         exit
  3099         end
  3099         end
  3100 
  3100 
  3101     else if (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and (not TestCollisionXWithGear(Gear, hwSign(Gear^.dX))) then
  3101     else if (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and (TestCollisionXWithGear(Gear, hwSign(Gear^.dX)) = 0) then
  3102         begin
  3102         begin
  3103         StopSoundChan(Gear^.SoundChannel);
  3103         StopSoundChan(Gear^.SoundChannel);
  3104         Gear^.Tag := 1;
  3104         Gear^.Tag := 1;
  3105         Gear^.doStep := @doStepDrill
  3105         Gear^.doStep := @doStepDrill
  3106         end;
  3106         end;
  4041 
  4041 
  4042             if iterator^.Radius > 1 then
  4042             if iterator^.Radius > 1 then
  4043                 iterator^.Radius := iterator^.Radius - 1;
  4043                 iterator^.Radius := iterator^.Radius - 1;
  4044 
  4044 
  4045             // check front
  4045             // check front
  4046             isCollision := TestCollisionY(iterator, sy)
  4046             isCollision := (TestCollisionY(iterator, sy) <> 0) or (TestCollisionX(iterator, sx) <> 0);
  4047                         or TestCollisionX(iterator, sx);
       
  4048 
  4047 
  4049             if not isCollision then
  4048             if not isCollision then
  4050                 begin
  4049                 begin
  4051                 // check center area (with half the radius so that the
  4050                 // check center area (with half the radius so that the
  4052                 // the square check won't check more pixels than we want to)
  4051                 // the square check won't check more pixels than we want to)
  4053                 iterator^.Radius := 1 + resetr div 2;
  4052                 iterator^.Radius := 1 + resetr div 2;
  4054                 rh := resetr div 4;
  4053                 rh := resetr div 4;
  4055                 isCollision := TestCollisionYwithXYShift(iterator,       0, -sy * rh, sy, false)
  4054                 isCollision := (TestCollisionYwithXYShift(iterator,       0, -sy * rh, sy, false) <> 0)
  4056                             or TestCollisionXwithXYShift(iterator, ox * rh,        0, sx, false);
  4055                             or (TestCollisionXwithXYShift(iterator, ox * rh,        0, sx, false) <> 0);
  4057                 end;
  4056                 end;
  4058 
  4057 
  4059             iterator^.Radius := resetr;
  4058             iterator^.Radius := resetr;
  4060 
  4059 
  4061             if isCollision then
  4060             if isCollision then
  5640         end
  5639         end
  5641     else if (GameTicks and $FF = 0) then
  5640     else if (GameTicks and $FF = 0) then
  5642         begin
  5641         begin
  5643         tdX:= HHGear^.X-Gear^.X;
  5642         tdX:= HHGear^.X-Gear^.X;
  5644         dir:= hwSign(tdX);
  5643         dir:= hwSign(tdX);
  5645         if not TestCollisionX(Gear, dir) then
  5644         if TestCollisionX(Gear, dir) = 0 then
  5646             Gear^.X:= Gear^.X + signAs(_1,tdX);
  5645             Gear^.X:= Gear^.X + signAs(_1,tdX);
  5647         if TestCollisionXwithXYShift(Gear, signAs(_10,tdX), 0, dir) then
  5646         if TestCollisionXwithXYShift(Gear, signAs(_10,tdX), 0, dir) <> 0 then
  5648             begin
  5647             begin
  5649             Gear^.dX:= SignAs(_0_15, tdX);
  5648             Gear^.dX:= SignAs(_0_15, tdX);
  5650             Gear^.dY:= -_0_3;
  5649             Gear^.dY:= -_0_3;
  5651             Gear^.State:= Gear^.State or gstMoving
  5650             Gear^.State:= Gear^.State or gstMoving
  5652             end
  5651             end
  5681         end
  5680         end
  5682     else if (Gear^.CollisionIndex = -1) and (Gear^.Timer = 0) then
  5681     else if (Gear^.CollisionIndex = -1) and (Gear^.Timer = 0) then
  5683         begin
  5682         begin
  5684         (*ox:= 0; oy:= 0;
  5683         (*ox:= 0; oy:= 0;
  5685         if TestCollisionYwithGear(Gear, -1) <> 0 then oy:= -1;
  5684         if TestCollisionYwithGear(Gear, -1) <> 0 then oy:= -1;
  5686         if TestCollisionXwithGear(Gear, 1)       then ox:=  1;
  5685         if TestCollisionXwithGear(Gear, 1)  <> 0 then ox:=  1;
  5687         if TestCollisionXwithGear(Gear, -1)      then ox:= -1;
  5686         if TestCollisionXwithGear(Gear, -1) <> 0 then ox:= -1;
  5688         if TestCollisionYwithGear(Gear, 1) <> 0  then oy:=  1;
  5687         if TestCollisionYwithGear(Gear, 1)  <> 0 then oy:=  1;
  5689         if Gear^.Health > 0 then
  5688         if Gear^.Health > 0 then
  5690             PlaySound(sndRopeAttach);
  5689             PlaySound(sndRopeAttach);
  5691 
  5690 
  5692         la:= _10000;
  5691         la:= _10000;
  5693         if (ox <> 0) or (oy <> 0) then
  5692         if (ox <> 0) or (oy <> 0) then
  5712         Gear^.Timer:= 500;
  5711         Gear^.Timer:= 500;
  5713         AddCI(Gear)
  5712         AddCI(Gear)
  5714         end
  5713         end
  5715     else if GameTicks and $3F = 0 then
  5714     else if GameTicks and $3F = 0 then
  5716         begin
  5715         begin
  5717         if  (TestCollisionYwithGear(Gear, -1) = 0)
  5716         if  (TestCollisionYwithGear(Gear,-1) = 0)
  5718         and (not TestCollisionXwithGear(Gear, 1))
  5717         and (TestCollisionXwithGear(Gear, 1) = 0)
  5719         and (not TestCollisionXwithGear(Gear, -1))
  5718         and (TestCollisionXwithGear(Gear,-1) = 0)
  5720         and (TestCollisionYwithGear(Gear, 1) = 0) then Gear^.State:= Gear^.State and (not gstCollision) or gstMoving;
  5719         and (TestCollisionYwithGear(Gear, 1) = 0) then Gear^.State:= Gear^.State and (not gstCollision) or gstMoving;
  5721         end
  5720         end
  5722 end;
  5721 end;
  5723 (*
  5722 (*
  5724  This didn't end up getting used, but, who knows, might be reasonable for javellin or something
  5723  This didn't end up getting used, but, who knows, might be reasonable for javellin or something