3 {$INCLUDE ../shared/a_modes.inc}
8 LCLIntf
, LCLType
, LMessages
;
11 String16
= String[16];
12 Char16
= packed array[0..15] of Char;
13 Char32
= packed array[0..31] of Char;
14 Char64
= packed array[0..63] of Char;
15 Char256
= packed array[0..255] of Char;
16 ArrayStr16
= Array of String16
;
17 SArray
= Array of String;
18 DWArray
= Array of DWORD
;
20 TDirection
= (D_LEFT
, D_RIGHT
);
22 function g_Collide(X1
, Y1
: Integer; Width1
, Height1
: Word;
23 X2
, Y2
: Integer; Width2
, Height2
: Word): Boolean;
24 function g_CollidePoint(X
, Y
, X2
, Y2
: Integer; Width
, Height
: Word): Boolean;
25 function g_CollideLevel(X
, Y
: Integer; Width
, Height
: Word): Boolean;
26 function g_CollideLevel2(X
, Y
: Integer; Width
, Height
: Word; _ID
: DWORD
; var PanelID
: DWORD
): Boolean;
27 function g_PatchLength(X1
, Y1
, X2
, Y2
: Integer): Word;
28 procedure IncMax(var A
: Integer; B
, Max
: Integer); overload
;
29 procedure IncMax(var A
: Single; B
, Max
: Single); overload
;
30 procedure IncMax(var A
: Integer; Max
: Integer); overload
;
31 procedure IncMax(var A
: Single; Max
: Single); overload
;
32 procedure IncMax(var A
: Word; B
, Max
: Word); overload
;
33 procedure IncMax(var A
: Word; Max
: Word); overload
;
34 procedure IncMax(var A
: SmallInt; B
, Max
: SmallInt); overload
;
35 procedure IncMax(var A
: SmallInt; Max
: SmallInt); overload
;
36 procedure DecMin(var A
: Integer; B
, Min
: Integer); overload
;
37 procedure DecMin(var A
: Single; B
, Min
: Single); overload
;
38 procedure DecMin(var A
: Integer; Min
: Integer); overload
;
39 procedure DecMin(var A
: Single; Min
: Single); overload
;
40 procedure DecMin(var A
: Word; B
, Min
: Word); overload
;
41 procedure DecMin(var A
: Word; Min
: Word); overload
;
42 procedure DecMin(var A
: Byte; B
, Min
: Byte); overload
;
43 procedure DecMin(var A
: Byte; Min
: Byte); overload
;
44 function Sign(A
: Integer): ShortInt; overload
;
45 function Sign(A
: Single): ShortInt; overload
;
46 function PointToRect(X
, Y
: Integer; X1
, Y1
, Width
, Height
: Integer): Integer;
47 procedure g_ChangeDir(var dir
: TDirection
);
48 function g_GetFileTime(fileName
: String): Integer;
49 function g_SetFileTime(fileName
: String; time
: Integer): Boolean;
54 Math
, g_map
, MAPDEF
, SysUtils
;
56 procedure g_ChangeDir(var dir
: TDirection
);
64 function g_GetFileTime(fileName
: String): Integer;
69 if not FileExists(fileName
) then
75 AssignFile(F
, fileName
);
77 Result
:= FileGetDate(TFileRec(F
).Handle
);
81 function g_SetFileTime(fileName
: String; time
: Integer): Boolean;
86 if (not FileExists(fileName
)) or (time
< 0) then
92 AssignFile(F
, fileName
);
94 Result
:= (FileSetDate(TFileRec(F
).Handle
, time
) = 0);
98 function g_PatchLength(X1
, Y1
, X2
, Y2
: Integer): Word;
100 Result
:= Trunc(Hypot(Abs(X2
-X1
), Abs(Y2
-Y1
)));
103 function g_CollideLevel(X
, Y
: Integer; Width
, Height
: Word): Boolean;
110 if gPanels
= nil then Exit
;
112 for a
:= 0 to High(gPanels
) do
113 if gPanels
[a
].PanelType
= PANEL_WALL
then
114 if not (((Y
+ Height
<= gPanels
[a
].Y
) or
115 (Y
>= gPanels
[a
].Y
+ gPanels
[a
].Height
)) or
116 ((X
+ Width
<= gPanels
[a
].X
) or
117 (X
>= gPanels
[a
].X
+ gPanels
[a
].Width
))) then
124 {function g_CollideLevel2(X, Y, X2, Y2: Integer): Boolean;
130 if gWalls = nil then Exit;
132 for a := 0 to High(gWalls) do
133 if not (((Y2 <= gWalls[a].Y) or
134 (Y >= gWalls[a].Y + gWalls[a].Height)) or
135 ((X2 <= gWalls[a].X) or
136 (X >= gWalls[a].X + gWalls[a].Width))) then
143 function g_CollideLevel2(X
, Y
: Integer; Width
, Height
: Word; _ID
: DWORD
; var PanelID
: DWORD
): Boolean;
149 if gPanels
= nil then Exit
;
151 for a
:= 0 to High(gPanels
) do
152 if (gPanels
[a
].PanelType
= PANEL_WALL
) and (_ID
<> a
) then
153 if not (((Y
+ Height
<= gPanels
[a
].Y
) or
154 (Y
>= gPanels
[a
].Y
+ gPanels
[a
].Height
)) or
155 ((X
+ Width
<= gPanels
[a
].X
) or
156 (X
>= gPanels
[a
].X
+ gPanels
[a
].Width
))) then
164 function g_Collide(X1
, Y1
: Integer; Width1
, Height1
: Word;
165 X2
, Y2
: Integer; Width2
, Height2
: Word): Boolean;
167 Result
:= not (((Y1
+ Height1
<= Y2
) or
168 (Y1
>= Y2
+ Height2
)) or
169 ((X1
+ Width1
<= X2
) or
170 (X1
>= X2
+ Width2
)));
173 function g_CollidePoint(X
, Y
, X2
, Y2
: Integer; Width
, Height
: Word): Boolean;
177 Result := (x >= 0) and (x <= Width) and
178 (y >= 0) and (y <= Height);}
179 Result
:= (X
>= X2
) and (X
<= (X2
+Width
)) and
180 (Y
>= Y2
) and (Y
<= (Y2
+Height
));
183 procedure IncMax(var A
: Integer; B
, Max
: Integer);
185 if A
+B
> Max
then A
:= Max
else A
:= A
+B
;
188 procedure IncMax(var A
: Single; B
, Max
: Single);
190 if A
+B
> Max
then A
:= Max
else A
:= A
+B
;
193 procedure DecMin(var A
: Integer; B
, Min
: Integer);
195 if A
-B
< Min
then A
:= Min
else A
:= A
-B
;
198 procedure DecMin(var A
: Word; B
, Min
: Word);
200 if A
-B
< Min
then A
:= Min
else A
:= A
-B
;
203 procedure DecMin(var A
: Single; B
, Min
: Single);
205 if A
-B
< Min
then A
:= Min
else A
:= A
-B
;
208 procedure IncMax(var A
: Integer; Max
: Integer);
210 if A
+1 > Max
then A
:= Max
else A
:= A
+1;
213 procedure IncMax(var A
: Single; Max
: Single);
215 if A
+1 > Max
then A
:= Max
else A
:= A
+1;
218 procedure IncMax(var A
: Word; B
, Max
: Word);
220 if A
+B
> Max
then A
:= Max
else A
:= A
+B
;
223 procedure IncMax(var A
: Word; Max
: Word);
225 if A
+1 > Max
then A
:= Max
else A
:= A
+1;
228 procedure IncMax(var A
: SmallInt; B
, Max
: SmallInt);
230 if A
+B
> Max
then A
:= Max
else A
:= A
+B
;
233 procedure IncMax(var A
: SmallInt; Max
: SmallInt);
235 if A
+1 > Max
then A
:= Max
else A
:= A
+1;
238 procedure DecMin(var A
: Integer; Min
: Integer);
240 if A
-1 < Min
then A
:= Min
else A
:= A
-1;
243 procedure DecMin(var A
: Single; Min
: Single);
245 if A
-1 < Min
then A
:= Min
else A
:= A
-1;
248 procedure DecMin(var A
: Word; Min
: Word);
250 if A
-1 < Min
then A
:= Min
else A
:= A
-1;
253 procedure DecMin(var A
: Byte; B
, Min
: Byte);
255 if A
-B
< Min
then A
:= Min
else A
:= A
-B
;
258 procedure DecMin(var A
: Byte; Min
: Byte); overload
;
260 if A
-1 < Min
then A
:= Min
else A
:= A
-1;
263 function Sign(A
: Integer): ShortInt;
265 if A
< 0 then Result
:= -1
266 else if A
> 0 then Result
:= 1
270 function Sign(A
: Single): ShortInt;
274 if Abs(A
) < Eps
then Result
:= 0
275 else if A
< 0 then Result
:= -1
279 function PointToRect(X
, Y
: Integer; X1
, Y1
, Width
, Height
: Integer): Integer;
286 if Y
< 0 then Result
:= Round(Sqrt(Sqr(X
)+Sqr(Y
)))
287 else if Y
> Height
then Result
:= Round(Sqrt(Sqr(X
)+Sqr(Y
-Height
)))
294 if y
< 0 then Result
:= Round(Sqrt(Sqr(X
)+Sqr(Y
)))
295 else if Y
> Height
then Result
:= Round(Sqrt(Sqr(X
)+Sqr(Y
-Height
)))
300 if Y
< 0 then Result
:= -Y
301 else if Y
> Height
then Result
:= Y
-Height