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
94 var
97 implementation
99 uses
103 {$PUSH}
107 begin
114 else
119 begin
123 else
125 else
128 {$POP}
131 begin
136 begin
137 result := g_Map_CollidePanel(X, Y, Width, Height, (PANEL_WALL or PANEL_CLOSEDOOR or PANEL_OPENDOOR), false);
139 (*
140 var
141 a: Integer;
142 begin
143 Result := False;
145 if gWalls = nil then
146 Exit;
148 for a := 0 to High(gWalls) do
149 if gWalls[a].Enabled and
150 not ( ((Y + Height <= gWalls[a].Y) or
151 (Y >= gWalls[a].Y + gWalls[a].Height)) or
152 ((X + Width <= gWalls[a].X) or
153 (X >= gWalls[a].X + gWalls[a].Width)) ) then
154 begin
155 Result := True;
156 Exit;
157 end;
158 end;
159 *)
162 var
164 begin
172 begin
174 Exit;
180 var
183 (*
184 i: Integer;
185 dx, dy: Integer;
186 Xerr, Yerr, d: LongWord;
187 incX, incY: Integer;
188 x, y: Integer;
189 *)
190 begin
191 (*
192 result := False;
194 Assert(gCollideMap <> nil, 'g_TraceVector: gCollideMap = nil');
196 Xerr := 0;
197 Yerr := 0;
198 dx := X2-X1;
199 dy := Y2-Y1;
201 if dx > 0 then incX := 1 else if dx < 0 then incX := -1 else incX := 0;
202 if dy > 0 then incY := 1 else if dy < 0 then incY := -1 else incY := 0;
204 dx := abs(dx);
205 dy := abs(dy);
207 if dx > dy then d := dx else d := dy;
209 x := X1;
210 y := Y1;
212 for i := 1 to d do
213 begin
214 Inc(Xerr, dx);
215 Inc(Yerr, dy);
216 if Xerr>d then
217 begin
218 Dec(Xerr, d);
219 Inc(x, incX);
220 end;
221 if Yerr > d then
222 begin
223 Dec(Yerr, d);
224 Inc(y, incY);
225 end;
227 if (y > gMapInfo.Height-1) or
228 (y < 0) or (x > gMapInfo.Width-1) or (x < 0) then
229 Exit;
230 if ByteBool(gCollideMap[y, x] and MARK_BLOCKED) then
231 Exit;
232 end;
234 Result := True;
235 *)
237 // `true` if no obstacles
245 var
248 begin
252 UID_PLAYER:
253 begin
254 repeat
262 begin
264 Break;
269 UID_MONSTER:
270 begin
271 //FIXME!!!
273 begin
282 begin
284 Result := UID_GAME
285 else
287 Result := UID_PLAYER
288 else
294 begin
303 begin
312 begin
320 begin
321 //Result := not (((Y2 <= Y3) or (Y1 >= Y4)) or ((X2 <= X3) or (X1 >= X4)));
326 begin
334 begin
339 begin
344 begin
349 begin
354 begin
359 begin
364 begin
369 begin
374 begin
379 begin
384 begin
389 begin
394 begin
399 begin
404 begin
409 begin
414 begin
421 const
423 begin
430 begin
433 // D(0;H) --- C(W;H)
438 else
443 end
444 else
450 else
455 end
457 begin
459 Result := -Y
460 else
469 const
471 var
473 begin
483 var
486 begin
500 var
503 begin
509 else
522 {function g_CollideLine(x1, y1, x2, y2, rX, rY: Integer; rWidth, rHeight: Word): Boolean;
523 const
524 table: array[0..8, 0..8] of Byte =
525 ((0, 0, 3, 3, 1, 2, 2, 0, 1),
526 (0, 0, 0, 0, 4, 7, 2, 0, 1),
527 (3, 0, 0, 0, 4, 4, 1, 3, 1),
528 (3, 0, 0, 0, 0, 0, 5, 6, 1),
529 (1, 4, 4, 0, 0, 0, 5, 5, 1),
530 (2, 7, 4, 0, 0, 0, 0, 0, 1),
531 (2, 2, 1, 5, 5, 0, 0, 0, 1),
532 (0, 0, 3, 6, 5, 0, 0, 0, 1),
533 (1, 1, 1, 1, 1, 1, 1, 1, 1));
535 function GetClass(x, y: Integer): Byte;
536 begin
537 if y < rY then
538 begin
539 if x < rX then Result := 7
540 else if x < rX+rWidth then Result := 0
541 else Result := 1;
542 end
543 else if y < rY+rHeight then
544 begin
545 if x < rX then Result := 6
546 else if x < rX+rWidth then Result := 8
547 else Result := 2;
548 end
549 else
550 begin
551 if x < rX then Result := 5
552 else if x < rX+rWidth then Result := 4
553 else Result := 3;
554 end;
555 end;
557 begin
558 case table[GetClass(x1, y1), GetClass(x2, y2)] of
559 0: Result := False;
560 1: Result := True;
561 2: Result := Abs((rY-y1))/Abs((rX-x1)) <= Abs((y2-y1))/Abs((x2-x1));
562 3: Result := Abs((rY-y1))/Abs((rX+rWidth-x1)) <= Abs((y2-y1))/Abs((x2-x1));
563 4: Result := Abs((rY+rHeight-y1))/Abs((rX+rWidth-x1)) >= Abs((y2-y1))/Abs((x2-x1));
564 5: Result := Abs((rY+rHeight-y1))/Abs((rX-x1)) >= Abs((y2-y1))/Abs((x2-x1));
565 6: Result := (Abs((rY-y1))/Abs((rX+rWidth-x1)) <= Abs((y2-y1))/Abs((x2-x1))) and
566 (Abs((rY+rHeight-y1))/Abs((rX-x1)) >= Abs((y2-y1))/Abs((x2-x1)));
567 7: Result := (Abs((rY+rHeight-y1))/Abs((rX+rWidth-x1)) >= Abs((y2-y1))/Abs((x2-x1))) and
568 (Abs((rY-y1))/Abs((rX-x1)) <= Abs((y2-y1))/Abs((x2-x1)));
569 else Result := False;
570 end;
571 end;}
574 {
575 var
576 i: Integer;
577 dx, dy: Integer;
578 Xerr, Yerr: Integer;
579 incX, incY: Integer;
580 x, y, d: Integer;
581 }
582 begin
584 {
585 Result := True;
587 Xerr := 0;
588 Yerr := 0;
589 dx := X2-X1;
590 dy := Y2-Y1;
592 if dx > 0 then incX := 1 else if dx < 0 then incX := -1 else incX := 0;
593 if dy > 0 then incY := 1 else if dy < 0 then incY := -1 else incY := 0;
595 dx := abs(dx);
596 dy := abs(dy);
598 if dx > dy then d := dx else d := dy;
600 x := X1;
601 y := Y1;
603 for i := 1 to d+1 do
604 begin
605 Inc(Xerr, dx);
606 Inc(Yerr, dy);
607 if Xerr > d then
608 begin
609 Dec(Xerr, d);
610 Inc(x, incX);
611 end;
612 if Yerr > d then
613 begin
614 Dec(Yerr, d);
615 Inc(y, incY);
616 end;
618 if (x >= rX) and (x <= (rX + rWidth - 1)) and
619 (y >= rY) and (y <= (rY + rHeight - 1)) then Exit;
620 end;
622 Result := False;
623 }
627 var
629 begin
633 begin
637 Exit;
643 var
650 begin
656 begin
665 begin
672 begin
681 begin
687 begin
696 begin
705 begin
709 begin
713 Break;
716 begin
724 Break;
728 Break;
733 begin
740 begin
744 vtInteger :
745 begin
747 begin
751 end
752 else
753 Break;
756 vtExtended :
757 begin
759 begin
763 end
764 else
765 Break;
768 vtString :
769 begin
771 begin
774 end
775 else
776 Break;
780 Break;
786 var
788 begin
795 begin
797 Exit;
802 var
804 begin
811 begin
813 Exit;
818 var
820 begin
829 begin
831 Exit;
836 var
839 begin
843 UID_PLAYER:
844 begin
852 UID_MONSTER:
853 begin
867 var
869 begin
872 Exit;
875 begin
878 begin
887 Break;
893 var
895 begin
900 begin
903 begin
910 Break;
916 var
918 begin
920 begin
922 Exit;
932 var
934 begin
936 begin
938 Exit;
948 var
952 begin
953 repeat
966 var
969 begin
974 begin
976 begin
979 continue;
982 begin
1004 else
1008 end else
1011 // reset to white at end
1016 var
1019 begin
1023 begin
1025 begin
1027 continue;
1030 begin
1032 continue;
1035 begin
1047 else
1051 end else
1057 begin
1062 var
1064 begin