1 (* Copyright (C) Doom 2D: Forever Developers
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.
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.
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/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_textures
, g_basic
, e_graphics
, g_phys
, g_grid
, g_player
, g_monsters
,
24 g_window
, g_map
, g_triggers
, g_items
, g_game
, g_panel
, g_console
, g_gfx
,
27 fui_common
, fui_events
, fui_ctls
,
31 procedure g_Holmes_Draw ();
32 procedure g_Holmes_DrawUI ();
34 procedure g_Holmes_OnEvent (var ev
: TFUIEvent
);
37 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
38 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
39 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
43 g_holmes_imfunctional
: Boolean = false;
44 g_holmes_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
50 {$INCLUDE ../nogl/noGLuses.inc}
51 {rttiobj,} typinfo
, e_texture
, e_res
,
52 SysUtils
, Classes
, SDL2
,
53 MAPDEF
, g_main
, g_options
,
54 utils
, hashtable
, xparser
;
58 hlmContext
: TGxContext
= nil;
59 //globalInited: Boolean = false;
62 msB
: Word = 0; // button state
63 kbS
: Word = 0; // keyboard modifiers state
64 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
65 showMonsInfo
: Boolean = false;
66 showMonsLOS2Plr
: Boolean = false;
67 showAllMonsCells
: Boolean = false;
68 showMapCurPos
: Boolean = false;
69 showLayersWindow
: Boolean = false;
70 showOutlineWindow
: Boolean = false;
71 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
72 showTraceBox
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
75 // ////////////////////////////////////////////////////////////////////////// //
76 {$INCLUDE g_holmes.inc}
77 {$INCLUDE g_holmes_ol.inc} // outliner
80 // ////////////////////////////////////////////////////////////////////////// //
81 {$INCLUDE g_holmes_cmd.inc}
82 procedure holmesInitCommands (); forward;
83 procedure holmesInitBinds (); forward;
86 // ////////////////////////////////////////////////////////////////////////// //
88 g_ol_nice
: Boolean = false;
89 g_ol_fill_walls
: Boolean = false;
90 g_ol_rlayer_back
: Boolean = false;
91 g_ol_rlayer_step
: Boolean = false;
92 g_ol_rlayer_wall
: Boolean = false;
93 g_ol_rlayer_door
: Boolean = false;
94 g_ol_rlayer_acid1
: Boolean = false;
95 g_ol_rlayer_acid2
: Boolean = false;
96 g_ol_rlayer_water
: Boolean = false;
97 g_ol_rlayer_fore
: Boolean = false;
100 // ////////////////////////////////////////////////////////////////////////// //
102 winHelp
: TUITopWindow
= nil;
103 winOptions
: TUITopWindow
= nil;
104 winLayers
: TUITopWindow
= nil;
105 winOutlines
: TUITopWindow
= nil;
108 procedure createHelpWindow (); forward;
109 procedure createOptionsWindow (); forward;
110 procedure createLayersWindow (); forward;
111 procedure createOutlinesWindow (); forward;
114 procedure toggleLayersWindowCB (me
: TUIControl
);
116 showLayersWindow
:= not showLayersWindow
;
117 if showLayersWindow
then
119 if (winLayers
= nil) then createLayersWindow();
120 uiAddWindow(winLayers
);
124 uiRemoveWindow(winLayers
);
128 procedure toggleOutlineWindowCB (me
: TUIControl
);
130 showOutlineWindow
:= not showOutlineWindow
;
131 if showOutlineWindow
then
133 if (winOutlines
= nil) then createOutlinesWindow();
134 uiAddWindow(winOutlines
);
138 uiRemoveWindow(winOutlines
);
143 procedure createHelpWindow ();
144 procedure addHelpEmptyLine ();
148 stx
:= TUIStaticText
.Create();
149 stx
.flExpand
:= true;
150 stx
.halign
:= 0; // center
154 winHelp
.appendChild(stx
);
157 procedure addHelpCaptionLine (const txt
: AnsiString);
161 stx
:= TUIStaticText
.Create();
162 stx
.flExpand
:= true;
163 stx
.halign
:= 0; // center
167 winHelp
.appendChild(stx
);
170 procedure addHelpCaption (const txt
: AnsiString);
174 stx
:= TUIStaticText
.Create();
175 stx
.flExpand
:= true;
176 stx
.halign
:= 0; // center
180 winHelp
.appendChild(stx
);
183 procedure addHelpKeyMouse (const key
, txt
, grp
: AnsiString);
189 box
:= TUIHBox
.Create();
190 box
.flExpand
:= true;
192 stx
:= TUIStaticText
.Create();
193 stx
.flExpand
:= true;
194 stx
.halign
:= 1; // right
195 stx
.valign
:= 0; // center
200 box
.appendChild(stx
);
202 span
:= TUISpan
.Create();
203 span
.flDefaultSize
:= TLaySize
.Create(12, 1);
204 span
.flExpand
:= true;
205 box
.appendChild(span
);
207 stx
:= TUIStaticText
.Create();
208 stx
.flExpand
:= true;
209 stx
.halign
:= -1; // left
210 stx
.valign
:= 0; // center
214 box
.appendChild(stx
);
215 winHelp
.appendChild(box
);
218 procedure addHelpKey (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-keys'); end;
219 procedure addHelpMouse (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-mouse'); end;
222 slist
: array of AnsiString = nil;
224 bind
: THolmesBinding
;
232 winHelp
:= TUITopWindow
.Create('Holmes Help');
233 winHelp
.escClose
:= true;
234 winHelp
.flHoriz
:= false;
237 for cmd
in cmdlist
do cmd
.helpmark
:= false;
240 for bind
in keybinds
do
242 if (Length(bind
.key
) = 0) then continue
;
243 if cmdlist
.get(bind
.cmdName
, cmd
) then
245 if (Length(cmd
.help
) > 0) then
247 cmd
.helpmark
:= true;
248 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
253 for cmd
in cmdlist
do
255 if not cmd
.helpmark
then continue
;
256 if (Length(cmd
.help
) = 0) then begin cmd
.helpmark
:= false; continue
; end;
258 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
259 if (f
= Length(slist
)) then
261 SetLength(slist
, Length(slist
)+1);
262 slist
[High(slist
)] := cmd
.section
;
266 addHelpCaptionLine('KEYBOARD');
267 //llb := TUISimpleText.Create(0, 0);
268 for f
:= 0 to High(slist
) do
270 //if (f > 0) then llb.appendItem('');
271 if (f
> 0) then addHelpEmptyLine();
272 //llb.appendItem(slist[f], true, true);
273 addHelpCaption(slist
[f
]);
274 for cmd
in cmdlist
do
276 if not cmd
.helpmark
then continue
;
277 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
278 for bind
in keybinds
do
280 if (Length(bind
.key
) = 0) then continue
;
281 if (cmd
.name
= bind
.cmdName
) then
284 //while (Length(s) < maxkeylen) do s += ' ';
285 //s := ' '+s+' -- '+cmd.help;
287 addHelpMouse(bind
.key
, cmd
.help
);
294 for cmd
in cmdlist
do cmd
.helpmark
:= false;
297 for bind
in msbinds
do
299 if (Length(bind
.key
) = 0) then continue
;
300 if cmdlist
.get(bind
.cmdName
, cmd
) then
302 if (Length(cmd
.help
) > 0) then
304 cmd
.helpmark
:= true;
305 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
310 //llb.appendItem('');
311 //llb.appendItem('mouse', true, true);
312 if (f
> 0) then addHelpEmptyLine();
313 addHelpCaptionLine('MOUSE');
314 for bind
in msbinds
do
316 if (Length(bind
.key
) = 0) then continue
;
317 if cmdlist
.get(bind
.cmdName
, cmd
) then
319 if (Length(cmd
.help
) > 0) then
322 //while (Length(s) < maxkeylen) do s += ' ';
323 //s := ' '+s+' -- '+cmd.help;
325 addHelpKey(bind
.key
, cmd
.help
);
330 //winHelp.appendChild(llb);
332 uiLayoutCtl(winHelp
);
333 winHelp
.escClose
:= true;
334 winHelp
.centerInScreen();
338 procedure winLayersClosed (me
: TUIControl
); begin showLayersWindow
:= false; end;
339 procedure winOutlinesClosed (me
: TUIControl
); begin showOutlineWindow
:= false; end;
341 procedure addCheckBox (parent
: TUIControl
; const text: AnsiString; pvar
: PBoolean; const aid
: AnsiString='');
345 cb
:= TUICheckBox
.Create();
350 parent
.appendChild(cb
);
353 procedure addButton (parent
: TUIControl
; const text: AnsiString; cb
: TUIControl
.TActionCB
);
357 but
:= TUIButton
.Create();
358 //but.flExpand := true;
361 parent
.appendChild(but
);
365 procedure actionFillWalls (cb
: TUIControl
);
367 TUICheckBox(cb
).checked
:= not TUICheckBox(cb
).checked
;
368 TUICheckBox(cb
.topLevel
['cbcontour']).enabled
:= not TUICheckBox(cb
).checked
;
371 procedure createLayersWindow ();
375 winLayers
:= TUITopWindow
.Create('layers');
376 winLayers
.flHoriz
:= false;
379 winLayers
.flHoriz
:= false;
380 winLayers
.escClose
:= true;
381 winLayers
.closeCB
:= winLayersClosed
;
383 box
:= TUIVBox
.Create();
384 addCheckBox(box
, '~background', @g_rlayer_back
);
385 addCheckBox(box
, '~steps', @g_rlayer_step
);
386 addCheckBox(box
, '~walls', @g_rlayer_wall
);
387 addCheckBox(box
, '~doors', @g_rlayer_door
);
388 addCheckBox(box
, 'acid~1', @g_rlayer_acid1
);
389 addCheckBox(box
, 'acid~2', @g_rlayer_acid2
);
390 addCheckBox(box
, 'wate~r', @g_rlayer_water
);
391 addCheckBox(box
, '~foreground', @g_rlayer_fore
);
392 winLayers
.appendChild(box
);
394 uiLayoutCtl(winLayers
);
398 procedure createOutlinesWindow ();
402 winOutlines
:= TUITopWindow
.Create('outlines');
403 winOutlines
.flHoriz
:= false;
404 winOutlines
.x0
:= 100;
405 winOutlines
.y0
:= 30;
406 winOutlines
.flHoriz
:= false;
407 winOutlines
.escClose
:= true;
408 winOutlines
.closeCB
:= winOutlinesClosed
;
410 box
:= TUIVBox
.Create();
411 box
.hasFrame
:= true;
412 box
.caption
:= 'layers';
413 addCheckBox(box
, '~background', @g_ol_rlayer_back
);
414 addCheckBox(box
, '~steps', @g_ol_rlayer_step
);
415 addCheckBox(box
, '~walls', @g_ol_rlayer_wall
);
416 addCheckBox(box
, '~doors', @g_ol_rlayer_door
);
417 addCheckBox(box
, 'acid~1', @g_ol_rlayer_acid1
);
418 addCheckBox(box
, 'acid~2', @g_ol_rlayer_acid2
);
419 addCheckBox(box
, 'wate~r', @g_ol_rlayer_water
);
420 addCheckBox(box
, '~foreground', @g_ol_rlayer_fore
);
421 winOutlines
.appendChild(box
);
423 box
:= TUIVBox
.Create();
424 box
.hasFrame
:= true;
425 box
.caption
:= 'options';
426 addCheckBox(box
, 'fi~ll walls', @g_ol_fill_walls
, 'cbfill');
427 addCheckBox(box
, 'con~tours', @g_ol_nice
, 'cbcontour');
428 winOutlines
.appendChild(box
);
430 winOutlines
.setActionCBFor('cbfill', actionFillWalls
);
432 uiLayoutCtl(winOutlines
);
436 procedure createOptionsWindow ();
441 winOptions
:= TUITopWindow
.Create('Holmes Options');
442 winOptions
.flHoriz
:= false;
443 winOptions
.flHoriz
:= false;
444 winOptions
.escClose
:= true;
446 box
:= TUIVBox
.Create();
447 box
.hasFrame
:= true;
448 box
.caption
:= 'visual';
449 addCheckBox(box
, 'map ~grid', @showGrid
);
450 addCheckBox(box
, 'cursor ~position on map', @showMapCurPos
);
451 addCheckBox(box
, '~monster info', @showMonsInfo
);
452 addCheckBox(box
, 'monster LO~S to player', @showMonsLOS2Plr
);
453 addCheckBox(box
, 'monster ~cells (SLOW!)', @showAllMonsCells
);
454 addCheckBox(box
, 'draw ~triggers (SLOW!)', @showTriggers
);
455 winOptions
.appendChild(box
);
457 box
:= TUIHBox
.Create();
458 box
.hasFrame
:= true;
459 box
.caption
:= 'windows';
460 box
.captionAlign
:= 0;
462 addButton(box
, '~layers', toggleLayersWindowCB
);
463 span
:= TUISpan
.Create();
464 span
.flExpand
:= true;
465 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
466 box
.appendChild(span
);
467 addButton(box
, '~outline', toggleOutlineWindowCB
);
468 winOptions
.appendChild(box
);
470 uiLayoutCtl(winOptions
);
471 winOptions
.centerInScreen();
475 procedure toggleLayersWindow (arg
: Integer=-1);
477 if (arg
< 0) then showLayersWindow
:= not showLayersWindow
else showLayersWindow
:= (arg
> 0);
478 showLayersWindow
:= not showLayersWindow
; // hack for callback
479 toggleLayersWindowCB(nil);
482 procedure toggleOutlineWindow (arg
: Integer=-1);
484 if (arg
< 0) then showOutlineWindow
:= not showOutlineWindow
else showOutlineWindow
:= (arg
> 0);
485 showOutlineWindow
:= not showOutlineWindow
; // hack for callback
486 toggleOutlineWindowCB(nil);
489 procedure toggleHelpWindow (arg
: Integer=-1);
491 if (winHelp
= nil) then
493 if (arg
= 0) then exit
;
496 if (arg
< 0) then begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
); end
497 else if (arg
= 0) then begin if uiVisibleWindow(winHelp
) then uiRemoveWindow(winHelp
); end
498 else begin if (not uiVisibleWindow(winHelp
)) then uiAddWindow(winHelp
); end;
499 if (not uiVisibleWindow(winHelp
)) then FreeAndNil(winHelp
);
502 procedure toggleOptionsWindow (arg
: Integer=-1);
504 if (winOptions
= nil) then createOptionsWindow();
505 if (arg
< 0) then begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
); end
506 else if (arg
= 0) then begin if uiVisibleWindow(winOptions
) then uiRemoveWindow(winOptions
); end
507 else begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
); end
511 // ////////////////////////////////////////////////////////////////////////// //
513 vpSet
: Boolean = false;
516 laserSet
: Boolean = false;
517 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
518 monMarkedUID
: Integer = -1;
519 platMarkedGUID
: Integer = -1;
522 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
529 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
536 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
543 laserSet
:= laserSet
; // shut up, fpc!
547 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
548 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
551 {$IFDEF HOLMES_OLD_OUTLINES}
553 edgeBmp
: array of Byte = nil;
556 procedure drawOutlines ();
560 procedure clearEdgeBmp ();
562 SetLength(edgeBmp
, (gScreenWidth
+4)*(gScreenHeight
+4));
563 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
566 procedure drawPanel (pan
: TPanel
);
568 sx
, len
, y0
, y1
: Integer;
570 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
571 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
572 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
573 if g_ol_nice
or g_ol_fill_walls
then
577 if (len
> gScreenWidth
+4) then len
:= gScreenWidth
+4;
578 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
579 if (sx
+len
> gScreenWidth
+4) then len
:= gScreenWidth
+4-sx
;
580 if (len
< 1) then exit
;
582 assert(sx
+len
<= gScreenWidth
+4);
585 if (y0
< 0) then y0
:= 0;
586 if (y1
> gScreenHeight
+4) then y1
:= gScreenHeight
+4;
589 FillChar(edgeBmp
[y0
*(gScreenWidth
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
595 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
604 procedure flushLine ();
606 if (lsy
> 0) and (lsx
> 0) then
611 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
617 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
618 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
626 procedure startLine (y
: Integer);
632 procedure putPixel (x
: Integer);
634 if (x
< 1) then exit
;
635 if (lex
+1 <> x
) then flushLine();
636 if (lsx
< 0) then lsx
:= x
;
640 procedure drawEdges ();
646 glDisable(GL_TEXTURE_2D
);
649 glDisable(GL_LINE_SMOOTH
);
650 glDisable(GL_POLYGON_SMOOTH
);
651 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
654 a
:= @edgeBmp
[y
*(gScreenWidth
+4)+1];
660 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gScreenWidth
+4)] = 0) or (a
[gScreenWidth
+4] = 0) or
661 (a
[-(gScreenWidth
+4)-1] = 0) or (a
[-(gScreenWidth
+4)+1] = 0) or
662 (a
[gScreenWidth
+4-1] = 0) or (a
[gScreenWidth
+4+1] = 0) then
673 procedure drawFilledWalls ();
679 glDisable(GL_TEXTURE_2D
);
682 glDisable(GL_LINE_SMOOTH
);
683 glDisable(GL_POLYGON_SMOOTH
);
684 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
687 a
:= @edgeBmp
[y
*(gScreenWidth
+4)+1];
691 if (a
[0] <> 0) then putPixel(x
);
698 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
706 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
707 for f
:= 0 to High(parr
) do
710 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
711 if ((pan
.PanelType
and ptype
) = 0) then continue
;
714 if g_ol_nice
then drawEdges();
715 if g_ol_fill_walls
then drawFilledWalls();
721 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
723 result
:= false; // don't stop
724 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
725 if ((pan
.PanelType
and xptag
) = 0) then exit
;
729 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
735 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
736 else panelTypeToTag(ptype
);
737 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
738 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
739 if g_ol_nice
then drawEdges();
740 if g_ol_fill_walls
then drawFilledWalls();
744 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
745 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
746 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
747 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
748 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
749 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
750 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
751 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
756 oliner
: TOutliner
= nil;
758 procedure drawOutlines ();
762 procedure clearOliner ();
764 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
765 if (oliner
= nil) then oliner
:= TOutliner
.Create(vpw
+2, vph
+2) else oliner
.setup(vpw
+2, vph
+2);
768 procedure drawOutline (ol
: TOutliner
; sx
, sy
: Integer);
769 procedure xline (x0
, x1
, y
: Integer);
773 if (g_dbg_scale
< 1.0) then
776 for x
:= x0
to x1
do glVertex2f(sx
+x
+0.375, sy
+y
+0.375);
782 glVertex2f(sx
+x0
+0, sy
+y
+0);
783 glVertex2f(sx
+x1
+1, sy
+y
+0);
784 glVertex2f(sx
+x1
+1, sy
+y
+1);
785 glVertex2f(sx
+x0
+0, sy
+y
+1);
791 sp
: TOutliner
.TSpanX
;
793 if (ol
= nil) then exit
;
795 glDisable(GL_POINT_SMOOTH
);
796 for y
:= 0 to ol
.height
-1 do
798 for sp
in ol
.eachSpanAtY(y
) do
800 if (g_dbg_scale
<= 1.0) then
803 glVertex2f(sx
+sp
.x0
+0.375, sy
+y
+0.375);
804 glVertex2f(sx
+sp
.x1
+0.375, sy
+y
+0.375);
810 glVertex2f(sx
+sp
.x0
+0, sy
+y
+0);
811 glVertex2f(sx
+sp
.x0
+1, sy
+y
+0);
812 glVertex2f(sx
+sp
.x0
+1, sy
+y
+1);
813 glVertex2f(sx
+sp
.x0
+0, sy
+y
+1);
815 glVertex2f(sx
+sp
.x1
+0, sy
+y
+0);
816 glVertex2f(sx
+sp
.x1
+1, sy
+y
+0);
817 glVertex2f(sx
+sp
.x1
+1, sy
+y
+1);
818 glVertex2f(sx
+sp
.x1
+0, sy
+y
+1);
822 for sp
in ol
.eachSpanEdgeAtY(y
, -1) do
824 xline(sp
.x0
, sp
.x1
, y
);
827 glVertex2f(sx+sp.x0+0, sy+y+0);
828 glVertex2f(sx+sp.x1+1, sy+y+0);
829 glVertex2f(sx+sp.x1+1, sy+y+1);
830 glVertex2f(sx+sp.x0+0, sy+y+1);
834 for sp
in ol
.eachSpanEdgeAtY(y
, +1) do
836 xline(sp
.x0
, sp
.x1
, y
);
839 glVertex2f(sx+sp.x0+0, sy+y+0);
840 glVertex2f(sx+sp.x1+1, sy+y+0);
841 glVertex2f(sx+sp.x1+1, sy+y+1);
842 glVertex2f(sx+sp.x0+0, sy+y+1);
849 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
857 if g_ol_nice
then clearOliner();
858 hlmContext
.color
:= TGxRGBA
.Create(r
, g
, b
);
859 for f
:= 0 to High(parr
) do
862 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
863 if ((pan
.PanelType
and ptype
) = 0) then continue
;
864 if (pan
.X
> vpx
+vpw
+41) or (pan
.Y
> vpy
+vph
+41) then continue
;
865 if (pan
.X
+pan
.Width
< vpx
-41) then continue
;
866 if (pan
.Y
+pan
.Height
< vpy
-41) then continue
;
869 oliner
.addRect(pan
.X
-(vpx
+1), pan
.Y
-(vpy
+1), pan
.Width
, pan
.Height
);
871 if g_ol_fill_walls
then
873 hlmContext
.fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
875 else if not g_ol_nice
then
877 hlmContext
.rect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
882 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
883 drawOutline(oliner
, vpx
+1, vpy
+1);
888 if (vpw
< 2) or (vph
< 2) then exit
;
889 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
890 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
891 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
892 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
893 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
894 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
895 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
896 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
901 procedure plrDebugDraw ();
902 procedure drawTileGrid ();
906 hlmContext
.color
:= TGxRGBA
.Create(96, 96, 96);
907 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
909 hlmContext
.line(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
);
912 hlmContext
.color
:= TGxRGBA
.Create(96, 96, 96);
913 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
915 hlmContext
.line(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
);
919 procedure drawAwakeCells ();
923 hlmContext
.color
:= TGxRGBA
.Create(128, 0, 128, 64);
924 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
926 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
928 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
930 hlmContext
.fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
);
936 procedure drawTraceBox ();
939 px
, py
, pw
, ph
: Integer;
944 if (Length(gPlayers
) < 1) then exit
;
946 if (plr
= nil) then exit
;
947 plr
.getMapBox(px
, py
, pw
, ph
);
948 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 200);
949 hlmContext
.rect(px
, py
, pw
, ph
);
950 pdx
:= pmsCurMapX
-(px
+pw
div 2);
951 pdy
:= pmsCurMapY
-(py
+ph
div 2);
952 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 200);
953 hlmContext
.line(px
+pw
div 2, py
+ph
div 2, px
+pw
div 2+pdx
, py
+ph
div 2+pdy
);
954 pan
:= mapGrid
.traceBox(ex
, ey
, px
, py
, pw
, ph
, pdx
, pdy
, GridTagObstacle
);
957 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 255, 180);
958 hlmContext
.rect(px
+pdx
, py
+pdy
, pw
, ph
);
962 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 180);
963 hlmContext
.rect(px
+pdx
, py
+pdy
, pw
, ph
);
965 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0, 180);
966 hlmContext
.rect(ex
, ey
, pw
, ph
);
969 procedure hilightCell (cx
, cy
: Integer);
971 hlmContext
.color
:= TGxRGBA
.Create(0, 128, 0, 64);
972 hlmContext
.fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
);
975 procedure hilightBodyCells (proxyId
: Integer);
978 pcellxy
: PGridCellCoord
;
980 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
981 it
:= monsGrid
.forEachBodyCell(proxyId
);
982 for pcellxy
in it
do hilightCell(pcellxy
^.x
, pcellxy
^.y
);
986 procedure hilightCell1 (cx
, cy
: Integer);
988 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
989 cx
:= cx
and (not (monsGrid
.tileSize
-1));
990 cy
:= cy
and (not (monsGrid
.tileSize
-1));
991 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 92);
992 hlmContext
.fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
);
995 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
997 result
:= false; // don't stop
998 if (pan
= nil) then exit
; // cell completion, ignore
999 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
1000 hlmContext
.color
:= TGxRGBA
.Create(0, 128, 128, 64);
1001 hlmContext
.fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
1004 procedure monsCollector (mon
: TMonster
);
1007 mx
, my
, mw
, mh
: Integer;
1009 mon
.getMapBox(mx
, my
, mw
, mh
);
1010 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 160);
1011 hlmContext
.rect(mx
, my
, mw
, mh
);
1012 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
1013 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
1015 //e_DrawPoint(8, ex, ey, 0, 255, 0);
1016 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0, 220);
1017 hlmContext
.fillRect(ex
-2, ey
-2, 7, 7);
1021 procedure drawMonsterInfo (mon
: TMonster
);
1023 mx
, my
, mw
, mh
: Integer;
1025 procedure drawMonsterTargetLine ();
1027 emx
, emy
, emw
, emh
: Integer;
1032 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
1034 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
1035 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1037 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
1039 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
1040 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1046 mon
.getMapBox(mx
, my
, mw
, mh
);
1047 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0);
1048 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2);
1049 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1051 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0);
1052 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, ex
, ey
);
1056 procedure drawLOS2Plr ();
1058 emx
, emy
, emw
, emh
: Integer;
1062 eplr
:= gPlayers
[0];
1063 if (eplr
= nil) then exit
;
1064 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1065 mon
.getMapBox(mx
, my
, mw
, mh
);
1066 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0);
1067 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2);
1068 {$IF DEFINED(D2F_DEBUG)}
1069 mapGrid
.dbgRayTraceTileHitCB
:= hilightCell1
;
1071 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1072 //if (mapGrid.traceRay(ex, ey, mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, hilightWallTrc, (GridTagWall or GridTagDoor)) <> nil) then
1074 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0);
1075 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, ex
, ey
);
1077 {$IF DEFINED(D2F_DEBUG)}
1078 mapGrid
.dbgRayTraceTileHitCB
:= nil;
1083 if (mon
= nil) then exit
;
1084 mon
.getMapBox(mx
, my
, mw
, mh
);
1087 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1088 hilightBodyCells(mon
.proxyId
);
1090 if showMonsInfo
then
1092 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1093 hlmContext
.font
:= 'msx6';
1094 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0);
1096 hlmContext
.darkenRect(mx
-4, my
-7*hlmContext
.charWidth(' ')-6, 110, 7*hlmContext
.charWidth(' ')+6, 128);
1101 hlmContext
.drawText(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
])); my
-= hlmContext
.charWidth(' ');
1103 hlmContext
.drawText(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)])); my
-= hlmContext
.charWidth(' ');
1105 hlmContext
.drawText(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
])); my
-= hlmContext
.charWidth(' ');
1107 hlmContext
.drawText(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
])); my
-= hlmContext
.charWidth(' ');
1109 hlmContext
.drawText(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
])); my
-= hlmContext
.charWidth(' ');
1111 hlmContext
.drawText(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
])); my
-= hlmContext
.charWidth(' ');
1112 hlmContext
.drawText(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
])); my
-= hlmContext
.charWidth(' ');
1115 drawMonsterTargetLine();
1116 if showMonsLOS2Plr
then drawLOS2Plr();
1118 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1119 property MonsterPain: Integer read FPain write FPain;
1120 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1124 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1126 result
:= false; // don't stop
1127 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1128 hilightBodyCells(mon
.proxyId
);
1131 procedure drawSelectedPlatformCells ();
1135 if not showGrid
then exit
;
1136 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1137 if (pan
= nil) then exit
;
1138 //mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
1139 hilightBodyCells(pan
.proxyId
);
1140 hlmContext
.color
:= TGxRGBA
.Create(0, 200, 0, 200);
1141 hlmContext
.rect(pan
.x
, pan
.y
, pan
.width
, pan
.height
);
1144 procedure drawTrigger (var trig
: TTrigger
);
1146 procedure drawPanelDest (pguid
: Integer);
1150 pan
:= g_Map_PanelByGUID(pguid
);
1151 if (pan
= nil) then exit
;
1152 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 220);
1153 hlmContext
.line(trig
.trigCenter
.x
, trig
.trigCenter
.y
, pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2);
1160 hlmContext
.font
:= 'msx6';
1161 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 96);
1162 hlmContext
.fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
);
1163 tts
:= trigType2Str(trig
.TriggerType
);
1164 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1165 hlmContext
.darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1166 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0);
1167 hlmContext
.drawText(tx
, trig
.y
-9, tts
);
1168 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1169 hlmContext
.darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1170 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0);
1171 hlmContext
.drawText(tx
, trig
.y
-19, trig
.mapId
);
1172 drawPanelDest(trig
.trigPanelGUID
);
1173 case trig
.TriggerType
of
1174 TRIGGER_NONE
: begin end;
1175 TRIGGER_EXIT
: begin end;
1176 TRIGGER_TELEPORT
: begin end;
1177 TRIGGER_OPENDOOR
: begin end;
1178 TRIGGER_CLOSEDOOR
: begin end;
1179 TRIGGER_DOOR
: begin end;
1180 TRIGGER_DOOR5
: begin end;
1181 TRIGGER_CLOSETRAP
: begin end;
1182 TRIGGER_TRAP
: begin end;
1183 TRIGGER_SECRET
: begin end;
1184 TRIGGER_LIFTUP
: begin end;
1185 TRIGGER_LIFTDOWN
: begin end;
1186 TRIGGER_LIFT
: begin end;
1187 TRIGGER_TEXTURE
: begin end;
1188 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1190 if (trig
.trigDataRec
.trigTWidth
> 0) and (trig
.trigDataRec
.trigTHeight
> 0) then
1192 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 255, 42);
1193 hlmContext
.fillRect(
1194 trig
.trigDataRec
.trigTX
, trig
.trigDataRec
.trigTY
,
1195 trig
.trigDataRec
.trigTWidth
, trig
.trigDataRec
.trigTHeight
);
1196 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 220);
1198 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1199 trig
.trigDataRec
.trigTX
+trig
.trigDataRec
.trigTWidth
div 2,
1200 trig
.trigDataRec
.trigTY
+trig
.trigDataRec
.trigTHeight
div 2);
1203 TRIGGER_SOUND
: begin end;
1204 TRIGGER_SPAWNMONSTER
: begin end;
1205 TRIGGER_SPAWNITEM
: begin end;
1206 TRIGGER_MUSIC
: begin end;
1207 TRIGGER_PUSH
: begin end;
1208 TRIGGER_SCORE
: begin end;
1209 TRIGGER_MESSAGE
: begin end;
1210 TRIGGER_DAMAGE
: begin end;
1211 TRIGGER_HEALTH
: begin end;
1212 TRIGGER_SHOT
: begin end;
1213 TRIGGER_EFFECT
: begin end;
1214 TRIGGER_SCRIPT
: begin end;
1217 //trigPanelId: Integer;
1220 procedure drawTriggers ();
1224 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1227 procedure drawGibsBoxes ();
1230 px
, py
, pw
, ph
: Integer;
1233 for f
:= 0 to High(gGibs
) do
1238 gib
.getMapBox(px
, py
, pw
, ph
);
1239 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255);
1240 hlmContext
.rect(px
, py
, pw
, ph
);
1248 it
: TMonsterGrid
.Iter
;
1249 mx
, my
, mw
, mh
: Integer;
1255 if (gPlayer1
= nil) then exit
;
1257 if (hlmContext
= nil) then hlmContext
:= TGxContext
.Create();
1259 gxSetContext(hlmContext
);
1261 //glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, vpw, vph);
1262 //hlmContext.clip := TGxRect.Create(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1265 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
1266 glTranslatef(-vpx, -vpy, 0);
1268 hlmContext
.glSetScaleTrans(g_dbg_scale
, -vpx
, -vpy
);
1269 glEnable(GL_SCISSOR_TEST
);
1270 glScissor(0, gScreenHeight
-gPlayerScreenSize
.Y
-1, gPlayerScreenSize
.X
, gPlayerScreenSize
.Y
);
1272 if (showGrid
) then drawTileGrid();
1277 //g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
1278 it
:= monsGrid
.forEachAlongLine(laserX0
, laserY0
, laserX1
, laserY1
, -1, true);
1279 for mit
in it
do monsCollector(mit
^);
1283 if (monMarkedUID
<> -1) then
1285 mon
:= g_Monsters_ByUID(monMarkedUID
);
1286 if (mon
<> nil) then
1288 mon
.getMapBox(mx
, my
, mw
, mh
);
1289 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
1290 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0, 220);
1291 hlmContext
.rect(mx
, my
, mw
, mh
);
1292 drawMonsterInfo(mon
);
1296 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1297 if showTriggers
then drawTriggers();
1298 if showGrid
then drawSelectedPlatformCells();
1302 if showTraceBox
then drawTraceBox();
1307 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1309 {$IF DEFINED(D2F_DEBUG)}
1310 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1312 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1313 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1314 {$IF DEFINED(D2F_DEBUG)}
1315 mapGrid.dbgRayTraceTileHitCB := nil;
1318 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1319 if (pan <> nil) then writeln('hit!');
1326 if showMapCurPos
then
1328 s
:= Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]);
1329 gxSetContext(hlmContext
);
1330 hlmContext
.font
:= 'win8';
1331 hlmContext
.color
:= TGxRGBA
.Create(0, 0, 0);
1332 for dy
:= -1 to 1 do
1334 for dx
:= -1 to 1 do
1336 if (dx
<> 0) or (dy
<> 0) then hlmContext
.drawText(4+dx
, gScreenHeight
-10+dy
, s
);
1339 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0);
1340 hlmContext
.drawText(4, gScreenHeight
-10, s
);
1346 // ////////////////////////////////////////////////////////////////////////// //
1347 procedure onKeyEvent (var ev
: TFUIEvent
);
1348 {$IF DEFINED(D2F_DEBUG)}
1355 procedure dummyWallTrc (cx
, cy
: Integer);
1363 {$IF DEFINED(D2F_DEBUG)}
1364 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1365 if ((ev
.scan
= SDL_SCANCODE_UP
) or (ev
.scan
= SDL_SCANCODE_DOWN
) or (ev
.scan
= SDL_SCANCODE_LEFT
) or (ev
.scan
= SDL_SCANCODE_RIGHT
)) and
1366 ((ev
.kstate
and TFUIEvent
.ModCtrl
) <> 0) then
1372 SDL_SCANCODE_UP
: dy
-= 120;
1373 SDL_SCANCODE_DOWN
: dy
+= 120;
1374 SDL_SCANCODE_LEFT
: dx
-= 120;
1375 SDL_SCANCODE_RIGHT
: dx
+= 120;
1377 {$IF DEFINED(D2F_DEBUG)}
1378 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1379 mapGrid
.dbgShowTraceLog
:= true;
1381 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1382 {$IF DEFINED(D2F_DEBUG)}
1383 //mapGrid.dbgRayTraceTileHitCB := nil;
1384 mapGrid
.dbgShowTraceLog
:= false;
1386 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1394 // ////////////////////////////////////////////////////////////////////////// //
1395 procedure g_Holmes_OnEvent (var ev
: TFUIEvent
);
1396 {$IF not DEFINED(HEADLESS)}
1398 doeat
: Boolean = false;
1401 {$IF not DEFINED(HEADLESS)}
1402 if g_Game_IsNet
then exit
;
1403 if not g_holmes_enabled
then exit
;
1404 if g_holmes_imfunctional
then exit
;
1406 holmesInitCommands();
1415 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1416 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1417 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1421 else if (ev
.mouse
) then
1430 uiDispatchEvent(ev
);
1431 if (not ev
.alive
) then exit
;
1435 if (gPlayer1
<> nil) and (vpSet
) then msbindExecute(ev
);
1440 if keybindExecute(ev
) then ev
.eat();
1441 if (ev
.alive
) then onKeyEvent(ev
);
1444 if (doeat
) then ev
.eat();
1449 // ////////////////////////////////////////////////////////////////////////// //
1450 procedure g_Holmes_Draw ();
1452 if g_Game_IsNet
then exit
;
1453 if not g_holmes_enabled
then exit
;
1454 if g_holmes_imfunctional
then exit
;
1456 {$IF not DEFINED(HEADLESS)}
1457 holmesInitCommands();
1460 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1461 glDisable(GL_STENCIL_TEST
);
1462 glDisable(GL_BLEND
);
1463 glDisable(GL_SCISSOR_TEST
);
1464 glDisable(GL_TEXTURE_2D
);
1466 if gGameOn
then plrDebugDraw();
1473 procedure g_Holmes_DrawUI ();
1475 if g_Game_IsNet
then exit
;
1476 if not g_holmes_enabled
then exit
;
1477 if g_holmes_imfunctional
then exit
;
1479 {$IF not DEFINED(HEADLESS)}
1480 gGfxDoClear
:= false;
1481 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1483 glMatrixMode(GL_MODELVIEW
);
1487 if assigned(postrenderFrameCB
) then postrenderFrameCB();
1495 // ////////////////////////////////////////////////////////////////////////// //
1496 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1497 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1498 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1500 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1501 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1502 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1503 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1505 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1506 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1508 procedure bcMonsterSpawn (s
: AnsiString);
1512 if not gGameOn
or g_Game_IsClient
then
1514 conwriteln('cannot spawn monster in this mode');
1517 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1518 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1519 monMarkedUID
:= mon
.UID
;
1522 procedure bcMonsterWakeup ();
1526 if (monMarkedUID
<> -1) then
1528 mon
:= g_Monsters_ByUID(monMarkedUID
);
1529 if (mon
<> nil) then mon
.WakeUp();
1533 procedure bcPlayerTeleport ();
1535 x
, y
, w
, h
: Integer;
1537 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1538 if (gPlayers
[0] <> nil) then
1540 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1541 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1545 procedure dbgToggleTraceBox (arg
: Integer=-1); begin if (arg
< 0) then showTraceBox
:= not showTraceBox
else showTraceBox
:= (arg
> 0); end;
1547 procedure dbgToggleHolmesPause (arg
: Integer=-1); begin if (arg
< 0) then g_Game_HolmesPause(not gPauseHolmes
) else g_Game_HolmesPause(arg
> 0); end;
1549 procedure cbAtcurSelectMonster ();
1550 function monsAtDump (mon
: TMonster
{; tag: Integer}): Boolean;
1552 result
:= true; // stop
1553 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1554 monMarkedUID
:= mon
.UID
;
1555 dumpPublishedProperties(mon
);
1559 x
, y
, w
, h
: Integer;
1561 it
: TMonsterGrid
.Iter
;
1564 if (Length(gPlayers
) > 0) then
1567 if (plr
<> nil) then
1569 plr
.getMapBox(x
, y
, w
, h
);
1570 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1572 dumpPublishedProperties(plr
);
1576 //e_WriteLog('===========================', MSG_NOTIFY);
1577 it
:= monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
);
1578 for mit
in it
do monsAtDump(mit
^);
1580 //e_WriteLog('---------------------------', MSG_NOTIFY);
1583 procedure cbAtcurDumpMonsters ();
1584 function monsAtDump (mon
: TMonster
{; tag: Integer}): Boolean;
1586 result
:= false; // don't stop
1587 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1591 it
: TMonsterGrid
.Iter
;
1593 it
:= monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
);
1594 if (it
.length
> 0) then
1596 e_WriteLog('===========================', TMsgType
.Notify
);
1597 for mit
in it
do monsAtDump(mit
^);
1598 e_WriteLog('---------------------------', TMsgType
.Notify
);
1603 procedure cbAtcurDumpWalls ();
1604 function wallToggle (pan
: TPanel
{; tag: Integer}): Boolean;
1606 result
:= false; // don't stop
1607 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1608 e_LogWritefln('wall ''%s'' #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan
.mapId
, pan
.arrIdx
, pan
.proxyId
, Integer(pan
.Enabled
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
]), pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
]);
1609 dumpPublishedProperties(pan
);
1612 hasTrigs
: Boolean = false;
1616 it
: TPanelGrid
.Iter
;
1618 platMarkedGUID
:= -1;
1619 it
:= mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, (GridTagWall
or GridTagDoor
));
1620 if (it
.length
> 0) then
1622 e_WriteLog('=== TOGGLE WALL ===', TMsgType
.Notify
);
1623 for mwit
in it
do wallToggle(mwit
^);
1624 e_WriteLog('--- toggle wall ---', TMsgType
.Notify
);
1627 if showTriggers
then
1629 for f
:= 0 to High(gTriggers
) do
1631 trig
:= @gTriggers
[f
];
1632 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1634 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1635 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1638 if hasTrigs
then writeln('--- triggers ---');
1642 procedure cbAtcurToggleWalls ();
1643 function wallToggle (pan
: TPanel
{; tag: Integer}): Boolean;
1645 result
:= false; // don't stop
1646 //e_WriteLog(Format('wall #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.X, pan.Y, pan.Width, pan.Height]), MSG_NOTIFY);
1647 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1651 it
: TPanelGrid
.Iter
;
1653 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1654 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1655 it
:= mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, (GridTagWall
or GridTagDoor
));
1656 for mwit
in it
do wallToggle(mwit
^);
1661 // ////////////////////////////////////////////////////////////////////////// //
1662 procedure holmesInitCommands ();
1664 if (cmdlist
<> nil) then exit
;
1665 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1666 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1667 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1668 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1670 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1671 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1672 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1673 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1674 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'wake up selected monster', 'monster control');
1676 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1678 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1679 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1681 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1683 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1684 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1685 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1687 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1688 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1689 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1690 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1692 cmdAdd('dbg_tracebox', dbgToggleTraceBox
, 'test traceBox()', 'player control');
1694 cmdAdd('hlm_pause', dbgToggleHolmesPause
, '"Holmes" pause mode', 'game control');
1698 procedure holmesInitBinds ();
1701 pr
: TTextParser
= nil;
1702 s
, kn
, v
: AnsiString;
1707 if not keybindsInited
then
1710 keybindAdd('F1', 'win_help');
1711 keybindAdd('M-F1', 'win_options');
1712 keybindAdd('C-O', 'win_outline');
1713 keybindAdd('C-L', 'win_layers');
1715 keybindAdd('M-M', 'mon_think_step');
1716 keybindAdd('M-I', 'mon_info');
1717 keybindAdd('M-L', 'mon_los_plr');
1718 keybindAdd('M-G', 'mon_cells');
1719 keybindAdd('M-A', 'mon_wakeup');
1721 keybindAdd('M-P', 'mplat_step');
1722 keybindAdd('M-O', 'mplat_toggle');
1724 keybindAdd('C-T', 'plr_teleport');
1725 keybindAdd('M-T', 'dbg_tracebox');
1727 keybindAdd('C-P', 'dbg_curpos');
1728 keybindAdd('C-G', 'dbg_grid');
1729 keybindAdd('C-X', 'dbg_triggers');
1731 keybindAdd('C-1', 'mon_spawn zombie');
1733 keybindAdd('C-S-P', 'hlm_pause');
1736 msbindAdd('LMB', 'atcur_select_monster');
1737 msbindAdd('M-LMB', 'atcur_dump_monsters');
1738 msbindAdd('RMB', 'atcur_dump_walls');
1739 msbindAdd('M-RMB', 'atcur_disable_walls');
1741 // load bindings from file
1743 st
:= e_OpenResourceRO(ConfigDirs
, 'holmes.rc');
1744 pr
:= TFileTextParser
.Create(st
);
1745 conwriteln('parsing "holmes.rc"...');
1746 while (pr
.tokType
<> pr
.TTEOF
) do
1749 if (s
= 'stop') then break
1750 else if (s
= 'unbind_keys') then keybinds
:= nil
1751 else if (s
= 'unbind_mouse') then msbinds
:= nil
1752 else if (s
= 'bind') then
1754 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1755 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1756 else s
:= pr
.expectId();
1758 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1759 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1760 else v
:= pr
.expectId();
1762 kn
:= parseModKeys(s
, kmods
, mbuts
);
1763 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1773 except on e
: Exception
do // sorry
1774 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1776 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1786 fuiEventCB
:= g_Holmes_OnEvent
;
1787 //uiContext.font := 'win14';
1789 conRegVar('hlm_ui_scale', @fuiRenderScale
, 0.01, 5.0, 'Holmes UI scale', '', false);