hedgewars/uGearsUtils.pas
changeset 14514 5ac181cb2396
parent 14337 94e50f346c57
child 14534 c38dd843763f
equal deleted inserted replaced
14513:5230c063214a 14514:5ac181cb2396
    62 
    62 
    63 function  GetAmmo(Hedgehog: PHedgehog): TAmmoType;
    63 function  GetAmmo(Hedgehog: PHedgehog): TAmmoType;
    64 function  GetUtility(Hedgehog: PHedgehog): TAmmoType;
    64 function  GetUtility(Hedgehog: PHedgehog): TAmmoType;
    65 
    65 
    66 function WorldWrap(var Gear: PGear): boolean;
    66 function WorldWrap(var Gear: PGear): boolean;
       
    67 function HomingWrap(var Gear: PGear): boolean;
    67 
    68 
    68 function IsHogLocal(HH: PHedgehog): boolean;
    69 function IsHogLocal(HH: PHedgehog): boolean;
    69 
    70 
    70 
    71 
    71 function MakeHedgehogsStep(Gear: PGear) : boolean;
    72 function MakeHedgehogsStep(Gear: PGear) : boolean;
  1807 *)
  1808 *)
  1808     WorldWrap:= true
  1809     WorldWrap:= true
  1809     end;
  1810     end;
  1810 end;
  1811 end;
  1811 
  1812 
       
  1813 (*
       
  1814 Applies wrap-around logic for the target of homing gears.
       
  1815 
       
  1816 In wrap-around world edge, the shortest way may to the target might
       
  1817 be across the border, so the X value of the target would lead the
       
  1818 gear to the wrong direction across the whole map. This procedure
       
  1819 changes the target X in this case.
       
  1820 This function must be called after the gear passed through
       
  1821 the wrap-around world edge (WorldWrap returned true).
       
  1822 
       
  1823 No-op for other world edges.
       
  1824 
       
  1825 Returns true if target has been changed.
       
  1826 *)
       
  1827 function HomingWrap(var Gear: PGear): boolean;
       
  1828 var dist_center, dist_right, dist_left: hwFloat;
       
  1829 begin
       
  1830     if WorldEdge = weWrap then
       
  1831         begin
       
  1832         HomingWrap:= false;
       
  1833         // We just check the same target 3 times:
       
  1834         // 1) in current section (no change)
       
  1835         // 2) clone in the right section
       
  1836         // 3) clone in the left section
       
  1837         // The gear will go for the target with the shortest distance to the gear.
       
  1838         // For simplicity, we only check distance on the X axis.
       
  1839         dist_center:= hwAbs(Gear^.X - int2hwFloat(Gear^.Target.X));
       
  1840         dist_right:= hwAbs(Gear^.X - int2hwFloat(Gear^.Target.X + (RightX-LeftX)));
       
  1841         dist_left:= hwAbs(Gear^.X - int2hwFloat(Gear^.Target.X - (RightX-LeftX)));
       
  1842         if (dist_left < dist_right) and (dist_left < dist_center) then
       
  1843             begin
       
  1844             dec(Gear^.Target.X, RightX-LeftX);
       
  1845             HomingWrap:= true;
       
  1846             end
       
  1847         else if (dist_right < dist_left) and (dist_right < dist_center) then
       
  1848             begin
       
  1849             inc(Gear^.Target.X, RightX-LeftX);
       
  1850             HomingWrap:= true;
       
  1851             end;
       
  1852         end;
       
  1853 end;
  1812 
  1854 
  1813 // Add an audiovisual bounce effect for gear after it bounced from bouncy material.
  1855 // Add an audiovisual bounce effect for gear after it bounced from bouncy material.
  1814 // Graphical effect is based on speed.
  1856 // Graphical effect is based on speed.
  1815 procedure AddBounceEffectForGear(Gear: PGear);
  1857 procedure AddBounceEffectForGear(Gear: PGear);
  1816 begin
  1858 begin