hedgewars/uUtils.pas
changeset 6894 555a8d8db228
parent 6700 e04da46ee43c
child 6978 1dc33050149d
equal deleted inserted replaced
6893:69cc0166be8d 6894:555a8d8db228
    24 uses uTypes, uFloat, GLunit;
    24 uses uTypes, uFloat, GLunit;
    25 
    25 
    26 procedure SplitBySpace(var a, b: shortstring);
    26 procedure SplitBySpace(var a, b: shortstring);
    27 procedure SplitByChar(var a, b: ansistring; c: char);
    27 procedure SplitByChar(var a, b: ansistring; c: char);
    28 
    28 
       
    29 {$IFNDEF PAS2C}
    29 function  EnumToStr(const en : TGearType) : shortstring; overload;
    30 function  EnumToStr(const en : TGearType) : shortstring; overload;
    30 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
    31 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
    31 function  EnumToStr(const en : TSound) : shortstring; overload;
    32 function  EnumToStr(const en : TSound) : shortstring; overload;
    32 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
    33 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
    33 function  EnumToStr(const en : THogEffect) : shortstring; overload;
    34 function  EnumToStr(const en : THogEffect) : shortstring; overload;
    34 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
    35 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
       
    36 {$ENDIF}
    35 
    37 
    36 function  Min(a, b: LongInt): LongInt; inline;
    38 function  Min(a, b: LongInt): LongInt; inline;
    37 function  Max(a, b: LongInt): LongInt; inline;
    39 function  Max(a, b: LongInt): LongInt; inline;
    38 
    40 
    39 function  IntToStr(n: LongInt): shortstring;
    41 function  IntToStr(n: LongInt): shortstring;
    40 function  FloatToStr(n: hwFloat): shortstring;
    42 function  FloatToStr(n: hwFloat): shortstring;
    41 
    43 
    42 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
    44 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
    43 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
    45 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
    44 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
    46 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
    45 function  DxDy2AttackAngle(const _dY, _dX: extended): LongInt;
    47 function  DxDy2AttackAnglef(const _dY, _dX: extended): LongInt;
    46 
    48 
    47 procedure SetLittle(var r: hwFloat);
    49 procedure SetLittle(var r: hwFloat);
    48 
    50 
    49 function  Str2PChar(const s: shortstring): PChar;
    51 function  Str2PChar(const s: shortstring): PChar;
    50 function  DecodeBase64(s: shortstring): shortstring;
    52 function  DecodeBase64(s: shortstring): shortstring;
   100     b:= copy(a, i + 1, Length(a) - i);
   102     b:= copy(a, i + 1, Length(a) - i);
   101     setlength(a, Pred(i));
   103     setlength(a, Pred(i));
   102     end else b:= '';
   104     end else b:= '';
   103 end;
   105 end;
   104 
   106 
       
   107 {$IFNDEF PAS2C}
   105 function EnumToStr(const en : TGearType) : shortstring; overload;
   108 function EnumToStr(const en : TGearType) : shortstring; overload;
   106 begin
   109 begin
   107 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
   110 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
   108 end;
   111 end;
   109 function EnumToStr(const en : TVisualGearType) : shortstring; overload;
   112 function EnumToStr(const en : TVisualGearType) : shortstring; overload;
   128 
   131 
   129 function EnumToStr(const en: TCapGroup) : shortstring; overload;
   132 function EnumToStr(const en: TCapGroup) : shortstring; overload;
   130 begin
   133 begin
   131 EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en))
   134 EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en))
   132 end;
   135 end;
   133 
   136 {$ENDIF}
   134 
   137 
   135 function Min(a, b: LongInt): LongInt;
   138 function Min(a, b: LongInt): LongInt;
   136 begin
   139 begin
   137 if a < b then
   140 if a < b then
   138     Min:= a
   141     Min:= a
   196 if _dX.isNegative then
   199 if _dX.isNegative then
   197     dX:= - dX;
   200     dX:= - dX;
   198 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   201 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   199 end;
   202 end;
   200 
   203 
   201 function DxDy2AttackAngle(const _dY, _dX: extended): LongInt; inline;
   204 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
   202 begin
   205 begin
   203 DxDy2AttackAngle:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
   206 DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
   204 end;
   207 end;
   205 
   208 
   206 
   209 
   207 procedure SetLittle(var r: hwFloat);
   210 procedure SetLittle(var r: hwFloat);
   208 begin
   211 begin