hedgewars/uGearsUtils.pas
changeset 12742 d08afea02908
parent 12740 83d62800d215
child 12748 f45ffb4cf1e1
equal deleted inserted replaced
12741:7cbb0241d31c 12742:d08afea02908
    55 
    55 
    56 function  GetAmmo(Hedgehog: PHedgehog): TAmmoType;
    56 function  GetAmmo(Hedgehog: PHedgehog): TAmmoType;
    57 function  GetUtility(Hedgehog: PHedgehog): TAmmoType;
    57 function  GetUtility(Hedgehog: PHedgehog): TAmmoType;
    58 
    58 
    59 function WorldWrap(var Gear: PGear): boolean;
    59 function WorldWrap(var Gear: PGear): boolean;
       
    60 function HomingWrap(var Gear: PGear): boolean;
    60 
    61 
    61 function IsHogLocal(HH: PHedgehog): boolean;
    62 function IsHogLocal(HH: PHedgehog): boolean;
    62 
    63 
    63 
    64 
    64 function MakeHedgehogsStep(Gear: PGear) : boolean;
    65 function MakeHedgehogsStep(Gear: PGear) : boolean;
  1626 *)
  1627 *)
  1627     WorldWrap:= true
  1628     WorldWrap:= true
  1628     end;
  1629     end;
  1629 end;
  1630 end;
  1630 
  1631 
       
  1632 (*
       
  1633 Applies wrap-around logic for the target of homing gears.
       
  1634 
       
  1635 In wrap-around world edge, the shortest way may to the target might
       
  1636 be across the border, so the X value of the target would lead the
       
  1637 gear to the wrong direction across the whole map. This procedure
       
  1638 changes the target X in this case.
       
  1639 This function must be called in the gear set-up routine and whenever
       
  1640 the gear passed through the wrap-around world edge.
       
  1641 
       
  1642 No-op for other world edges.
       
  1643 
       
  1644 Returns true if target has been changed.
       
  1645 *)
       
  1646 function HomingWrap(var Gear: PGear): boolean;
       
  1647 var dist_center, dist_right, dist_left: hwFloat;
       
  1648 begin
       
  1649     if WorldEdge = weWrap then
       
  1650         begin
       
  1651         HomingWrap:= false;
       
  1652         // We just need check the same target 3 times:
       
  1653         // 1) in current section (no change)
       
  1654         // 2) clone in the right section
       
  1655         // 3) clone in the left section
       
  1656         // The gear will go for the target with the shortest distance to the gear
       
  1657         dist_center:= Distance(Gear^.X - int2hwFloat(Gear^.Target.X), Gear^.Y - int2hwFloat(Gear^.Target.Y));
       
  1658         dist_right:= Distance(Gear^.X - int2hwFloat(Gear^.Target.X + (RightX-LeftX)), Gear^.Y - int2hwFloat(Gear^.Target.Y));
       
  1659         dist_left:= Distance(Gear^.X - int2hwFloat(Gear^.Target.X - (RightX-LeftX)), Gear^.Y - int2hwFloat(Gear^.Target.Y));
       
  1660         if (dist_left < dist_right) and (dist_left < dist_center) then
       
  1661             begin
       
  1662             dec(Gear^.Target.X, RightX-LeftX);
       
  1663             HomingWrap:= true;
       
  1664             end
       
  1665         else if (dist_right < dist_left) and (dist_right < dist_center) then
       
  1666             begin
       
  1667             inc(Gear^.Target.X, RightX-LeftX);
       
  1668             HomingWrap:= true;
       
  1669             end;
       
  1670         end;
       
  1671 end;
       
  1672 
  1631 procedure AddBounceEffectForGear(Gear: PGear);
  1673 procedure AddBounceEffectForGear(Gear: PGear);
  1632 var boing: PVisualGear;
  1674 var boing: PVisualGear;
  1633 begin
  1675 begin
  1634     boing:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot, 0, false, 1);
  1676     boing:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot, 0, false, 1);
  1635     if boing <> nil then
  1677     if boing <> nil then