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
96 var
99 implementation
101 uses
105 {$PUSH}
109 begin
116 else
121 begin
125 else
127 else
130 {$POP}
134 begin
135 {$IF DEFINED(CPUX86_64) OR DEFINED(CPUAMD64) OR DEFINED(CPUX64)}
137 {$ELSEIF DEFINED(CPUI386) OR DEFINED(CPU386)}
139 {$ELSEIF DEFINED(CPUI8086)}
141 {$ELSEIF DEFINED(CPUI64)}
143 {$ELSEIF DEFINED(CPUARM)}
145 {$ELSEIF DEFINED(CPUAVR)}
147 {$ELSEIF DEFINED(CPUPOWERPC32)}
149 {$ELSEIF DEFINED(CPUPOWERPC64)}
151 {$ELSEIF DEFINED(CPUALPHA)}}
153 {$ELSEIF DEFINED(CPUSPARC32)}
155 {$ELSEIF DEFINED(CPUM68020)}
157 {$ELSEIF DEFINED(CPU68K) OR DEFINED(CPUM68K)}
159 {$ELSEIF DEFINED(CPUSPARC)}
161 {$ELSEIF DEFINED(CPUPOWERPC)}
163 {$ELSEIF DEFINED(CPU86) OR DEFINED(CPU87)}
165 {$ELSE}
167 {$ENDIF}
169 {$IF DEFINED(CPU64)}
171 {$ELSEIF DEFINED(CPU32)}
173 {$ELSEIF DEFINED(CPU16)}
175 {$ELSE}
177 {$ENDIF}
179 {$IF DEFINED(FPUSOFT)}
181 {$ELSEIF DEFINED(FPUSSE3)}
183 {$ELSEIF DEFINED(FPUSSE2)}
185 {$ELSEIF DEFINED(FPUSSE)}
187 {$ELSEIF DEFINED(FPUSSE64)}
189 {$ELSEIF DEFINED(FPULIBGCC)}
191 {$ELSEIF DEFINED(FPU68881)}
193 {$ELSEIF DEFINED(FPUVFP)}
195 {$ELSEIF DEFINED(FPUFPA11)}
197 {$ELSEIF DEFINED(FPUFPA10)}
199 {$ELSEIF DEFINED(FPUFPA)}
201 {$ELSEIF DEFINED(FPUX87)}
203 {$ELSEIF DEFINED(FPUITANIUM)}
205 {$ELSEIF DEFINED(FPUSTANDARD)}
207 {$ELSEIF DEFINED(FPUHARD)}
209 {$ELSE}
211 {$ENDIF}
217 begin
222 begin
223 result := g_Map_CollidePanel(X, Y, Width, Height, (PANEL_WALL or PANEL_CLOSEDOOR or PANEL_OPENDOOR), false);
225 (*
226 var
227 a: Integer;
228 begin
229 Result := False;
231 if gWalls = nil then
232 Exit;
234 for a := 0 to High(gWalls) do
235 if gWalls[a].Enabled and
236 not ( ((Y + Height <= gWalls[a].Y) or
237 (Y >= gWalls[a].Y + gWalls[a].Height)) or
238 ((X + Width <= gWalls[a].X) or
239 (X >= gWalls[a].X + gWalls[a].Width)) ) then
240 begin
241 Result := True;
242 Exit;
243 end;
244 end;
245 *)
248 var
250 begin
258 begin
260 Exit;
266 var
269 (*
270 i: Integer;
271 dx, dy: Integer;
272 Xerr, Yerr, d: LongWord;
273 incX, incY: Integer;
274 x, y: Integer;
275 *)
276 begin
277 (*
278 result := False;
280 Assert(gCollideMap <> nil, 'g_TraceVector: gCollideMap = nil');
282 Xerr := 0;
283 Yerr := 0;
284 dx := X2-X1;
285 dy := Y2-Y1;
287 if dx > 0 then incX := 1 else if dx < 0 then incX := -1 else incX := 0;
288 if dy > 0 then incY := 1 else if dy < 0 then incY := -1 else incY := 0;
290 dx := abs(dx);
291 dy := abs(dy);
293 if dx > dy then d := dx else d := dy;
295 x := X1;
296 y := Y1;
298 for i := 1 to d do
299 begin
300 Inc(Xerr, dx);
301 Inc(Yerr, dy);
302 if Xerr>d then
303 begin
304 Dec(Xerr, d);
305 Inc(x, incX);
306 end;
307 if Yerr > d then
308 begin
309 Dec(Yerr, d);
310 Inc(y, incY);
311 end;
313 if (y > gMapInfo.Height-1) or
314 (y < 0) or (x > gMapInfo.Width-1) or (x < 0) then
315 Exit;
316 if ByteBool(gCollideMap[y, x] and MARK_BLOCKED) then
317 Exit;
318 end;
320 Result := True;
321 *)
323 // `true` if no obstacles
331 var
334 begin
338 UID_PLAYER:
339 begin
340 repeat
348 begin
350 Break;
355 UID_MONSTER:
356 begin
357 //FIXME!!!
359 begin
368 begin
370 Result := UID_GAME
371 else
373 Result := UID_PLAYER
374 else
380 begin
389 begin
398 begin
406 begin
407 //Result := not (((Y2 <= Y3) or (Y1 >= Y4)) or ((X2 <= X3) or (X1 >= X4)));
412 begin
420 begin
425 begin
430 begin
435 begin
440 begin
445 begin
450 begin
455 begin
460 begin
465 begin
470 begin
475 begin
480 begin
485 begin
490 begin
495 begin
500 begin
507 const
509 begin
516 begin
519 // D(0;H) --- C(W;H)
524 else
529 end
530 else
536 else
541 end
543 begin
545 Result := -Y
546 else
555 const
557 var
559 begin
569 begin
574 begin
576 Exit;
586 var
589 begin
603 var
606 begin
612 else
625 {function g_CollideLine(x1, y1, x2, y2, rX, rY: Integer; rWidth, rHeight: Word): Boolean;
626 const
627 table: array[0..8, 0..8] of Byte =
628 ((0, 0, 3, 3, 1, 2, 2, 0, 1),
629 (0, 0, 0, 0, 4, 7, 2, 0, 1),
630 (3, 0, 0, 0, 4, 4, 1, 3, 1),
631 (3, 0, 0, 0, 0, 0, 5, 6, 1),
632 (1, 4, 4, 0, 0, 0, 5, 5, 1),
633 (2, 7, 4, 0, 0, 0, 0, 0, 1),
634 (2, 2, 1, 5, 5, 0, 0, 0, 1),
635 (0, 0, 3, 6, 5, 0, 0, 0, 1),
636 (1, 1, 1, 1, 1, 1, 1, 1, 1));
638 function GetClass(x, y: Integer): Byte;
639 begin
640 if y < rY then
641 begin
642 if x < rX then Result := 7
643 else if x < rX+rWidth then Result := 0
644 else Result := 1;
645 end
646 else if y < rY+rHeight then
647 begin
648 if x < rX then Result := 6
649 else if x < rX+rWidth then Result := 8
650 else Result := 2;
651 end
652 else
653 begin
654 if x < rX then Result := 5
655 else if x < rX+rWidth then Result := 4
656 else Result := 3;
657 end;
658 end;
660 begin
661 case table[GetClass(x1, y1), GetClass(x2, y2)] of
662 0: Result := False;
663 1: Result := True;
664 2: Result := Abs((rY-y1))/Abs((rX-x1)) <= Abs((y2-y1))/Abs((x2-x1));
665 3: Result := Abs((rY-y1))/Abs((rX+rWidth-x1)) <= Abs((y2-y1))/Abs((x2-x1));
666 4: Result := Abs((rY+rHeight-y1))/Abs((rX+rWidth-x1)) >= Abs((y2-y1))/Abs((x2-x1));
667 5: Result := Abs((rY+rHeight-y1))/Abs((rX-x1)) >= Abs((y2-y1))/Abs((x2-x1));
668 6: Result := (Abs((rY-y1))/Abs((rX+rWidth-x1)) <= Abs((y2-y1))/Abs((x2-x1))) and
669 (Abs((rY+rHeight-y1))/Abs((rX-x1)) >= Abs((y2-y1))/Abs((x2-x1)));
670 7: Result := (Abs((rY+rHeight-y1))/Abs((rX+rWidth-x1)) >= Abs((y2-y1))/Abs((x2-x1))) and
671 (Abs((rY-y1))/Abs((rX-x1)) <= Abs((y2-y1))/Abs((x2-x1)));
672 else Result := False;
673 end;
674 end;}
677 {
678 var
679 i: Integer;
680 dx, dy: Integer;
681 Xerr, Yerr: Integer;
682 incX, incY: Integer;
683 x, y, d: Integer;
684 }
685 begin
687 {
688 Result := True;
690 Xerr := 0;
691 Yerr := 0;
692 dx := X2-X1;
693 dy := Y2-Y1;
695 if dx > 0 then incX := 1 else if dx < 0 then incX := -1 else incX := 0;
696 if dy > 0 then incY := 1 else if dy < 0 then incY := -1 else incY := 0;
698 dx := abs(dx);
699 dy := abs(dy);
701 if dx > dy then d := dx else d := dy;
703 x := X1;
704 y := Y1;
706 for i := 1 to d+1 do
707 begin
708 Inc(Xerr, dx);
709 Inc(Yerr, dy);
710 if Xerr > d then
711 begin
712 Dec(Xerr, d);
713 Inc(x, incX);
714 end;
715 if Yerr > d then
716 begin
717 Dec(Yerr, d);
718 Inc(y, incY);
719 end;
721 if (x >= rX) and (x <= (rX + rWidth - 1)) and
722 (y >= rY) and (y <= (rY + rHeight - 1)) then Exit;
723 end;
725 Result := False;
726 }
730 var
732 begin
736 begin
740 Exit;
746 var
753 begin
759 begin
768 begin
775 begin
784 begin
790 begin
799 begin
808 begin
812 begin
816 Break;
819 begin
827 Break;
831 Break;
836 begin
843 begin
847 vtInteger :
848 begin
850 begin
854 end
855 else
856 Break;
859 vtExtended :
860 begin
862 begin
866 end
867 else
868 Break;
871 vtString :
872 begin
874 begin
877 end
878 else
879 Break;
883 Break;
889 var
891 begin
898 begin
900 Exit;
905 var
907 begin
914 begin
916 Exit;
921 var
923 begin
932 begin
934 Exit;
939 var
942 begin
946 UID_PLAYER:
947 begin
955 UID_MONSTER:
956 begin
970 var
972 begin
975 Exit;
978 begin
981 begin
990 Break;
996 var
998 begin
1003 begin
1006 begin
1013 Break;
1019 var
1021 begin
1023 begin
1025 Exit;
1035 var
1037 begin
1039 begin
1041 Exit;
1051 var
1055 begin
1056 repeat
1069 var
1072 begin
1077 begin
1079 begin
1082 continue;
1085 begin
1107 else
1111 end else
1114 // reset to white at end
1119 var
1122 begin
1126 begin
1128 begin
1130 continue;
1133 begin
1135 continue;
1138 begin
1150 else
1154 end else
1160 begin
1165 var
1167 begin