hedgewars/uUtils.pas
changeset 8838 aa2ffd427f6a
parent 8575 228fbb2a76a4
child 8847 ff7fbab7cd56
child 9080 9b42757d7e71
equal deleted inserted replaced
8835:01bcf9ea68c1 8838:aa2ffd427f6a
    25 
    25 
    26 procedure SplitBySpace(var a, b: shortstring);
    26 procedure SplitBySpace(var a, b: shortstring);
    27 procedure SplitByChar(var a, b: shortstring; c: char);
    27 procedure SplitByChar(var a, b: shortstring; c: char);
    28 procedure SplitByChar(var a, b: ansistring; c: char);
    28 procedure SplitByChar(var a, b: ansistring; c: char);
    29 
    29 
    30 {$IFNDEF PAS2C}
       
    31 function  EnumToStr(const en : TGearType) : shortstring; overload;
    30 function  EnumToStr(const en : TGearType) : shortstring; overload;
    32 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
    31 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
    33 function  EnumToStr(const en : TSound) : shortstring; overload;
    32 function  EnumToStr(const en : TSound) : shortstring; overload;
    34 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
    33 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
    35 function  EnumToStr(const en : THogEffect) : shortstring; overload;
    34 function  EnumToStr(const en : THogEffect) : shortstring; overload;
    36 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
    35 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
    37 {$ENDIF}
       
    38 
    36 
    39 function  Min(a, b: LongInt): LongInt; inline;
    37 function  Min(a, b: LongInt): LongInt; inline;
    40 function  Max(a, b: LongInt): LongInt; inline;
    38 function  Max(a, b: LongInt): LongInt; inline;
    41 
    39 
    42 function  IntToStr(n: LongInt): shortstring;
    40 function  IntToStr(n: LongInt): shortstring;
    66 function  CheckNoTeamOrHH: boolean; inline;
    64 function  CheckNoTeamOrHH: boolean; inline;
    67 
    65 
    68 function  GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt;
    66 function  GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt;
    69 function  GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
    67 function  GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
    70 
    68 
    71 {$IFNDEF PAS2C}
       
    72 procedure Write(var f: textfile; s: shortstring);
    69 procedure Write(var f: textfile; s: shortstring);
    73 procedure WriteLn(var f: textfile; s: shortstring);
    70 procedure WriteLn(var f: textfile; s: shortstring);
    74 {$ENDIF}
       
    75 
    71 
    76 function  isPhone: Boolean; inline;
    72 function  isPhone: Boolean; inline;
    77 function  getScreenDPI: Double; inline; //cdecl; external;
    73 function  getScreenDPI: Double; inline; //cdecl; external;
    78 
    74 
    79 {$IFDEF IPHONEOS}
    75 {$IFDEF IPHONEOS}
    90 procedure initModule(isNotPreview: boolean);
    86 procedure initModule(isNotPreview: boolean);
    91 procedure freeModule;
    87 procedure freeModule;
    92 
    88 
    93 
    89 
    94 implementation
    90 implementation
    95 uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils;
    91 uses typinfo, Math, uConsts, uVariables, SysUtils;
    96 
    92 
    97 {$IFDEF DEBUGFILE}
    93 {$IFDEF DEBUGFILE}
    98 var f: textfile;
    94 var f: textfile;
    99 {$IFDEF USE_VIDEO_RECORDING}
    95 {$IFDEF USE_VIDEO_RECORDING}
   100     logMutex: TRTLCriticalSection; // mutex for debug file
    96     logMutex: TRTLCriticalSection; // mutex for debug file
   133     b:= copy(a, i + 1, Length(a) - i);
   129     b:= copy(a, i + 1, Length(a) - i);
   134     setlength(a, Pred(i));
   130     setlength(a, Pred(i));
   135     end else b:= '';
   131     end else b:= '';
   136 end;
   132 end;
   137 
   133 
   138 {$IFNDEF PAS2C}
       
   139 function EnumToStr(const en : TGearType) : shortstring; overload;
   134 function EnumToStr(const en : TGearType) : shortstring; overload;
   140 begin
   135 begin
   141 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
   136 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
   142 end;
   137 end;
       
   138 
   143 function EnumToStr(const en : TVisualGearType) : shortstring; overload;
   139 function EnumToStr(const en : TVisualGearType) : shortstring; overload;
   144 begin
   140 begin
   145 EnumToStr:= GetEnumName(TypeInfo(TVisualGearType), ord(en))
   141 EnumToStr:= GetEnumName(TypeInfo(TVisualGearType), ord(en))
   146 end;
   142 end;
   147 
   143 
   162 
   158 
   163 function EnumToStr(const en: TCapGroup) : shortstring; overload;
   159 function EnumToStr(const en: TCapGroup) : shortstring; overload;
   164 begin
   160 begin
   165 EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en))
   161 EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en))
   166 end;
   162 end;
   167 {$ENDIF}
   163 
   168 
   164 
   169 function Min(a, b: LongInt): LongInt;
   165 function Min(a, b: LongInt): LongInt;
   170 begin
   166 begin
   171 if a < b then
   167 if a < b then
   172     Min:= a
   168     Min:= a
   405 function CheckNoTeamOrHH: boolean;
   401 function CheckNoTeamOrHH: boolean;
   406 begin
   402 begin
   407 CheckNoTeamOrHH:= (CurrentTeam = nil) or (CurrentHedgehog^.Gear = nil);
   403 CheckNoTeamOrHH:= (CurrentTeam = nil) or (CurrentHedgehog^.Gear = nil);
   408 end;
   404 end;
   409 
   405 
   410 {$IFNDEF PAS2C}
       
   411 procedure Write(var f: textfile; s: shortstring);
   406 procedure Write(var f: textfile; s: shortstring);
   412 begin
   407 begin
   413 system.write(f, s)
   408 system.write(f, s)
   414 end;
   409 end;
   415 
   410 
   416 procedure WriteLn(var f: textfile; s: shortstring);
   411 procedure WriteLn(var f: textfile; s: shortstring);
   417 begin
   412 begin
   418 system.writeln(f, s)
   413 system.writeln(f, s)
   419 end;
   414 end;
   420 {$ENDIF}
   415 
   421 
   416 
   422 // this function is just to determine whether we are running on a limited screen device
   417 // this function is just to determine whether we are running on a limited screen device
   423 function isPhone: Boolean; inline;
   418 function isPhone: Boolean; inline;
   424 begin
   419 begin
   425     isPhone:= false;
   420     isPhone:= false;