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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF} geom
,
24 g_textures
, g_basic
, e_graphics
, g_phys
, g_grid
, g_player
, g_monsters
,
25 g_window
, g_map
, g_triggers
, g_items
, g_game
, g_panel
, g_console
, g_gfx
,
27 sdlcarcass
, glgfx
, gh_ui_common
, gh_ui
;
30 procedure g_Holmes_Draw ();
31 procedure g_Holmes_DrawUI ();
33 procedure g_Holmes_MouseEvent (var ev
: THMouseEvent
);
34 procedure g_Holmes_KeyEvent (var ev
: THKeyEvent
);
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_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
49 {rttiobj,} typinfo
, e_texture
,
50 SysUtils
, Classes
, GL
, SDL2
,
51 MAPDEF
, g_main
, g_options
,
52 utils
, hashtable
, xparser
;
56 //globalInited: Boolean = false;
59 msB
: Word = 0; // button state
60 kbS
: Word = 0; // keyboard modifiers state
61 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
62 showMonsInfo
: Boolean = false;
63 showMonsLOS2Plr
: Boolean = false;
64 showAllMonsCells
: Boolean = false;
65 showMapCurPos
: Boolean = false;
66 showLayersWindow
: Boolean = false;
67 showOutlineWindow
: Boolean = false;
68 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
69 showTraceBox
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
72 // ////////////////////////////////////////////////////////////////////////// //
73 {$INCLUDE g_holmes.inc}
74 {$INCLUDE g_holmes_ol.inc} // outliner
77 // ////////////////////////////////////////////////////////////////////////// //
78 {$INCLUDE g_holmes_cmd.inc}
79 procedure holmesInitCommands (); forward;
80 procedure holmesInitBinds (); forward;
83 // ////////////////////////////////////////////////////////////////////////// //
85 g_ol_nice
: Boolean = false;
86 g_ol_fill_walls
: Boolean = false;
87 g_ol_rlayer_back
: Boolean = false;
88 g_ol_rlayer_step
: Boolean = false;
89 g_ol_rlayer_wall
: Boolean = false;
90 g_ol_rlayer_door
: Boolean = false;
91 g_ol_rlayer_acid1
: Boolean = false;
92 g_ol_rlayer_acid2
: Boolean = false;
93 g_ol_rlayer_water
: Boolean = false;
94 g_ol_rlayer_fore
: Boolean = false;
97 // ////////////////////////////////////////////////////////////////////////// //
99 winHelp
: TUITopWindow
= nil;
100 winOptions
: TUITopWindow
= nil;
101 winLayers
: TUITopWindow
= nil;
102 winOutlines
: TUITopWindow
= nil;
105 procedure createHelpWindow (); forward;
106 procedure createOptionsWindow (); forward;
107 procedure createLayersWindow (); forward;
108 procedure createOutlinesWindow (); forward;
111 procedure toggleLayersWindowCB (me
: TUIControl
);
113 showLayersWindow
:= not showLayersWindow
;
114 if showLayersWindow
then
116 if (winLayers
= nil) then createLayersWindow();
117 uiAddWindow(winLayers
);
121 uiRemoveWindow(winLayers
);
125 procedure toggleOutlineWindowCB (me
: TUIControl
);
127 showOutlineWindow
:= not showOutlineWindow
;
128 if showOutlineWindow
then
130 if (winOutlines
= nil) then createOutlinesWindow();
131 uiAddWindow(winOutlines
);
135 uiRemoveWindow(winOutlines
);
140 procedure createHelpWindow ();
141 procedure addHelpEmptyLine ();
145 stx
:= TUIStaticText
.Create();
146 stx
.flExpand
:= true;
147 stx
.halign
:= 0; // center
151 winHelp
.appendChild(stx
);
154 procedure addHelpCaptionLine (const txt
: AnsiString);
158 stx
:= TUIStaticText
.Create();
159 stx
.flExpand
:= true;
160 stx
.halign
:= 0; // center
164 winHelp
.appendChild(stx
);
167 procedure addHelpCaption (const txt
: AnsiString);
171 stx
:= TUIStaticText
.Create();
172 stx
.flExpand
:= true;
173 stx
.halign
:= 0; // center
177 winHelp
.appendChild(stx
);
180 procedure addHelpKeyMouse (const key
, txt
, grp
: AnsiString);
186 box
:= TUIHBox
.Create();
187 box
.flExpand
:= true;
189 stx
:= TUIStaticText
.Create();
190 stx
.flExpand
:= true;
191 stx
.halign
:= 1; // right
192 stx
.valign
:= 0; // center
197 box
.appendChild(stx
);
199 span
:= TUISpan
.Create();
200 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
201 span
.flExpand
:= true;
202 box
.appendChild(span
);
204 stx
:= TUIStaticText
.Create();
205 stx
.flExpand
:= true;
206 stx
.halign
:= -1; // left
207 stx
.valign
:= 0; // center
211 box
.appendChild(stx
);
212 winHelp
.appendChild(box
);
215 procedure addHelpKey (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-keys'); end;
216 procedure addHelpMouse (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-mouse'); end;
219 slist
: array of AnsiString = nil;
221 bind
: THolmesBinding
;
229 winHelp
:= TUITopWindow
.Create('Holmes Help');
230 winHelp
.escClose
:= true;
231 winHelp
.flHoriz
:= false;
234 for cmd
in cmdlist
do cmd
.helpmark
:= false;
237 for bind
in keybinds
do
239 if (Length(bind
.key
) = 0) then continue
;
240 if cmdlist
.get(bind
.cmdName
, cmd
) then
242 if (Length(cmd
.help
) > 0) then
244 cmd
.helpmark
:= true;
245 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
250 for cmd
in cmdlist
do
252 if not cmd
.helpmark
then continue
;
253 if (Length(cmd
.help
) = 0) then begin cmd
.helpmark
:= false; continue
; end;
255 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
256 if (f
= Length(slist
)) then
258 SetLength(slist
, Length(slist
)+1);
259 slist
[High(slist
)] := cmd
.section
;
263 addHelpCaptionLine('KEYBOARD');
264 //llb := TUISimpleText.Create(0, 0);
265 for f
:= 0 to High(slist
) do
267 //if (f > 0) then llb.appendItem('');
268 if (f
> 0) then addHelpEmptyLine();
269 //llb.appendItem(slist[f], true, true);
270 addHelpCaption(slist
[f
]);
271 for cmd
in cmdlist
do
273 if not cmd
.helpmark
then continue
;
274 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
275 for bind
in keybinds
do
277 if (Length(bind
.key
) = 0) then continue
;
278 if (cmd
.name
= bind
.cmdName
) then
281 //while (Length(s) < maxkeylen) do s += ' ';
282 //s := ' '+s+' -- '+cmd.help;
284 addHelpMouse(bind
.key
, cmd
.help
);
291 for cmd
in cmdlist
do cmd
.helpmark
:= false;
294 for bind
in msbinds
do
296 if (Length(bind
.key
) = 0) then continue
;
297 if cmdlist
.get(bind
.cmdName
, cmd
) then
299 if (Length(cmd
.help
) > 0) then
301 cmd
.helpmark
:= true;
302 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
307 //llb.appendItem('');
308 //llb.appendItem('mouse', true, true);
309 if (f
> 0) then addHelpEmptyLine();
310 addHelpCaptionLine('MOUSE');
311 for bind
in msbinds
do
313 if (Length(bind
.key
) = 0) then continue
;
314 if cmdlist
.get(bind
.cmdName
, cmd
) then
316 if (Length(cmd
.help
) > 0) then
319 //while (Length(s) < maxkeylen) do s += ' ';
320 //s := ' '+s+' -- '+cmd.help;
322 addHelpKey(bind
.key
, cmd
.help
);
327 //winHelp.appendChild(llb);
329 winHelp
.flMaxSize
:= TLaySize
.Create(trunc(getScrWdt
/gh_ui_scale
), trunc(getScrHgt
/gh_ui_scale
));
330 uiLayoutCtl(winHelp
);
331 winHelp
.centerInScreen();
335 procedure winLayersClosed (me
: TUIControl
); begin showLayersWindow
:= false; end;
336 procedure winOutlinesClosed (me
: TUIControl
); begin showOutlineWindow
:= false; end;
338 procedure addCheckBox (parent
: TUIControl
; const text: AnsiString; pvar
: PBoolean);
342 cb
:= TUICheckBox
.Create();
346 parent
.appendChild(cb
);
349 procedure addButton (parent
: TUIControl
; const text: AnsiString; cb
: TUIControl
.TActionCB
);
353 but
:= TUIButton
.Create();
354 //but.flExpand := true;
357 parent
.appendChild(but
);
361 procedure createLayersWindow ();
365 winLayers
:= TUITopWindow
.Create('layers');
368 winLayers
.flHoriz
:= false;
369 winLayers
.escClose
:= true;
370 winLayers
.closeCB
:= winLayersClosed
;
372 box
:= TUIVBox
.Create();
373 addCheckBox(box
, '~background', @g_rlayer_back
);
374 addCheckBox(box
, '~steps', @g_rlayer_step
);
375 addCheckBox(box
, '~walls', @g_rlayer_wall
);
376 addCheckBox(box
, '~doors', @g_rlayer_door
);
377 addCheckBox(box
, 'acid~1', @g_rlayer_acid1
);
378 addCheckBox(box
, 'acid~2', @g_rlayer_acid2
);
379 addCheckBox(box
, 'wate~r', @g_rlayer_water
);
380 addCheckBox(box
, '~foreground', @g_rlayer_fore
);
381 winLayers
.appendChild(box
);
383 winLayers
.flMaxSize
:= TLaySize
.Create(trunc(getScrWdt
/gh_ui_scale
), trunc(getScrHgt
/gh_ui_scale
));
384 uiLayoutCtl(winLayers
);
388 procedure createOutlinesWindow ();
392 winOutlines
:= TUITopWindow
.Create('outlines');
393 winOutlines
.x0
:= 100;
394 winOutlines
.y0
:= 30;
395 winOutlines
.flHoriz
:= false;
396 winOutlines
.escClose
:= true;
397 winOutlines
.closeCB
:= winOutlinesClosed
;
399 box
:= TUIVBox
.Create();
400 box
.hasFrame
:= true;
401 box
.caption
:= 'layers';
402 addCheckBox(box
, '~background', @g_ol_rlayer_back
);
403 addCheckBox(box
, '~steps', @g_ol_rlayer_step
);
404 addCheckBox(box
, '~walls', @g_ol_rlayer_wall
);
405 addCheckBox(box
, '~doors', @g_ol_rlayer_door
);
406 addCheckBox(box
, 'acid~1', @g_ol_rlayer_acid1
);
407 addCheckBox(box
, 'acid~2', @g_ol_rlayer_acid2
);
408 addCheckBox(box
, 'wate~r', @g_ol_rlayer_water
);
409 addCheckBox(box
, '~foreground', @g_ol_rlayer_fore
);
410 winOutlines
.appendChild(box
);
412 box
:= TUIVBox
.Create();
413 box
.hasFrame
:= true;
414 box
.caption
:= 'options';
415 addCheckBox(box
, 'fi~ll walls', @g_ol_fill_walls
);
416 addCheckBox(box
, 'con~tours', @g_ol_nice
);
417 winOutlines
.appendChild(box
);
419 winOutlines
.flMaxSize
:= TLaySize
.Create(trunc(getScrWdt
/gh_ui_scale
), trunc(getScrHgt
/gh_ui_scale
));
420 uiLayoutCtl(winOutlines
);
424 procedure createOptionsWindow ();
429 winOptions
:= TUITopWindow
.Create('Holmes Options');
430 winOptions
.flHoriz
:= false;
431 winOptions
.escClose
:= true;
433 box
:= TUIVBox
.Create();
434 box
.hasFrame
:= true;
435 box
.caption
:= 'visual';
436 addCheckBox(box
, 'map ~grid', @showGrid
);
437 addCheckBox(box
, 'cursor ~position on map', @showMapCurPos
);
438 addCheckBox(box
, '~monster info', @showMonsInfo
);
439 addCheckBox(box
, 'monster LO~S to player', @showMonsLOS2Plr
);
440 addCheckBox(box
, 'monster ~cells (SLOW!)', @showAllMonsCells
);
441 addCheckBox(box
, 'draw ~triggers (SLOW!)', @showTriggers
);
442 winOptions
.appendChild(box
);
444 box
:= TUIHBox
.Create();
445 box
.hasFrame
:= true;
446 box
.caption
:= 'windows';
447 box
.captionAlign
:= 0;
449 addButton(box
, '~layers', toggleLayersWindowCB
);
450 span
:= TUISpan
.Create();
451 span
.flExpand
:= true;
452 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
453 box
.appendChild(span
);
454 addButton(box
, '~outline', toggleOutlineWindowCB
);
455 winOptions
.appendChild(box
);
457 winOptions
.flMaxSize
:= TLaySize
.Create(trunc(getScrWdt
/gh_ui_scale
), trunc(getScrHgt
/gh_ui_scale
));
458 uiLayoutCtl(winOptions
);
459 winOptions
.centerInScreen();
463 procedure toggleLayersWindow (arg
: Integer=-1);
465 if (arg
< 0) then showLayersWindow
:= not showLayersWindow
else showLayersWindow
:= (arg
> 0);
466 showLayersWindow
:= not showLayersWindow
; // hack for callback
467 toggleLayersWindowCB(nil);
470 procedure toggleOutlineWindow (arg
: Integer=-1);
472 if (arg
< 0) then showOutlineWindow
:= not showOutlineWindow
else showOutlineWindow
:= (arg
> 0);
473 showOutlineWindow
:= not showOutlineWindow
; // hack for callback
474 toggleOutlineWindowCB(nil);
477 procedure toggleHelpWindow (arg
: Integer=-1);
479 if (winHelp
= nil) then createHelpWindow();
480 if (arg
< 0) then begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
); end
481 else if (arg
= 0) then begin if uiVisibleWindow(winHelp
) then uiRemoveWindow(winHelp
); end
482 else begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
); end
485 procedure toggleOptionsWindow (arg
: Integer=-1);
487 if (winOptions
= nil) then createOptionsWindow();
488 if (arg
< 0) then begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
); end
489 else if (arg
= 0) then begin if uiVisibleWindow(winOptions
) then uiRemoveWindow(winOptions
); end
490 else begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
); end
494 // ////////////////////////////////////////////////////////////////////////// //
496 vpSet
: Boolean = false;
499 laserSet
: Boolean = false;
500 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
501 monMarkedUID
: Integer = -1;
502 platMarkedGUID
: Integer = -1;
505 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
512 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
519 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
526 laserSet
:= laserSet
; // shut up, fpc!
530 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
531 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
534 procedure plrDebugMouse (var ev
: THMouseEvent
);
536 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
537 if (gPlayer1
= nil) or not vpSet
then exit
;
538 //if (ev.kind <> THMouseEvent.Press) then exit;
539 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
544 {$IFDEF HOLMES_OLD_OUTLINES}
546 edgeBmp
: array of Byte = nil;
549 procedure drawOutlines ();
553 procedure clearEdgeBmp ();
555 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
556 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
559 procedure drawPanel (pan
: TPanel
);
561 sx
, len
, y0
, y1
: Integer;
563 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
564 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
565 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
566 if g_ol_nice
or g_ol_fill_walls
then
570 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
571 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
572 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
573 if (len
< 1) then exit
;
575 assert(sx
+len
<= gWinSizeX
+4);
578 if (y0
< 0) then y0
:= 0;
579 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
582 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
588 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
597 procedure flushLine ();
599 if (lsy
> 0) and (lsx
> 0) then
604 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
610 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
611 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
619 procedure startLine (y
: Integer);
625 procedure putPixel (x
: Integer);
627 if (x
< 1) then exit
;
628 if (lex
+1 <> x
) then flushLine();
629 if (lsx
< 0) then lsx
:= x
;
633 procedure drawEdges ();
639 glDisable(GL_TEXTURE_2D
);
642 glDisable(GL_LINE_SMOOTH
);
643 glDisable(GL_POLYGON_SMOOTH
);
644 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
647 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
653 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
654 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
655 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
666 procedure drawFilledWalls ();
672 glDisable(GL_TEXTURE_2D
);
675 glDisable(GL_LINE_SMOOTH
);
676 glDisable(GL_POLYGON_SMOOTH
);
677 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
680 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
684 if (a
[0] <> 0) then putPixel(x
);
691 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
699 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
700 for f
:= 0 to High(parr
) do
703 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
704 if ((pan
.PanelType
and ptype
) = 0) then continue
;
707 if g_ol_nice
then drawEdges();
708 if g_ol_fill_walls
then drawFilledWalls();
714 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
716 result
:= false; // don't stop
717 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
718 if ((pan
.PanelType
and xptag
) = 0) then exit
;
722 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
728 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
729 else panelTypeToTag(ptype
);
730 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
731 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
732 if g_ol_nice
then drawEdges();
733 if g_ol_fill_walls
then drawFilledWalls();
737 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
738 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
739 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
740 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
741 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
742 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
743 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
744 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
749 oliner
: TOutliner
= nil;
751 procedure drawOutlines ();
755 procedure clearOliner ();
757 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
758 if (oliner
= nil) then oliner
:= TOutliner
.Create(vpw
+2, vph
+2) else oliner
.setup(vpw
+2, vph
+2);
761 procedure drawOutline (ol
: TOutliner
; sx
, sy
: Integer);
762 procedure xline (x0
, x1
, y
: Integer);
766 if (g_dbg_scale
< 1.0) then
769 for x
:= x0
to x1
do glVertex2f(sx
+x
+0.375, sy
+y
+0.375);
775 glVertex2f(sx
+x0
+0, sy
+y
+0);
776 glVertex2f(sx
+x1
+1, sy
+y
+0);
777 glVertex2f(sx
+x1
+1, sy
+y
+1);
778 glVertex2f(sx
+x0
+0, sy
+y
+1);
784 sp
: TOutliner
.TSpanX
;
786 if (ol
= nil) then exit
;
788 glDisable(GL_POINT_SMOOTH
);
789 for y
:= 0 to ol
.height
-1 do
791 for sp
in ol
.eachSpanAtY(y
) do
793 if (g_dbg_scale
<= 1.0) then
796 glVertex2f(sx
+sp
.x0
+0.375, sy
+y
+0.375);
797 glVertex2f(sx
+sp
.x1
+0.375, sy
+y
+0.375);
803 glVertex2f(sx
+sp
.x0
+0, sy
+y
+0);
804 glVertex2f(sx
+sp
.x0
+1, sy
+y
+0);
805 glVertex2f(sx
+sp
.x0
+1, sy
+y
+1);
806 glVertex2f(sx
+sp
.x0
+0, sy
+y
+1);
808 glVertex2f(sx
+sp
.x1
+0, sy
+y
+0);
809 glVertex2f(sx
+sp
.x1
+1, sy
+y
+0);
810 glVertex2f(sx
+sp
.x1
+1, sy
+y
+1);
811 glVertex2f(sx
+sp
.x1
+0, sy
+y
+1);
815 for sp
in ol
.eachSpanEdgeAtY(y
, -1) do
817 xline(sp
.x0
, sp
.x1
, y
);
820 glVertex2f(sx+sp.x0+0, sy+y+0);
821 glVertex2f(sx+sp.x1+1, sy+y+0);
822 glVertex2f(sx+sp.x1+1, sy+y+1);
823 glVertex2f(sx+sp.x0+0, sy+y+1);
827 for sp
in ol
.eachSpanEdgeAtY(y
, +1) do
829 xline(sp
.x0
, sp
.x1
, y
);
832 glVertex2f(sx+sp.x0+0, sy+y+0);
833 glVertex2f(sx+sp.x1+1, sy+y+0);
834 glVertex2f(sx+sp.x1+1, sy+y+1);
835 glVertex2f(sx+sp.x0+0, sy+y+1);
842 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
850 if g_ol_nice
then clearOliner();
851 for f
:= 0 to High(parr
) do
854 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
855 if ((pan
.PanelType
and ptype
) = 0) then continue
;
856 if (pan
.X
> vpx
+vpw
+41) or (pan
.Y
> vpy
+vph
+41) then continue
;
857 if (pan
.X
+pan
.Width
< vpx
-41) then continue
;
858 if (pan
.Y
+pan
.Height
< vpy
-41) then continue
;
861 oliner
.addRect(pan
.X
-(vpx
+1), pan
.Y
-(vpy
+1), pan
.Width
, pan
.Height
);
863 if g_ol_fill_walls
then
865 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(r
, g
, b
));
867 else if not g_ol_nice
then
869 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(r
, g
, b
));
874 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
875 drawOutline(oliner
, vpx
+1, vpy
+1);
880 if (vpw
< 2) or (vph
< 2) then exit
;
881 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
882 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
883 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
884 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
885 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
886 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
887 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
888 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
893 procedure plrDebugDraw ();
894 procedure drawTileGrid ();
898 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
900 drawLine(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, TGxRGBA
.Create(96, 96, 96));
903 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
905 drawLine(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
, TGxRGBA
.Create(96, 96, 96));
909 procedure drawAwakeCells ();
913 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
915 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
917 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
919 fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(128, 0, 128, 64));
925 procedure drawTraceBox ();
928 px
, py
, pw
, ph
: Integer;
933 if (Length(gPlayers
) < 1) then exit
;
935 if (plr
= nil) then exit
;
936 plr
.getMapBox(px
, py
, pw
, ph
);
937 drawRect(px
, py
, pw
, ph
, TGxRGBA
.Create(255, 0, 255, 200));
938 pdx
:= pmsCurMapX
-(px
+pw
div 2);
939 pdy
:= pmsCurMapY
-(py
+ph
div 2);
940 drawLine(px
+pw
div 2, py
+ph
div 2, px
+pw
div 2+pdx
, py
+ph
div 2+pdy
, TGxRGBA
.Create(255, 0, 255, 200));
941 pan
:= mapGrid
.traceBox(ex
, ey
, px
, py
, pw
, ph
, pdx
, pdy
, nil, GridTagObstacle
);
944 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, TGxRGBA
.Create(255, 255, 255, 180));
948 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, TGxRGBA
.Create(255, 255, 0, 180));
950 drawRect(ex
, ey
, pw
, ph
, TGxRGBA
.Create(255, 127, 0, 180));
953 procedure hilightCell (cx
, cy
: Integer);
955 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(0, 128, 0, 64));
958 procedure hilightCell1 (cx
, cy
: Integer);
960 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
961 cx
:= cx
and (not (monsGrid
.tileSize
-1));
962 cy
:= cy
and (not (monsGrid
.tileSize
-1));
963 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(255, 255, 0, 92));
966 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
968 result
:= false; // don't stop
969 if (pan
= nil) then exit
; // cell completion, ignore
970 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
971 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(0, 128, 128, 64));
974 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
977 mx
, my
, mw
, mh
: Integer;
980 mon
.getMapBox(mx
, my
, mw
, mh
);
981 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
982 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
984 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
988 procedure drawMonsterInfo (mon
: TMonster
);
990 mx
, my
, mw
, mh
: Integer;
992 procedure drawMonsterTargetLine ();
994 emx
, emy
, emw
, emh
: Integer;
999 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
1001 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
1002 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1004 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
1006 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
1007 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1013 mon
.getMapBox(mx
, my
, mw
, mh
);
1014 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, TGxRGBA
.Create(255, 0, 0));
1015 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1017 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, TGxRGBA
.Create(0, 255, 0));
1021 procedure drawLOS2Plr ();
1023 emx
, emy
, emw
, emh
: Integer;
1027 eplr
:= gPlayers
[0];
1028 if (eplr
= nil) then exit
;
1029 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1030 mon
.getMapBox(mx
, my
, mw
, mh
);
1031 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, TGxRGBA
.Create(255, 0, 0));
1032 {$IF DEFINED(D2F_DEBUG)}
1033 mapGrid
.dbgRayTraceTileHitCB
:= hilightCell1
;
1035 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1036 //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
1038 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, TGxRGBA
.Create(0, 255, 0));
1040 {$IF DEFINED(D2F_DEBUG)}
1041 mapGrid
.dbgRayTraceTileHitCB
:= nil;
1046 if (mon
= nil) then exit
;
1047 mon
.getMapBox(mx
, my
, mw
, mh
);
1050 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1052 if showMonsInfo
then
1054 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1055 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
1060 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1062 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1064 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1066 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1068 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1070 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1071 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1074 drawMonsterTargetLine();
1075 if showMonsLOS2Plr
then drawLOS2Plr();
1077 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1078 property MonsterPain: Integer read FPain write FPain;
1079 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1083 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1085 result
:= false; // don't stop
1086 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1089 procedure drawSelectedPlatformCells ();
1093 if not showGrid
then exit
;
1094 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1095 if (pan
= nil) then exit
;
1096 mapGrid
.forEachBodyCell(pan
.proxyId
, hilightCell
);
1097 drawRect(pan
.x
, pan
.y
, pan
.width
, pan
.height
, TGxRGBA
.Create(0, 200, 0, 200));
1100 procedure drawTrigger (var trig
: TTrigger
);
1102 procedure drawPanelDest (pguid
: Integer);
1106 pan
:= g_Map_PanelByGUID(pguid
);
1107 if (pan
= nil) then exit
;
1109 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1110 pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2,
1111 TGxRGBA
.Create(255, 0, 255, 220));
1118 fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
, TGxRGBA
.Create(255, 0, 255, 96));
1119 tts
:= trigType2Str(trig
.TriggerType
);
1120 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1121 darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1122 drawText6(tx
, trig
.y
-9, tts
, TGxRGBA
.Create(255, 127, 0));
1123 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1124 darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1125 drawText6(tx
, trig
.y
-19, trig
.mapId
, TGxRGBA
.Create(255, 255, 0));
1126 drawPanelDest(trig
.trigPanelGUID
);
1127 case trig
.TriggerType
of
1128 TRIGGER_NONE
: begin end;
1129 TRIGGER_EXIT
: begin end;
1130 TRIGGER_TELEPORT
: begin end;
1131 TRIGGER_OPENDOOR
: begin end;
1132 TRIGGER_CLOSEDOOR
: begin end;
1133 TRIGGER_DOOR
: begin end;
1134 TRIGGER_DOOR5
: begin end;
1135 TRIGGER_CLOSETRAP
: begin end;
1136 TRIGGER_TRAP
: begin end;
1137 TRIGGER_SECRET
: begin end;
1138 TRIGGER_LIFTUP
: begin end;
1139 TRIGGER_LIFTDOWN
: begin end;
1140 TRIGGER_LIFT
: begin end;
1141 TRIGGER_TEXTURE
: begin end;
1142 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1144 if (trig
.trigDataRec
.trigTWidth
> 0) and (trig
.trigDataRec
.trigTHeight
> 0) then
1147 trig
.trigDataRec
.trigTX
, trig
.trigDataRec
.trigTY
,
1148 trig
.trigDataRec
.trigTWidth
, trig
.trigDataRec
.trigTHeight
,
1149 TGxRGBA
.Create(0, 255, 255, 42));
1151 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1152 trig
.trigDataRec
.trigTX
+trig
.trigDataRec
.trigTWidth
div 2,
1153 trig
.trigDataRec
.trigTY
+trig
.trigDataRec
.trigTHeight
div 2,
1154 TGxRGBA
.Create(255, 0, 255, 220));
1157 TRIGGER_SOUND
: begin end;
1158 TRIGGER_SPAWNMONSTER
: begin end;
1159 TRIGGER_SPAWNITEM
: begin end;
1160 TRIGGER_MUSIC
: begin end;
1161 TRIGGER_PUSH
: begin end;
1162 TRIGGER_SCORE
: begin end;
1163 TRIGGER_MESSAGE
: begin end;
1164 TRIGGER_DAMAGE
: begin end;
1165 TRIGGER_HEALTH
: begin end;
1166 TRIGGER_SHOT
: begin end;
1167 TRIGGER_EFFECT
: begin end;
1168 TRIGGER_SCRIPT
: begin end;
1171 //trigPanelId: Integer;
1174 procedure drawTriggers ();
1178 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1181 procedure drawGibsBoxes ();
1184 px
, py
, pw
, ph
: Integer;
1187 for f
:= 0 to High(gGibs
) do
1192 gib
.getMapBox(px
, py
, pw
, ph
);
1193 drawRect(px
, py
, pw
, ph
, TGxRGBA
.Create(255, 0, 255));
1199 scisave
: TScissorSave
;
1201 mx
, my
, mw
, mh
: Integer;
1205 if (gPlayer1
= nil) then exit
;
1207 scisave
.save(true); // enable scissoring
1210 //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
1211 glScissor(0, gScreenHeight
-gPlayerScreenSize
.Y
-1, gPlayerScreenSize
.X
, gPlayerScreenSize
.Y
);
1213 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
1214 glTranslatef(-vpx
, -vpy
, 0);
1216 if (showGrid
) then drawTileGrid();
1219 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
1221 if (monMarkedUID
<> -1) then
1223 mon
:= g_Monsters_ByUID(monMarkedUID
);
1224 if (mon
<> nil) then
1226 mon
.getMapBox(mx
, my
, mw
, mh
);
1227 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
1228 drawMonsterInfo(mon
);
1232 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1233 if showTriggers
then drawTriggers();
1234 if showGrid
then drawSelectedPlatformCells();
1238 if showTraceBox
then drawTraceBox();
1243 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1245 {$IF DEFINED(D2F_DEBUG)}
1246 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1248 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1249 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1250 {$IF DEFINED(D2F_DEBUG)}
1251 mapGrid.dbgRayTraceTileHitCB := nil;
1254 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1255 if (pan <> nil) then writeln('hit!');
1263 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), TGxRGBA
.Create(255, 255, 0));
1267 // ////////////////////////////////////////////////////////////////////////// //
1268 procedure g_Holmes_MouseEvent (var ev
: THMouseEvent
);
1272 if g_Game_IsNet
then exit
;
1273 if not g_holmes_enabled
then exit
;
1275 holmesInitCommands();
1286 if (not he
.eaten
) then plrDebugMouse(he
);
1291 // ////////////////////////////////////////////////////////////////////////// //
1292 procedure g_Holmes_KeyEvent (var ev
: THKeyEvent
);
1294 doeat
: Boolean = false;
1295 {$IF DEFINED(D2F_DEBUG)}
1301 procedure dummyWallTrc (cx
, cy
: Integer);
1306 if g_Game_IsNet
then exit
;
1307 if not g_holmes_enabled
then exit
;
1309 holmesInitCommands();
1315 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1316 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1317 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1322 if (ev
.eaten
) then exit
;
1323 if keybindExecute(ev
) then begin ev
.eat(); exit
; end;
1327 {$IF DEFINED(D2F_DEBUG)}
1328 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1329 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
1330 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
1336 SDL_SCANCODE_UP
: dy
-= 120;
1337 SDL_SCANCODE_DOWN
: dy
+= 120;
1338 SDL_SCANCODE_LEFT
: dx
-= 120;
1339 SDL_SCANCODE_RIGHT
: dx
+= 120;
1341 {$IF DEFINED(D2F_DEBUG)}
1342 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1343 mapGrid
.dbgShowTraceLog
:= true;
1345 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1346 {$IF DEFINED(D2F_DEBUG)}
1347 //mapGrid.dbgRayTraceTileHitCB := nil;
1348 mapGrid
.dbgShowTraceLog
:= false;
1350 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1355 if (doeat
) then ev
.eat();
1359 // ////////////////////////////////////////////////////////////////////////// //
1360 procedure g_Holmes_Draw ();
1362 if g_Game_IsNet
then exit
;
1364 {$IF not DEFINED(HEADLESS)}
1365 holmesInitCommands();
1368 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1369 glDisable(GL_STENCIL_TEST
);
1370 glDisable(GL_BLEND
);
1371 glDisable(GL_SCISSOR_TEST
);
1372 glDisable(GL_TEXTURE_2D
);
1374 if gGameOn
then plrDebugDraw();
1381 procedure g_Holmes_DrawUI ();
1383 if g_Game_IsNet
then exit
;
1384 if not g_holmes_enabled
then exit
;
1385 {$IF not DEFINED(HEADLESS)}
1386 gGfxDoClear
:= false;
1387 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1389 glMatrixMode(GL_MODELVIEW
);
1393 if assigned(postrenderFrameCB
) then postrenderFrameCB();
1401 // ////////////////////////////////////////////////////////////////////////// //
1402 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1403 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1404 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1406 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1407 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1408 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1409 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1411 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1412 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1414 procedure bcMonsterSpawn (s
: AnsiString);
1418 if not gGameOn
or g_Game_IsClient
then
1420 conwriteln('cannot spawn monster in this mode');
1423 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1424 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1425 monMarkedUID
:= mon
.UID
;
1428 procedure bcMonsterWakeup ();
1432 if (monMarkedUID
<> -1) then
1434 mon
:= g_Monsters_ByUID(monMarkedUID
);
1435 if (mon
<> nil) then mon
.WakeUp();
1439 procedure bcPlayerTeleport ();
1441 x
, y
, w
, h
: Integer;
1443 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1444 if (gPlayers
[0] <> nil) then
1446 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1447 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1451 procedure dbgToggleTraceBox (arg
: Integer=-1); begin if (arg
< 0) then showTraceBox
:= not showTraceBox
else showTraceBox
:= (arg
> 0); end;
1453 procedure dbgToggleHolmesPause (arg
: Integer=-1); begin if (arg
< 0) then g_Game_HolmesPause(not gPauseHolmes
) else g_Game_HolmesPause(arg
> 0); end;
1455 procedure cbAtcurSelectMonster ();
1456 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1458 result
:= true; // stop
1459 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1460 monMarkedUID
:= mon
.UID
;
1461 dumpPublishedProperties(mon
);
1465 x
, y
, w
, h
: Integer;
1468 if (Length(gPlayers
) > 0) then
1471 if (plr
<> nil) then
1473 plr
.getMapBox(x
, y
, w
, h
);
1474 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1476 dumpPublishedProperties(plr
);
1480 //e_WriteLog('===========================', MSG_NOTIFY);
1481 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1482 //e_WriteLog('---------------------------', MSG_NOTIFY);
1485 procedure cbAtcurDumpMonsters ();
1486 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1488 result
:= false; // don't stop
1489 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1492 e_WriteLog('===========================', TMsgType
.Notify
);
1493 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1494 e_WriteLog('---------------------------', TMsgType
.Notify
);
1497 procedure cbAtcurDumpWalls ();
1498 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1500 result
:= false; // don't stop
1501 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1502 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
]);
1503 dumpPublishedProperties(pan
);
1506 hasTrigs
: Boolean = false;
1510 platMarkedGUID
:= -1;
1511 e_WriteLog('=== TOGGLE WALL ===', TMsgType
.Notify
);
1512 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1513 e_WriteLog('--- toggle wall ---', TMsgType
.Notify
);
1514 if showTriggers
then
1516 for f
:= 0 to High(gTriggers
) do
1518 trig
:= @gTriggers
[f
];
1519 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1521 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1522 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1525 if hasTrigs
then writeln('--- triggers ---');
1529 procedure cbAtcurToggleWalls ();
1530 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1532 result
:= false; // don't stop
1533 //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);
1534 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1537 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1538 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1539 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1543 // ////////////////////////////////////////////////////////////////////////// //
1544 procedure holmesInitCommands ();
1546 if (cmdlist
<> nil) then exit
;
1547 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1548 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1549 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1550 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1552 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1553 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1554 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1555 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1556 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'wake up selected monster', 'monster control');
1558 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1560 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1561 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1563 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1565 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1566 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1567 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1569 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1570 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1571 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1572 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1574 cmdAdd('dbg_tracebox', dbgToggleTraceBox
, 'test traceBox()', 'player control');
1576 cmdAdd('hlm_pause', dbgToggleHolmesPause
, '"Holmes" pause mode', 'game control');
1580 procedure holmesInitBinds ();
1583 pr
: TTextParser
= nil;
1584 s
, kn
, v
: AnsiString;
1589 if not keybindsInited
then
1592 keybindAdd('F1', 'win_help');
1593 keybindAdd('M-F1', 'win_options');
1594 keybindAdd('C-O', 'win_outline');
1595 keybindAdd('C-L', 'win_layers');
1597 keybindAdd('M-M', 'mon_think_step');
1598 keybindAdd('M-I', 'mon_info');
1599 keybindAdd('M-L', 'mon_los_plr');
1600 keybindAdd('M-G', 'mon_cells');
1601 keybindAdd('M-A', 'mon_wakeup');
1603 keybindAdd('M-P', 'mplat_step');
1604 keybindAdd('M-O', 'mplat_toggle');
1606 keybindAdd('C-T', 'plr_teleport');
1607 keybindAdd('M-T', 'dbg_tracebox');
1609 keybindAdd('C-P', 'dbg_curpos');
1610 keybindAdd('C-G', 'dbg_grid');
1611 keybindAdd('C-X', 'dbg_triggers');
1613 keybindAdd('C-1', 'mon_spawn zombie');
1615 keybindAdd('C-S-P', 'hlm_pause');
1618 msbindAdd('LMB', 'atcur_select_monster');
1619 msbindAdd('M-LMB', 'atcur_dump_monsters');
1620 msbindAdd('RMB', 'atcur_dump_walls');
1621 msbindAdd('M-RMB', 'atcur_disable_walls');
1623 // load bindings from file
1625 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1626 pr
:= TFileTextParser
.Create(st
);
1627 conwriteln('parsing "holmes.rc"...');
1628 while (pr
.tokType
<> pr
.TTEOF
) do
1631 if (s
= 'stop') then break
1632 else if (s
= 'unbind_keys') then keybinds
:= nil
1633 else if (s
= 'unbind_mouse') then msbinds
:= nil
1634 else if (s
= 'bind') then
1636 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1637 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1638 else s
:= pr
.expectId();
1640 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1641 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1642 else v
:= pr
.expectId();
1644 kn
:= parseModKeys(s
, kmods
, mbuts
);
1645 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1655 except on e
: Exception
do // sorry
1656 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1658 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1663 procedure onMouseEvent (var ev
: THMouseEvent
);
1665 if not g_holmes_enabled
then exit
;
1666 g_Holmes_MouseEvent(ev
);
1669 procedure onKeyEvent (var ev
: THKeyEvent
);
1671 if not g_holmes_enabled
then exit
;
1672 g_Holmes_KeyEvent(ev
);
1677 evMouseCB
:= onMouseEvent
;
1678 evKeyCB
:= onKeyEvent
;
1680 conRegVar('hlm_ui_scale', @gh_ui_scale
, 0.01, 5.0, 'Holmes UI scale', '', false);