41 |
41 |
42 function IntToStr(n: LongInt): shortstring; |
42 function IntToStr(n: LongInt): shortstring; |
43 function StrToInt(s: shortstring): LongInt; |
43 function StrToInt(s: shortstring): LongInt; |
44 function FloatToStr(n: hwFloat): shortstring; |
44 function FloatToStr(n: hwFloat): shortstring; |
45 |
45 |
46 function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
46 function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; inline; |
47 function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
47 function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
48 function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
48 function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
49 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; |
49 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; |
50 |
50 |
51 procedure SetLittle(var r: hwFloat); |
51 procedure SetLittle(var r: hwFloat); |
59 function endian(independent: LongWord): LongWord; inline; |
59 function endian(independent: LongWord): LongWord; inline; |
60 |
60 |
61 function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
61 function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
62 |
62 |
63 procedure AddFileLog(s: shortstring); |
63 procedure AddFileLog(s: shortstring); |
|
64 procedure AddFileLogRaw(s: pchar); cdecl; |
64 |
65 |
65 function CheckNoTeamOrHH: boolean; inline; |
66 function CheckNoTeamOrHH: boolean; inline; |
66 |
67 |
67 function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt; |
68 function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt; |
68 function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt; |
69 function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt; |
79 implementation |
80 implementation |
80 uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils; |
81 uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils; |
81 |
82 |
82 {$IFDEF DEBUGFILE} |
83 {$IFDEF DEBUGFILE} |
83 var f: textfile; |
84 var f: textfile; |
|
85 {$IFDEF USE_VIDEO_RECORDING} |
|
86 logMutex: TRTLCriticalSection; // mutex for debug file |
|
87 {$ENDIF} |
84 {$ENDIF} |
88 {$ENDIF} |
85 var CharArray: array[byte] of Char; |
89 var CharArray: array[byte] of Char; |
86 |
90 |
87 procedure SplitBySpace(var a,b: shortstring); |
91 procedure SplitBySpace(var a,b: shortstring); |
88 begin |
92 begin |
180 begin |
184 begin |
181 FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
185 FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
182 end; |
186 end; |
183 |
187 |
184 |
188 |
185 function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
189 function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; inline; |
186 var dY, dX: Extended; |
190 var dY, dX: Extended; |
187 begin |
191 begin |
188 dY:= _dY.QWordValue / $100000000; |
192 dY:= hwFloat2Float(_dY); |
189 if _dY.isNegative then |
193 dX:= hwFloat2Float(_dX); |
190 dY:= - dY; |
|
191 dX:= _dX.QWordValue / $100000000; |
|
192 if _dX.isNegative then |
|
193 dX:= - dX; |
|
194 DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
194 DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
195 end; |
195 end; |
196 |
196 |
197 function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
197 function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
198 const _16divPI: Extended = 16/pi; |
198 const _16divPI: Extended = 16/pi; |
199 var dY, dX: Extended; |
199 var dY, dX: Extended; |
200 begin |
200 begin |
201 dY:= _dY.QWordValue / $100000000; |
201 dY:= hwFloat2Float(_dY); |
202 if _dY.isNegative then |
202 dX:= hwFloat2Float(_dX); |
203 dY:= - dY; |
|
204 dX:= _dX.QWordValue / $100000000; |
|
205 if _dX.isNegative then |
|
206 dX:= - dX; |
|
207 DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
203 DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
208 end; |
204 end; |
209 |
205 |
210 function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
206 function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
211 const MaxAngleDivPI: Extended = cMaxAngle/pi; |
207 const MaxAngleDivPI: Extended = cMaxAngle/pi; |
212 var dY, dX: Extended; |
208 var dY, dX: Extended; |
213 begin |
209 begin |
214 dY:= _dY.QWordValue / $100000000; |
210 dY:= hwFloat2Float(_dY); |
215 if _dY.isNegative then |
211 dX:= hwFloat2Float(_dX); |
216 dY:= - dY; |
|
217 dX:= _dX.QWordValue / $100000000; |
|
218 if _dX.isNegative then |
|
219 dX:= - dX; |
|
220 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
212 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
221 end; |
213 end; |
222 |
214 |
223 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline; |
215 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline; |
224 begin |
216 begin |
301 |
293 |
302 procedure AddFileLog(s: shortstring); |
294 procedure AddFileLog(s: shortstring); |
303 begin |
295 begin |
304 s:= s; |
296 s:= s; |
305 {$IFDEF DEBUGFILE} |
297 {$IFDEF DEBUGFILE} |
|
298 {$IFDEF USE_VIDEO_RECORDING} |
|
299 EnterCriticalSection(logMutex); |
|
300 {$ENDIF} |
306 writeln(f, inttostr(GameTicks) + ': ' + s); |
301 writeln(f, inttostr(GameTicks) + ': ' + s); |
307 flush(f) |
302 flush(f); |
308 {$ENDIF} |
303 {$IFDEF USE_VIDEO_RECORDING} |
309 end; |
304 LeaveCriticalSection(logMutex); |
310 |
305 {$ENDIF} |
|
306 {$ENDIF} |
|
307 end; |
|
308 |
|
309 procedure AddFileLogRaw(s: pchar); cdecl; |
|
310 begin |
|
311 s:= s; |
|
312 {$IFDEF DEBUGFILE} |
|
313 {$IFDEF USE_VIDEO_RECORDING} |
|
314 EnterCriticalSection(logMutex); |
|
315 {$ENDIF} |
|
316 write(f, s); |
|
317 flush(f); |
|
318 {$IFDEF USE_VIDEO_RECORDING} |
|
319 LeaveCriticalSection(logMutex); |
|
320 {$ENDIF} |
|
321 {$ENDIF} |
|
322 end; |
311 |
323 |
312 function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
324 function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
313 var l, i : LongInt; |
325 var l, i : LongInt; |
314 u: WideChar; |
326 u: WideChar; |
315 tmpstr: array[0..256] of WideChar; |
327 tmpstr: array[0..256] of WideChar; |
395 {$IFNDEF MOBILE}var i: LongInt;{$ENDIF} |
407 {$IFNDEF MOBILE}var i: LongInt;{$ENDIF} |
396 {$ENDIF} |
408 {$ENDIF} |
397 begin |
409 begin |
398 {$IFDEF DEBUGFILE} |
410 {$IFDEF DEBUGFILE} |
399 if isGame then |
411 if isGame then |
400 logfileBase:= 'game' |
412 begin |
|
413 if GameType = gmtRecord then |
|
414 logfileBase:= 'rec' |
|
415 else |
|
416 logfileBase:= 'game'; |
|
417 end |
401 else |
418 else |
402 logfileBase:= 'preview'; |
419 logfileBase:= 'preview'; |
|
420 {$IFDEF USE_VIDEO_RECORDING} |
|
421 InitCriticalSection(logMutex); |
|
422 {$ENDIF} |
403 {$I-} |
423 {$I-} |
404 {$IFDEF MOBILE} |
424 {$IFDEF MOBILE} |
405 {$IFDEF IPHONEOS} Assign(f,'../Documents/hw-' + logfileBase + '.log'); {$ENDIF} |
425 {$IFDEF IPHONEOS} Assign(f,'../Documents/hw-' + logfileBase + '.log'); {$ENDIF} |
406 {$IFDEF ANDROID} Assign(f,pathPrefix + '/' + logfileBase + '.log'); {$ENDIF} |
426 {$IFDEF ANDROID} Assign(f,pathPrefix + '/' + logfileBase + '.log'); {$ENDIF} |
407 Rewrite(f); |
427 Rewrite(f); |