hedgewars/uGearsHandlersMess.pas
changeset 12805 6023a4f06013
parent 12804 a889cb350930
child 12806 895ef1c8f5ff
equal deleted inserted replaced
12804:a889cb350930 12805:6023a4f06013
   207     gi := GearsList;
   207     gi := GearsList;
   208     while gi <> nil do
   208     while gi <> nil do
   209         begin
   209         begin
   210         if (gi^.Kind = gtHedgehog) then
   210         if (gi^.Kind = gtHedgehog) then
   211             begin
   211             begin
   212             d := r - hwRound(PointDistance(gi^.X, x, gi^.Y, y, true));
   212             d := r - hwRound(Distance(gi^.X - x, gi^.Y - y));
   213             if (d > 1) and (gi^.Hedgehog^.Effects[heInvulnerable] = 0) and (GetRandom(2) = 0) then
   213             if (d > 1) and (gi^.Hedgehog^.Effects[heInvulnerable] = 0) and (GetRandom(2) = 0) then
   214                 begin
   214                 begin
   215                 if (CurrentHedgehog^.Gear = gi) then
   215                 if (CurrentHedgehog^.Gear = gi) then
   216                     PlaySoundV(sndOops, gi^.Hedgehog^.Team^.voicepack)
   216                     PlaySoundV(sndOops, gi^.Hedgehog^.Team^.voicepack)
   217 
   217 
  1800 end;
  1800 end;
  1801 
  1801 
  1802 procedure doStepAirMine(Gear: PGear);
  1802 procedure doStepAirMine(Gear: PGear);
  1803 var i,t,targDist,tmpDist: LongWord;
  1803 var i,t,targDist,tmpDist: LongWord;
  1804     targ, tmpG: PGear;
  1804     targ, tmpG: PGear;
  1805     trackSpeed, airFriction: hwFloat;
  1805     trackSpeed, airFriction, tX, tY: hwFloat;
  1806     isUnderwater: Boolean;
  1806     isUnderwater: Boolean;
  1807 begin
  1807 begin
  1808     isUnderwater:= CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y) + Gear^.Radius);
  1808     isUnderwater:= CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y) + Gear^.Radius);
  1809     if Gear^.Pos > 0 then
  1809     if Gear^.Pos > 0 then
  1810         begin
  1810         begin
  1827         end
  1827         end
  1828     else if Gear^.Hedgehog <> nil then
  1828     else if Gear^.Hedgehog <> nil then
  1829         targ:= Gear^.Hedgehog^.Gear;
  1829         targ:= Gear^.Hedgehog^.Gear;
  1830     if targ <> nil then
  1830     if targ <> nil then
  1831         begin
  1831         begin
       
  1832         tX:=Gear^.X-targ^.X;
       
  1833         tY:=Gear^.Y-targ^.Y;
  1832         // allow escaping - should maybe flag this too
  1834         // allow escaping - should maybe flag this too
  1833         if (GameTicks > Gear^.FlightTime+10000) or 
  1835         if (GameTicks > Gear^.FlightTime+10000) or 
  1834             (hwRound(PointDistance(Gear^.X, targ^.X, Gear^.Y, targ^.Y, true)) > Gear^.Angle*6) then
  1836             ((tX.Round+tY.Round > Gear^.Angle*6) and
       
  1837             (hwRound(hwSqr(tX) + hwSqr(tY)) > sqr(Gear^.Angle*6))) then
  1835             targ:= nil
  1838             targ:= nil
  1836         end;
  1839         end;
  1837 
  1840 
  1838     // If in ready timer, or after turn, or in first 5 seconds of turn (really a window due to extra time utility)
  1841     // If in ready timer, or after turn, or in first 5 seconds of turn (really a window due to extra time utility)
  1839     // or mine is inactive due to lack of gsttmpflag or hunting is disabled due to seek radius of 0
  1842     // or mine is inactive due to lack of gsttmpflag or hunting is disabled due to seek radius of 0
  1849         ((GameTicks and $FF) = 17) and
  1852         ((GameTicks and $FF) = 17) and
  1850         (GameTicks > Gear^.FlightTime) then // recheck hunted hog
  1853         (GameTicks > Gear^.FlightTime) then // recheck hunted hog
  1851         begin
  1854         begin
  1852         gear^.State:= gear^.State or gstChooseTarget;
  1855         gear^.State:= gear^.State or gstChooseTarget;
  1853         if targ <> nil then
  1856         if targ <> nil then
  1854              targDist:= PointDistance(Gear^.X, targ^.X, Gear^.Y, targ^.Y, true).Round
  1857              targDist:= Distance(Gear^.X-targ^.X,Gear^.Y-targ^.Y).Round
  1855         else targDist:= 0;
  1858         else targDist:= 0;
  1856         for t:= 0 to Pred(TeamsCount) do
  1859         for t:= 0 to Pred(TeamsCount) do
  1857             with TeamsArray[t]^ do
  1860             with TeamsArray[t]^ do
  1858                 for i:= 0 to cMaxHHIndex do
  1861                 for i:= 0 to cMaxHHIndex do
  1859                     if Hedgehogs[i].Gear <> nil then
  1862                     if Hedgehogs[i].Gear <> nil then
  1860                         begin
  1863                         begin
  1861                         tmpG:= Hedgehogs[i].Gear;
  1864                         tmpG:= Hedgehogs[i].Gear;
       
  1865                         tX:=Gear^.X-tmpG^.X;
       
  1866                         tY:=Gear^.Y-tmpG^.Y;
  1862                         if (Gear^.Angle = $FFFFFFFF) or
  1867                         if (Gear^.Angle = $FFFFFFFF) or
  1863                             (hwRound(PointDistance(Gear^.X, tmpG^.X, Gear^.Y, tmpG^.Y, true)) < Gear^.Angle) then
  1868                             ((tX.Round+tY.Round < Gear^.Angle) and
       
  1869                             (hwRound(hwSqr(tX) + hwSqr(tY)) < sqr(Gear^.Angle))) then
  1864                             begin
  1870                             begin
  1865                             if targ <> nil then tmpDist:= PointDistance(Gear^.X, tmpG^.X, Gear^.Y, tmpG^.Y, true).Round;
  1871                             if targ <> nil then tmpDist:= Distance(tX,tY).Round;
  1866                             if (targ = nil) or (tmpDist < targDist) then
  1872                             if (targ = nil) or (tmpDist < targDist) then
  1867                                 begin
  1873                                 begin
  1868                                 if targ = nil then targDist:= PointDistance(Gear^.X, tmpG^.X, Gear^.Y, tmpG^.Y, true).Round
  1874                                 if targ = nil then targDist:= Distance(tX,tY).Round
  1869                                 else targDist:= tmpDist;
  1875                                 else targDist:= tmpDist;
  1870                                 Gear^.Hedgehog:= @Hedgehogs[i];
  1876                                 Gear^.Hedgehog:= @Hedgehogs[i];
  1871                                 targ:= tmpG;
  1877                                 targ:= tmpG;
  1872                                 end
  1878                                 end
  1873                             end
  1879                             end
  1880         if isUnderwater then
  1886         if isUnderwater then
  1881             trackSpeed.QWordValue:= Gear^.Power div 2
  1887             trackSpeed.QWordValue:= Gear^.Power div 2
  1882         else
  1888         else
  1883             trackSpeed.QWordValue:= Gear^.Power;
  1889             trackSpeed.QWordValue:= Gear^.Power;
  1884         if (Gear^.X < targ^.X) and (Gear^.dX < _0_1)  then
  1890         if (Gear^.X < targ^.X) and (Gear^.dX < _0_1)  then
  1885             if (WorldEdge = weWrap) and ((targ^.X - Gear^.X) > ((Gear^.X - int2hwFloat(LeftX)) + (int2hwFloat(RightX) - targ^.X))) then
  1891              Gear^.dX:= Gear^.dX+trackSpeed // please leave as an add.  I like the effect
  1886                  Gear^.dX:= Gear^.dX-trackSpeed
       
  1887             else
       
  1888                  Gear^.dX:= Gear^.dX+trackSpeed // please leave as an add.  I like the effect
       
  1889         else if (Gear^.X > targ^.X) and (Gear^.dX > -_0_1) then
  1892         else if (Gear^.X > targ^.X) and (Gear^.dX > -_0_1) then
  1890             if (WorldEdge = weWrap) and ((Gear^.X - targ^.X) > ((targ^.X - int2hwFloat(LeftX)) + (int2hwFloat(RightX) - Gear^.X))) then
  1893             Gear^.dX:= Gear^.dX-trackSpeed;
  1891                 Gear^.dX:= Gear^.dX+trackSpeed
       
  1892             else
       
  1893                 Gear^.dX:= Gear^.dX-trackSpeed;
       
  1894         if (Gear^.Y < targ^.Y) and (Gear^.dY < _0_1)  then
  1894         if (Gear^.Y < targ^.Y) and (Gear^.dY < _0_1)  then
  1895              Gear^.dY:= Gear^.dY+trackSpeed
  1895              Gear^.dY:= Gear^.dY+trackSpeed
  1896         else if (Gear^.Y > targ^.Y) and (Gear^.dY > -_0_1) then
  1896         else if (Gear^.Y > targ^.Y) and (Gear^.dY > -_0_1) then
  1897             Gear^.dY:= Gear^.dY-trackSpeed
  1897             Gear^.dY:= Gear^.dY-trackSpeed
  1898         end
  1898         end
  1904             begin
  1904             begin
  1905             if ((GameTicks and $1F) = 0) then
  1905             if ((GameTicks and $1F) = 0) then
  1906                 begin
  1906                 begin
  1907                 if targ <> nil then
  1907                 if targ <> nil then
  1908                     begin
  1908                     begin
  1909                     if (hwRound(PointDistance(Gear^.X, targ^.X, Gear^.Y, targ^.Y, true)) < Gear^.Karma) then
  1909                     tX:=Gear^.X-targ^.X;
       
  1910                     tY:=Gear^.Y-targ^.Y;
       
  1911                     if (tX.Round+tY.Round < Gear^.Karma) and
       
  1912                        (hwRound(hwSqr(tX) + hwSqr(tY)) < sqr(Gear^.Karma)) then
  1910                     Gear^.State := Gear^.State or gstAttacking
  1913                     Gear^.State := Gear^.State or gstAttacking
  1911                     end
  1914                     end
  1912                 else if (Gear^.Angle > 0) and (CheckGearNear(Gear, gtHedgehog, Gear^.Karma, Gear^.Karma) <> nil) then
  1915                 else if (Gear^.Angle > 0) and (CheckGearNear(Gear, gtHedgehog, Gear^.Karma, Gear^.Karma) <> nil) then
  1913                     Gear^.State := Gear^.State or gstAttacking
  1916                     Gear^.State := Gear^.State or gstAttacking
  1914                 end
  1917                 end
  1921             if Gear^.Timer = 0 then
  1924             if Gear^.Timer = 0 then
  1922                 begin
  1925                 begin
  1923                 // recheck
  1926                 // recheck
  1924                 if targ <> nil then
  1927                 if targ <> nil then
  1925                     begin
  1928                     begin
  1926                     if (hwRound(PointDistance(Gear^.X, targ^.X, Gear^.Y, targ^.Y, true)) < Gear^.Karma) then
  1929                     tX:=Gear^.X-targ^.X;
       
  1930                     tY:=Gear^.Y-targ^.Y;
       
  1931                     if (tX.Round+tY.Round < Gear^.Karma) and
       
  1932                        (hwRound(hwSqr(tX) + hwSqr(tY)) < sqr(Gear^.Karma)) then
  1927                         begin
  1933                         begin
  1928                         Gear^.Hedgehog:= CurrentHedgehog;
  1934                         Gear^.Hedgehog:= CurrentHedgehog;
  1929                         tmpG:= FollowGear;
  1935                         tmpG:= FollowGear;
  1930                         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Karma, Gear^.Hedgehog, EXPLAutoSound);
  1936                         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Karma, Gear^.Hedgehog, EXPLAutoSound);
  1931                         FollowGear:= tmpG;
  1937                         FollowGear:= tmpG;