3 {$INCLUDE ../shared/a_modes.inc}
8 LCLIntf
, LCLType
, LMessages
;
11 EDITOR_VERSION
= '0.667';
12 EDITOR_BUILDDATE
= {$I %DATE%};
13 EDITOR_BUILDTIME
= {$I %TIME%};
16 String16
= String[16];
17 Char16
= packed array[0..15] of Char;
18 Char32
= packed array[0..31] of Char;
19 Char64
= packed array[0..63] of Char;
20 Char256
= packed array[0..255] of Char;
21 ArrayStr16
= Array of String16
;
22 SArray
= Array of String;
23 DWArray
= Array of DWORD
;
25 TDirection
= (D_LEFT
, D_RIGHT
);
27 function g_GetBuilderName (): AnsiString
;
28 function g_GetBuildHash (full
: Boolean = True): AnsiString
;
30 function g_Collide(X1
, Y1
: Integer; Width1
, Height1
: Word;
31 X2
, Y2
: Integer; Width2
, Height2
: Word): Boolean;
32 function g_CollidePoint(X
, Y
, X2
, Y2
: Integer; Width
, Height
: Word): Boolean;
33 function g_CollideLevel(X
, Y
: Integer; Width
, Height
: Word): Boolean;
34 function g_CollideLevel2(X
, Y
: Integer; Width
, Height
: Word; _ID
: DWORD
; var PanelID
: DWORD
): Boolean;
35 function g_PatchLength(X1
, Y1
, X2
, Y2
: Integer): Word;
36 procedure IncMax(var A
: Integer; B
, Max
: Integer); overload
;
37 procedure IncMax(var A
: Single; B
, Max
: Single); overload
;
38 procedure IncMax(var A
: Integer; Max
: Integer); overload
;
39 procedure IncMax(var A
: Single; Max
: Single); overload
;
40 procedure IncMax(var A
: Word; B
, Max
: Word); overload
;
41 procedure IncMax(var A
: Word; Max
: Word); overload
;
42 procedure IncMax(var A
: SmallInt
; B
, Max
: SmallInt
); overload
;
43 procedure IncMax(var A
: SmallInt
; Max
: SmallInt
); overload
;
44 procedure DecMin(var A
: Integer; B
, Min
: Integer); overload
;
45 procedure DecMin(var A
: Single; B
, Min
: Single); overload
;
46 procedure DecMin(var A
: Integer; Min
: Integer); overload
;
47 procedure DecMin(var A
: Single; Min
: Single); overload
;
48 procedure DecMin(var A
: Word; B
, Min
: Word); overload
;
49 procedure DecMin(var A
: Word; Min
: Word); overload
;
50 procedure DecMin(var A
: Byte; B
, Min
: Byte); overload
;
51 procedure DecMin(var A
: Byte; Min
: Byte); overload
;
52 function Sign(A
: Integer): ShortInt
; overload
;
53 function Sign(A
: Single): ShortInt
; overload
;
54 function PointToRect(X
, Y
: Integer; X1
, Y1
, Width
, Height
: Integer): Integer;
55 procedure g_ChangeDir(var dir
: TDirection
);
56 function g_GetFileTime(fileName
: String): Integer;
57 function g_SetFileTime(fileName
: String; time
: Integer): Boolean;
62 Math
, g_map
, MAPDEF
, SysUtils
;
65 {$WARN 2054 OFF} // unknwon env var
66 {$WARN 6018 OFF} // unreachable code
67 function g_GetBuilderName (): AnsiString
;
69 if {$I %D2DF_BUILD_USER%} <> '' then
70 result
:= {$I %D2DF_BUILD_USER%} // custom
71 else if {$I %USER%} <> '' then
72 result
:= {$I %USER%} // unix username
73 else if {$I %USERNAME%} <> '' then
74 result
:= {$I %USERNAME%} // windows username
79 function g_GetBuildHash (full
: Boolean = True): AnsiString
;
81 if {$I %D2DF_BUILD_HASH%} <> '' then
83 result
:= {$I %D2DF_BUILD_HASH%}
85 result
:= Copy({$I %D2DF_BUILD_HASH%}, 1, 7)
87 result
:= 'custom build'
91 procedure g_ChangeDir(var dir
: TDirection
);
99 function g_GetFileTime(fileName
: String): Integer;
104 if not FileExists(fileName
) then
110 AssignFile(F
, fileName
);
112 Result
:= FileGetDate(TFileRec(F
).Handle
);
116 function g_SetFileTime(fileName
: String; time
: Integer): Boolean;
121 if (not FileExists(fileName
)) or (time
< 0) then
127 AssignFile(F
, fileName
);
129 Result
:= (FileSetDate(TFileRec(F
).Handle
, time
) = 0);
133 function g_PatchLength(X1
, Y1
, X2
, Y2
: Integer): Word;
135 Result
:= Trunc(Hypot(Abs(X2
-X1
), Abs(Y2
-Y1
)));
138 function g_CollideLevel(X
, Y
: Integer; Width
, Height
: Word): Boolean;
145 if gPanels
= nil then Exit
;
147 for a
:= 0 to High(gPanels
) do
148 if gPanels
[a
].PanelType
= PANEL_WALL
then
149 if not (((Y
+ Height
<= gPanels
[a
].Y
) or
150 (Y
>= gPanels
[a
].Y
+ gPanels
[a
].Height
)) or
151 ((X
+ Width
<= gPanels
[a
].X
) or
152 (X
>= gPanels
[a
].X
+ gPanels
[a
].Width
))) then
159 {function g_CollideLevel2(X, Y, X2, Y2: Integer): Boolean;
165 if gWalls = nil then Exit;
167 for a := 0 to High(gWalls) do
168 if not (((Y2 <= gWalls[a].Y) or
169 (Y >= gWalls[a].Y + gWalls[a].Height)) or
170 ((X2 <= gWalls[a].X) or
171 (X >= gWalls[a].X + gWalls[a].Width))) then
178 function g_CollideLevel2(X
, Y
: Integer; Width
, Height
: Word; _ID
: DWORD
; var PanelID
: DWORD
): Boolean;
184 if gPanels
= nil then Exit
;
186 for a
:= 0 to High(gPanels
) do
187 if (gPanels
[a
].PanelType
= PANEL_WALL
) and (_ID
<> a
) then
188 if not (((Y
+ Height
<= gPanels
[a
].Y
) or
189 (Y
>= gPanels
[a
].Y
+ gPanels
[a
].Height
)) or
190 ((X
+ Width
<= gPanels
[a
].X
) or
191 (X
>= gPanels
[a
].X
+ gPanels
[a
].Width
))) then
199 function g_Collide(X1
, Y1
: Integer; Width1
, Height1
: Word;
200 X2
, Y2
: Integer; Width2
, Height2
: Word): Boolean;
202 Result
:= not (((Y1
+ Height1
<= Y2
) or
203 (Y1
>= Y2
+ Height2
)) or
204 ((X1
+ Width1
<= X2
) or
205 (X1
>= X2
+ Width2
)));
208 function g_CollidePoint(X
, Y
, X2
, Y2
: Integer; Width
, Height
: Word): Boolean;
212 Result := (x >= 0) and (x <= Width) and
213 (y >= 0) and (y <= Height);}
214 Result
:= (X
>= X2
) and (X
<= (X2
+Width
)) and
215 (Y
>= Y2
) and (Y
<= (Y2
+Height
));
218 procedure IncMax(var A
: Integer; B
, Max
: Integer);
220 if A
+B
> Max
then A
:= Max
else A
:= A
+B
;
223 procedure IncMax(var A
: Single; B
, Max
: Single);
225 if A
+B
> Max
then A
:= Max
else A
:= A
+B
;
228 procedure DecMin(var A
: Integer; B
, Min
: Integer);
230 if A
-B
< Min
then A
:= Min
else A
:= A
-B
;
233 procedure DecMin(var A
: Word; B
, Min
: Word);
235 if A
-B
< Min
then A
:= Min
else A
:= A
-B
;
238 procedure DecMin(var A
: Single; B
, Min
: Single);
240 if A
-B
< Min
then A
:= Min
else A
:= A
-B
;
243 procedure IncMax(var A
: Integer; Max
: Integer);
245 if A
+1 > Max
then A
:= Max
else A
:= A
+1;
248 procedure IncMax(var A
: Single; Max
: Single);
250 if A
+1 > Max
then A
:= Max
else A
:= A
+1;
253 procedure IncMax(var A
: Word; B
, Max
: Word);
255 if A
+B
> Max
then A
:= Max
else A
:= A
+B
;
258 procedure IncMax(var A
: Word; Max
: Word);
260 if A
+1 > Max
then A
:= Max
else A
:= A
+1;
263 procedure IncMax(var A
: SmallInt
; B
, Max
: SmallInt
);
265 if A
+B
> Max
then A
:= Max
else A
:= A
+B
;
268 procedure IncMax(var A
: SmallInt
; Max
: SmallInt
);
270 if A
+1 > Max
then A
:= Max
else A
:= A
+1;
273 procedure DecMin(var A
: Integer; Min
: Integer);
275 if A
-1 < Min
then A
:= Min
else A
:= A
-1;
278 procedure DecMin(var A
: Single; Min
: Single);
280 if A
-1 < Min
then A
:= Min
else A
:= A
-1;
283 procedure DecMin(var A
: Word; Min
: Word);
285 if A
-1 < Min
then A
:= Min
else A
:= A
-1;
288 procedure DecMin(var A
: Byte; B
, Min
: Byte);
290 if A
-B
< Min
then A
:= Min
else A
:= A
-B
;
293 procedure DecMin(var A
: Byte; Min
: Byte); overload
;
295 if A
-1 < Min
then A
:= Min
else A
:= A
-1;
298 function Sign(A
: Integer): ShortInt
;
300 if A
< 0 then Result
:= -1
301 else if A
> 0 then Result
:= 1
305 function Sign(A
: Single): ShortInt
;
309 if Abs(A
) < Eps
then Result
:= 0
310 else if A
< 0 then Result
:= -1
314 function PointToRect(X
, Y
: Integer; X1
, Y1
, Width
, Height
: Integer): Integer;
321 if Y
< 0 then Result
:= Round(Sqrt(Sqr(X
)+Sqr(Y
)))
322 else if Y
> Height
then Result
:= Round(Sqrt(Sqr(X
)+Sqr(Y
-Height
)))
329 if y
< 0 then Result
:= Round(Sqrt(Sqr(X
)+Sqr(Y
)))
330 else if Y
> Height
then Result
:= Round(Sqrt(Sqr(X
)+Sqr(Y
-Height
)))
335 if Y
< 0 then Result
:= -Y
336 else if Y
> Height
then Result
:= Y
-Height