hedgewars/uUtils.pas
changeset 12735 83d62800d215
parent 12621 d972b31f8881
child 12744 058a5d373e4a
equal deleted inserted replaced
12734:bb75ad94878b 12735:83d62800d215
    74 
    74 
    75 function  CheckNoTeamOrHH: boolean; inline;
    75 function  CheckNoTeamOrHH: boolean; inline;
    76 
    76 
    77 function  GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt;
    77 function  GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt;
    78 function  GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
    78 function  GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
       
    79 
       
    80 function CalcWorldWrap(X, radius: LongInt): LongInt;
    79 
    81 
    80 function read1stLn(filePath: shortstring): shortstring;
    82 function read1stLn(filePath: shortstring): shortstring;
    81 function readValueFromINI(key, filePath: shortstring): shortstring;
    83 function readValueFromINI(key, filePath: shortstring): shortstring;
    82 
    84 
    83 {$IFNDEF PAS2C}
    85 {$IFNDEF PAS2C}
   554         GetLaunchY:= hwRound(AngleSin(angle) * Ammoz[at].ejectY) - hwRound(AngleCos(angle) * Ammoz[at].ejectX) - 2
   556         GetLaunchY:= hwRound(AngleSin(angle) * Ammoz[at].ejectY) - hwRound(AngleCos(angle) * Ammoz[at].ejectX) - 2
   555     else
   557     else
   556         GetLaunchY:= 0*)
   558         GetLaunchY:= 0*)
   557 end;
   559 end;
   558 
   560 
       
   561 // Takes an X coordinate and corrects if according to the world edge rules
       
   562 // Wrap-around: X will be wrapped
       
   563 // Bouncy: X will be kept inside the legal land (taking radius into account)
       
   564 // Other world edges: Just returns X
       
   565 // radius is a radius (gear radius) tolerance for an appropriate distance from bouncy world edges.
       
   566 // Set radius to 0 if you don't care.
       
   567 function CalcWorldWrap(X, radius: LongInt): LongInt;
       
   568 begin
       
   569     if WorldEdge = weWrap then
       
   570         if X < LongInt(leftX) then
       
   571              X:= X + (LongInt(rightX) - LongInt(leftX))
       
   572         else if X > LongInt(rightX) then
       
   573              X:= X - (LongInt(rightX) - LongInt(leftX))
       
   574     else if WorldEdge = weBounce then
       
   575         if X - radius < LongInt(leftX) then
       
   576             X:= LongInt(leftX) + radius
       
   577         else if X + radius > LongInt(rightX) then
       
   578             X:= LongInt(rightX) - radius;
       
   579     CalcWorldWrap:= X;
       
   580 end;
       
   581 
   559 function CheckNoTeamOrHH: boolean;
   582 function CheckNoTeamOrHH: boolean;
   560 begin
   583 begin
   561 CheckNoTeamOrHH:= (CurrentTeam = nil) or (CurrentHedgehog^.Gear = nil);
   584 CheckNoTeamOrHH:= (CurrentTeam = nil) or (CurrentHedgehog^.Gear = nil);
   562 end;
   585 end;
   563 
   586