1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
18 interface
20 uses
23 const
35 type
95 var
98 implementation
100 uses
104 {$PUSH}
108 begin
115 else
120 begin
124 else
126 else
129 {$POP}
133 begin
134 {$IF DEFINED(CPUX86_64) OR DEFINED(CPUAMD64) OR DEFINED(CPUX64)}
136 {$ELSEIF DEFINED(CPUI386) OR DEFINED(CPU386)}
138 {$ELSEIF DEFINED(CPUI8086)}
140 {$ELSEIF DEFINED(CPUI64)}
142 {$ELSEIF DEFINED(CPUARM)}
144 {$ELSEIF DEFINED(CPUAVR)}
146 {$ELSEIF DEFINED(CPUPOWERPC32)}
148 {$ELSEIF DEFINED(CPUPOWERPC64)}
150 {$ELSEIF DEFINED(CPUALPHA)}}
152 {$ELSEIF DEFINED(CPUSPARC32)}
154 {$ELSEIF DEFINED(CPUM68020)}
156 {$ELSEIF DEFINED(CPU68K) OR DEFINED(CPUM68K)}
158 {$ELSEIF DEFINED(CPUSPARC)}
160 {$ELSEIF DEFINED(CPUPOWERPC)}
162 {$ELSEIF DEFINED(CPU86) OR DEFINED(CPU87)}
164 {$ELSE}
166 {$ENDIF}
168 {$IF DEFINED(CPU64)}
170 {$ELSEIF DEFINED(CPU32)}
172 {$ELSEIF DEFINED(CPU16)}
174 {$ELSE}
176 {$ENDIF}
178 {$IF DEFINED(FPUSOFT)}
180 {$ELSEIF DEFINED(FPUSSE3)}
182 {$ELSEIF DEFINED(FPUSSE2)}
184 {$ELSEIF DEFINED(FPUSSE)}
186 {$ELSEIF DEFINED(FPUSSE64)}
188 {$ELSEIF DEFINED(FPULIBGCC)}
190 {$ELSEIF DEFINED(FPU68881)}
192 {$ELSEIF DEFINED(FPUVFP)}
194 {$ELSEIF DEFINED(FPUFPA11)}
196 {$ELSEIF DEFINED(FPUFPA10)}
198 {$ELSEIF DEFINED(FPUFPA)}
200 {$ELSEIF DEFINED(FPUX87)}
202 {$ELSEIF DEFINED(FPUITANIUM)}
204 {$ELSEIF DEFINED(FPUSTANDARD)}
206 {$ELSEIF DEFINED(FPUHARD)}
208 {$ELSE}
210 {$ENDIF}
216 begin
221 begin
222 result := g_Map_CollidePanel(X, Y, Width, Height, (PANEL_WALL or PANEL_CLOSEDOOR or PANEL_OPENDOOR), false);
224 (*
225 var
226 a: Integer;
227 begin
228 Result := False;
230 if gWalls = nil then
231 Exit;
233 for a := 0 to High(gWalls) do
234 if gWalls[a].Enabled and
235 not ( ((Y + Height <= gWalls[a].Y) or
236 (Y >= gWalls[a].Y + gWalls[a].Height)) or
237 ((X + Width <= gWalls[a].X) or
238 (X >= gWalls[a].X + gWalls[a].Width)) ) then
239 begin
240 Result := True;
241 Exit;
242 end;
243 end;
244 *)
247 var
249 begin
257 begin
259 Exit;
265 var
268 (*
269 i: Integer;
270 dx, dy: Integer;
271 Xerr, Yerr, d: LongWord;
272 incX, incY: Integer;
273 x, y: Integer;
274 *)
275 begin
276 (*
277 result := False;
279 Assert(gCollideMap <> nil, 'g_TraceVector: gCollideMap = nil');
281 Xerr := 0;
282 Yerr := 0;
283 dx := X2-X1;
284 dy := Y2-Y1;
286 if dx > 0 then incX := 1 else if dx < 0 then incX := -1 else incX := 0;
287 if dy > 0 then incY := 1 else if dy < 0 then incY := -1 else incY := 0;
289 dx := abs(dx);
290 dy := abs(dy);
292 if dx > dy then d := dx else d := dy;
294 x := X1;
295 y := Y1;
297 for i := 1 to d do
298 begin
299 Inc(Xerr, dx);
300 Inc(Yerr, dy);
301 if Xerr>d then
302 begin
303 Dec(Xerr, d);
304 Inc(x, incX);
305 end;
306 if Yerr > d then
307 begin
308 Dec(Yerr, d);
309 Inc(y, incY);
310 end;
312 if (y > gMapInfo.Height-1) or
313 (y < 0) or (x > gMapInfo.Width-1) or (x < 0) then
314 Exit;
315 if ByteBool(gCollideMap[y, x] and MARK_BLOCKED) then
316 Exit;
317 end;
319 Result := True;
320 *)
322 // `true` if no obstacles
330 var
333 begin
337 UID_PLAYER:
338 begin
339 repeat
347 begin
349 Break;
354 UID_MONSTER:
355 begin
356 //FIXME!!!
358 begin
367 begin
369 Result := UID_GAME
370 else
372 Result := UID_PLAYER
373 else
379 begin
388 begin
397 begin
405 begin
406 //Result := not (((Y2 <= Y3) or (Y1 >= Y4)) or ((X2 <= X3) or (X1 >= X4)));
411 begin
419 begin
424 begin
429 begin
434 begin
439 begin
444 begin
449 begin
454 begin
459 begin
464 begin
469 begin
474 begin
479 begin
484 begin
489 begin
494 begin
499 begin
506 const
508 begin
515 begin
518 // D(0;H) --- C(W;H)
523 else
528 end
529 else
535 else
540 end
542 begin
544 Result := -Y
545 else
554 const
556 var
558 begin
568 var
571 begin
585 var
588 begin
594 else
607 {function g_CollideLine(x1, y1, x2, y2, rX, rY: Integer; rWidth, rHeight: Word): Boolean;
608 const
609 table: array[0..8, 0..8] of Byte =
610 ((0, 0, 3, 3, 1, 2, 2, 0, 1),
611 (0, 0, 0, 0, 4, 7, 2, 0, 1),
612 (3, 0, 0, 0, 4, 4, 1, 3, 1),
613 (3, 0, 0, 0, 0, 0, 5, 6, 1),
614 (1, 4, 4, 0, 0, 0, 5, 5, 1),
615 (2, 7, 4, 0, 0, 0, 0, 0, 1),
616 (2, 2, 1, 5, 5, 0, 0, 0, 1),
617 (0, 0, 3, 6, 5, 0, 0, 0, 1),
618 (1, 1, 1, 1, 1, 1, 1, 1, 1));
620 function GetClass(x, y: Integer): Byte;
621 begin
622 if y < rY then
623 begin
624 if x < rX then Result := 7
625 else if x < rX+rWidth then Result := 0
626 else Result := 1;
627 end
628 else if y < rY+rHeight then
629 begin
630 if x < rX then Result := 6
631 else if x < rX+rWidth then Result := 8
632 else Result := 2;
633 end
634 else
635 begin
636 if x < rX then Result := 5
637 else if x < rX+rWidth then Result := 4
638 else Result := 3;
639 end;
640 end;
642 begin
643 case table[GetClass(x1, y1), GetClass(x2, y2)] of
644 0: Result := False;
645 1: Result := True;
646 2: Result := Abs((rY-y1))/Abs((rX-x1)) <= Abs((y2-y1))/Abs((x2-x1));
647 3: Result := Abs((rY-y1))/Abs((rX+rWidth-x1)) <= Abs((y2-y1))/Abs((x2-x1));
648 4: Result := Abs((rY+rHeight-y1))/Abs((rX+rWidth-x1)) >= Abs((y2-y1))/Abs((x2-x1));
649 5: Result := Abs((rY+rHeight-y1))/Abs((rX-x1)) >= Abs((y2-y1))/Abs((x2-x1));
650 6: Result := (Abs((rY-y1))/Abs((rX+rWidth-x1)) <= Abs((y2-y1))/Abs((x2-x1))) and
651 (Abs((rY+rHeight-y1))/Abs((rX-x1)) >= Abs((y2-y1))/Abs((x2-x1)));
652 7: Result := (Abs((rY+rHeight-y1))/Abs((rX+rWidth-x1)) >= Abs((y2-y1))/Abs((x2-x1))) and
653 (Abs((rY-y1))/Abs((rX-x1)) <= Abs((y2-y1))/Abs((x2-x1)));
654 else Result := False;
655 end;
656 end;}
659 {
660 var
661 i: Integer;
662 dx, dy: Integer;
663 Xerr, Yerr: Integer;
664 incX, incY: Integer;
665 x, y, d: Integer;
666 }
667 begin
669 {
670 Result := True;
672 Xerr := 0;
673 Yerr := 0;
674 dx := X2-X1;
675 dy := Y2-Y1;
677 if dx > 0 then incX := 1 else if dx < 0 then incX := -1 else incX := 0;
678 if dy > 0 then incY := 1 else if dy < 0 then incY := -1 else incY := 0;
680 dx := abs(dx);
681 dy := abs(dy);
683 if dx > dy then d := dx else d := dy;
685 x := X1;
686 y := Y1;
688 for i := 1 to d+1 do
689 begin
690 Inc(Xerr, dx);
691 Inc(Yerr, dy);
692 if Xerr > d then
693 begin
694 Dec(Xerr, d);
695 Inc(x, incX);
696 end;
697 if Yerr > d then
698 begin
699 Dec(Yerr, d);
700 Inc(y, incY);
701 end;
703 if (x >= rX) and (x <= (rX + rWidth - 1)) and
704 (y >= rY) and (y <= (rY + rHeight - 1)) then Exit;
705 end;
707 Result := False;
708 }
712 var
714 begin
718 begin
722 Exit;
728 var
735 begin
741 begin
750 begin
757 begin
766 begin
772 begin
781 begin
790 begin
794 begin
798 Break;
801 begin
809 Break;
813 Break;
818 begin
825 begin
829 vtInteger :
830 begin
832 begin
836 end
837 else
838 Break;
841 vtExtended :
842 begin
844 begin
848 end
849 else
850 Break;
853 vtString :
854 begin
856 begin
859 end
860 else
861 Break;
865 Break;
871 var
873 begin
880 begin
882 Exit;
887 var
889 begin
896 begin
898 Exit;
903 var
905 begin
914 begin
916 Exit;
921 var
924 begin
928 UID_PLAYER:
929 begin
937 UID_MONSTER:
938 begin
952 var
954 begin
957 Exit;
960 begin
963 begin
972 Break;
978 var
980 begin
985 begin
988 begin
995 Break;
1001 var
1003 begin
1005 begin
1007 Exit;
1017 var
1019 begin
1021 begin
1023 Exit;
1033 var
1037 begin
1038 repeat
1051 var
1054 begin
1059 begin
1061 begin
1064 continue;
1067 begin
1089 else
1093 end else
1096 // reset to white at end
1101 var
1104 begin
1108 begin
1110 begin
1112 continue;
1115 begin
1117 continue;
1120 begin
1132 else
1136 end else
1142 begin
1147 var
1149 begin