33 function EnumToStr(const en : TAmmoType) : shortstring; overload; |
33 function EnumToStr(const en : TAmmoType) : shortstring; overload; |
34 function EnumToStr(const en : TStatInfoType) : shortstring; overload; |
34 function EnumToStr(const en : TStatInfoType) : shortstring; overload; |
35 function EnumToStr(const en : THogEffect) : shortstring; overload; |
35 function EnumToStr(const en : THogEffect) : shortstring; overload; |
36 function EnumToStr(const en : TCapGroup) : shortstring; overload; |
36 function EnumToStr(const en : TCapGroup) : shortstring; overload; |
37 function EnumToStr(const en : TSprite) : shortstring; overload; |
37 function EnumToStr(const en : TSprite) : shortstring; overload; |
|
38 function EnumToStr(const en : TMapGen) : shortstring; overload; |
38 |
39 |
39 function Min(a, b: LongInt): LongInt; inline; |
40 function Min(a, b: LongInt): LongInt; inline; |
|
41 function MinD(a, b: double) : double; inline; |
40 function Max(a, b: LongInt): LongInt; inline; |
42 function Max(a, b: LongInt): LongInt; inline; |
41 |
43 |
42 function IntToStr(n: LongInt): shortstring; |
44 function IntToStr(n: LongInt): shortstring; |
43 function StrToInt(s: shortstring): LongInt; |
45 function StrToInt(s: shortstring): LongInt; |
44 function FloatToStr(n: hwFloat): shortstring; |
46 function FloatToStr(n: hwFloat): shortstring; |
93 |
95 |
94 implementation |
96 implementation |
95 uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils; |
97 uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils; |
96 |
98 |
97 {$IFDEF DEBUGFILE} |
99 {$IFDEF DEBUGFILE} |
98 var f: textfile; |
100 var logFile: textfile; |
99 {$IFDEF USE_VIDEO_RECORDING} |
101 {$IFDEF USE_VIDEO_RECORDING} |
100 logMutex: TRTLCriticalSection; // mutex for debug file |
102 logMutex: TRTLCriticalSection; // mutex for debug file |
101 {$ENDIF} |
103 {$ENDIF} |
102 {$ENDIF} |
104 {$ENDIF} |
103 var CharArray: array[0..255] of Char; |
105 var CharArray: array[0..255] of Char; |
183 function EnumToStr(const en: TSprite) : shortstring; overload; |
185 function EnumToStr(const en: TSprite) : shortstring; overload; |
184 begin |
186 begin |
185 EnumToStr := GetEnumName(TypeInfo(TSprite), ord(en)) |
187 EnumToStr := GetEnumName(TypeInfo(TSprite), ord(en)) |
186 end; |
188 end; |
187 |
189 |
|
190 function EnumToStr(const en: TMapGen) : shortstring; overload; |
|
191 begin |
|
192 EnumToStr := GetEnumName(TypeInfo(TMapGen), ord(en)) |
|
193 end; |
|
194 |
188 |
195 |
189 function Min(a, b: LongInt): LongInt; |
196 function Min(a, b: LongInt): LongInt; |
190 begin |
197 begin |
191 if a < b then |
198 if a < b then |
192 Min:= a |
199 Min:= a |
193 else |
200 else |
194 Min:= b |
201 Min:= b |
|
202 end; |
|
203 |
|
204 function MinD(a, b: double): double; |
|
205 begin |
|
206 if a < b then |
|
207 MinD:= a |
|
208 else |
|
209 MinD:= b |
195 end; |
210 end; |
196 |
211 |
197 function Max(a, b: LongInt): LongInt; |
212 function Max(a, b: LongInt): LongInt; |
198 begin |
213 begin |
199 if a > b then |
214 if a > b then |
278 end; |
293 end; |
279 |
294 |
280 |
295 |
281 function DecodeBase64(s: shortstring): shortstring; |
296 function DecodeBase64(s: shortstring): shortstring; |
282 const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
297 const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
283 var i, t, c: Longword; |
298 var i, t, c: LongInt; |
284 begin |
299 begin |
285 c:= 0; |
300 c:= 0; |
286 for i:= 1 to Length(s) do |
301 for i:= 1 to Length(s) do |
287 begin |
302 begin |
288 t:= Pos(s[i], table); |
303 t:= Pos(s[i], table); |
343 {$IFDEF DEBUGFILE} |
358 {$IFDEF DEBUGFILE} |
344 |
359 |
345 {$IFDEF USE_VIDEO_RECORDING} |
360 {$IFDEF USE_VIDEO_RECORDING} |
346 EnterCriticalSection(logMutex); |
361 EnterCriticalSection(logMutex); |
347 {$ENDIF} |
362 {$ENDIF} |
348 writeln(f, inttostr(GameTicks) + ': ' + s); |
363 writeln(logFile, inttostr(GameTicks) + ': ' + s); |
349 flush(f); |
364 flush(logFile); |
350 |
365 |
351 {$IFDEF USE_VIDEO_RECORDING} |
366 {$IFDEF USE_VIDEO_RECORDING} |
352 LeaveCriticalSection(logMutex); |
367 LeaveCriticalSection(logMutex); |
353 {$ENDIF} |
368 {$ENDIF} |
354 |
369 |
527 {$ENDIF} |
543 {$ENDIF} |
528 {$IFDEF USE_VIDEO_RECORDING} |
544 {$IFDEF USE_VIDEO_RECORDING} |
529 InitCriticalSection(logMutex); |
545 InitCriticalSection(logMutex); |
530 {$ENDIF} |
546 {$ENDIF} |
531 {$I-} |
547 {$I-} |
532 {$IFNDEF PAS2C} |
548 rwfailed:= false; |
533 f:= stderr; // if everything fails, write to stderr |
549 (*if (length(UserPathPrefix) > 0) then |
534 {$ENDIF} |
|
535 (* if (length(UserPathPrefix) > 0) then |
|
536 begin |
550 begin |
537 {$IFNDEF PAS2C} |
551 {$IFNDEF PAS2C} |
538 // create directory if it doesn't exist |
552 // create directory if it doesn't exist |
539 if not FileExists(UserPathPrefix + '/Logs/') then |
553 if not FileExists(UserPathPrefix + '/Logs/') then |
540 CreateDir(UserPathPrefix + '/Logs/'); |
554 CreateDir(UserPathPrefix + '/Logs/'); |
541 {$ENDIF} |
555 {$ENDIF} |
542 // if log is locked, write to the next one |
556 // if log is locked, write to the next one |
543 i:= 0; |
557 i:= 0; |
544 while(i < 7) do |
558 while(i < 7) do |
545 begin |
559 begin |
546 assign(f, shortstring(UserPathPrefix) + '/Logs/' + logfileBase + inttostr(i) + '.log'); |
560 assign(logFile, shortstring(UserPathPrefix) + '/Logs/' + logfileBase + inttostr(i) + '.log'); |
547 if IOResult = 0 then |
561 Rewrite(logFile); |
|
562 // note: IOResult is a function in pascal and a variable in pas2c |
|
563 rwfailed:= (IOResult <> 0); |
|
564 if (not rwfailed) then |
548 break; |
565 break; |
549 inc(i) |
566 inc(i) |
550 end; |
567 end; |
551 end;*) |
568 end; |
552 Rewrite(f); |
569 *) |
|
570 {$IFNDEF PAS2C} |
|
571 // if everything fails, write to stderr |
|
572 //if (length(UserPathPrefix) = 0) or (rwfailed) then |
|
573 logFile:= stderr; |
|
574 {$ENDIF} |
553 {$I+} |
575 {$I+} |
554 {$ENDIF} |
576 {$ENDIF} |
555 |
577 |
556 //mobile stuff |
578 //mobile stuff |
557 {$IFDEF IPHONEOS} |
579 {$IFDEF IPHONEOS} |