hedgewars/uGearsUtils.pas
changeset 12804 a889cb350930
parent 12743 f45ffb4cf1e1
child 12898 8a40ce061d94
equal deleted inserted replaced
12803:e3d18c92c332 12804:a889cb350930
    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;
       
    61 
    60 
    62 function IsHogLocal(HH: PHedgehog): boolean;
    61 function IsHogLocal(HH: PHedgehog): boolean;
    63 
    62 
    64 
    63 
    65 function MakeHedgehogsStep(Gear: PGear) : boolean;
    64 function MakeHedgehogsStep(Gear: PGear) : boolean;
  1638 *)
  1637 *)
  1639     WorldWrap:= true
  1638     WorldWrap:= true
  1640     end;
  1639     end;
  1641 end;
  1640 end;
  1642 
  1641 
  1643 (*
       
  1644 Applies wrap-around logic for the target of homing gears.
       
  1645 
       
  1646 In wrap-around world edge, the shortest way may to the target might
       
  1647 be across the border, so the X value of the target would lead the
       
  1648 gear to the wrong direction across the whole map. This procedure
       
  1649 changes the target X in this case.
       
  1650 This function must be called in the gear set-up routine and whenever
       
  1651 the gear passed through the wrap-around world edge.
       
  1652 
       
  1653 No-op for other world edges.
       
  1654 
       
  1655 Returns true if target has been changed.
       
  1656 *)
       
  1657 function HomingWrap(var Gear: PGear): boolean;
       
  1658 var dist_center, dist_right, dist_left: hwFloat;
       
  1659 begin
       
  1660     if WorldEdge = weWrap then
       
  1661         begin
       
  1662         HomingWrap:= false;
       
  1663         // We just need check the same target 3 times:
       
  1664         // 1) in current section (no change)
       
  1665         // 2) clone in the right section
       
  1666         // 3) clone in the left section
       
  1667         // The gear will go for the target with the shortest distance to the gear
       
  1668         dist_center:= Distance(Gear^.X - int2hwFloat(Gear^.Target.X), Gear^.Y - int2hwFloat(Gear^.Target.Y));
       
  1669         dist_right:= Distance(Gear^.X - int2hwFloat(Gear^.Target.X + (RightX-LeftX)), Gear^.Y - int2hwFloat(Gear^.Target.Y));
       
  1670         dist_left:= Distance(Gear^.X - int2hwFloat(Gear^.Target.X - (RightX-LeftX)), Gear^.Y - int2hwFloat(Gear^.Target.Y));
       
  1671         if (dist_left < dist_right) and (dist_left < dist_center) then
       
  1672             begin
       
  1673             dec(Gear^.Target.X, RightX-LeftX);
       
  1674             HomingWrap:= true;
       
  1675             end
       
  1676         else if (dist_right < dist_left) and (dist_right < dist_center) then
       
  1677             begin
       
  1678             inc(Gear^.Target.X, RightX-LeftX);
       
  1679             HomingWrap:= true;
       
  1680             end;
       
  1681         end;
       
  1682 end;
       
  1683 
       
  1684 procedure AddBounceEffectForGear(Gear: PGear);
  1642 procedure AddBounceEffectForGear(Gear: PGear);
  1685 var boing: PVisualGear;
  1643 var boing: PVisualGear;
  1686 begin
  1644 begin
  1687     boing:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot, 0, false, 1);
  1645     boing:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot, 0, false, 1);
  1688     if boing <> nil then
  1646     if boing <> nil then