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
,
28 fui_common
, fui_events
, fui_ctls
,
32 procedure g_Holmes_Draw ();
33 procedure g_Holmes_DrawUI ();
35 procedure g_Holmes_MouseEvent (var ev
: THMouseEvent
);
36 procedure g_Holmes_KeyEvent (var ev
: THKeyEvent
);
39 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
40 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
41 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
45 g_holmes_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
51 {rttiobj,} typinfo
, e_texture
,
52 SysUtils
, Classes
, GL
, SDL2
,
53 MAPDEF
, g_main
, g_options
,
54 utils
, hashtable
, xparser
;
58 //globalInited: Boolean = false;
61 msB
: Word = 0; // button state
62 kbS
: Word = 0; // keyboard modifiers state
63 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
64 showMonsInfo
: Boolean = false;
65 showMonsLOS2Plr
: Boolean = false;
66 showAllMonsCells
: Boolean = false;
67 showMapCurPos
: Boolean = false;
68 showLayersWindow
: Boolean = false;
69 showOutlineWindow
: Boolean = false;
70 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
71 showTraceBox
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
74 // ////////////////////////////////////////////////////////////////////////// //
75 {$INCLUDE g_holmes.inc}
76 {$INCLUDE g_holmes_ol.inc} // outliner
79 // ////////////////////////////////////////////////////////////////////////// //
80 {$INCLUDE g_holmes_cmd.inc}
81 procedure holmesInitCommands (); forward;
82 procedure holmesInitBinds (); forward;
85 // ////////////////////////////////////////////////////////////////////////// //
87 g_ol_nice
: Boolean = false;
88 g_ol_fill_walls
: Boolean = false;
89 g_ol_rlayer_back
: Boolean = false;
90 g_ol_rlayer_step
: Boolean = false;
91 g_ol_rlayer_wall
: Boolean = false;
92 g_ol_rlayer_door
: Boolean = false;
93 g_ol_rlayer_acid1
: Boolean = false;
94 g_ol_rlayer_acid2
: Boolean = false;
95 g_ol_rlayer_water
: Boolean = false;
96 g_ol_rlayer_fore
: Boolean = false;
99 // ////////////////////////////////////////////////////////////////////////// //
101 winHelp
: TUITopWindow
= nil;
102 winOptions
: TUITopWindow
= nil;
103 winLayers
: TUITopWindow
= nil;
104 winOutlines
: TUITopWindow
= nil;
107 procedure createHelpWindow (); forward;
108 procedure createOptionsWindow (); forward;
109 procedure createLayersWindow (); forward;
110 procedure createOutlinesWindow (); forward;
113 procedure toggleLayersWindowCB (me
: TUIControl
);
115 showLayersWindow
:= not showLayersWindow
;
116 if showLayersWindow
then
118 if (winLayers
= nil) then createLayersWindow();
119 uiAddWindow(winLayers
);
123 uiRemoveWindow(winLayers
);
127 procedure toggleOutlineWindowCB (me
: TUIControl
);
129 showOutlineWindow
:= not showOutlineWindow
;
130 if showOutlineWindow
then
132 if (winOutlines
= nil) then createOutlinesWindow();
133 uiAddWindow(winOutlines
);
137 uiRemoveWindow(winOutlines
);
142 procedure createHelpWindow ();
143 procedure addHelpEmptyLine ();
147 stx
:= TUIStaticText
.Create();
148 stx
.flExpand
:= true;
149 stx
.halign
:= 0; // center
153 winHelp
.appendChild(stx
);
156 procedure addHelpCaptionLine (const txt
: AnsiString);
160 stx
:= TUIStaticText
.Create();
161 stx
.flExpand
:= true;
162 stx
.halign
:= 0; // center
166 winHelp
.appendChild(stx
);
169 procedure addHelpCaption (const txt
: AnsiString);
173 stx
:= TUIStaticText
.Create();
174 stx
.flExpand
:= true;
175 stx
.halign
:= 0; // center
179 winHelp
.appendChild(stx
);
182 procedure addHelpKeyMouse (const key
, txt
, grp
: AnsiString);
188 box
:= TUIHBox
.Create();
189 box
.flExpand
:= true;
191 stx
:= TUIStaticText
.Create();
192 stx
.flExpand
:= true;
193 stx
.halign
:= 1; // right
194 stx
.valign
:= 0; // center
199 box
.appendChild(stx
);
201 span
:= TUISpan
.Create();
202 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
203 span
.flExpand
:= true;
204 box
.appendChild(span
);
206 stx
:= TUIStaticText
.Create();
207 stx
.flExpand
:= true;
208 stx
.halign
:= -1; // left
209 stx
.valign
:= 0; // center
213 box
.appendChild(stx
);
214 winHelp
.appendChild(box
);
217 procedure addHelpKey (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-keys'); end;
218 procedure addHelpMouse (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-mouse'); end;
221 slist
: array of AnsiString = nil;
223 bind
: THolmesBinding
;
231 winHelp
:= TUITopWindow
.Create('Holmes Help');
232 winHelp
.escClose
:= true;
233 winHelp
.flHoriz
:= false;
236 for cmd
in cmdlist
do cmd
.helpmark
:= false;
239 for bind
in keybinds
do
241 if (Length(bind
.key
) = 0) then continue
;
242 if cmdlist
.get(bind
.cmdName
, cmd
) then
244 if (Length(cmd
.help
) > 0) then
246 cmd
.helpmark
:= true;
247 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
252 for cmd
in cmdlist
do
254 if not cmd
.helpmark
then continue
;
255 if (Length(cmd
.help
) = 0) then begin cmd
.helpmark
:= false; continue
; end;
257 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
258 if (f
= Length(slist
)) then
260 SetLength(slist
, Length(slist
)+1);
261 slist
[High(slist
)] := cmd
.section
;
265 addHelpCaptionLine('KEYBOARD');
266 //llb := TUISimpleText.Create(0, 0);
267 for f
:= 0 to High(slist
) do
269 //if (f > 0) then llb.appendItem('');
270 if (f
> 0) then addHelpEmptyLine();
271 //llb.appendItem(slist[f], true, true);
272 addHelpCaption(slist
[f
]);
273 for cmd
in cmdlist
do
275 if not cmd
.helpmark
then continue
;
276 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
277 for bind
in keybinds
do
279 if (Length(bind
.key
) = 0) then continue
;
280 if (cmd
.name
= bind
.cmdName
) then
283 //while (Length(s) < maxkeylen) do s += ' ';
284 //s := ' '+s+' -- '+cmd.help;
286 addHelpMouse(bind
.key
, cmd
.help
);
293 for cmd
in cmdlist
do cmd
.helpmark
:= false;
296 for bind
in msbinds
do
298 if (Length(bind
.key
) = 0) then continue
;
299 if cmdlist
.get(bind
.cmdName
, cmd
) then
301 if (Length(cmd
.help
) > 0) then
303 cmd
.helpmark
:= true;
304 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
309 //llb.appendItem('');
310 //llb.appendItem('mouse', true, true);
311 if (f
> 0) then addHelpEmptyLine();
312 addHelpCaptionLine('MOUSE');
313 for bind
in msbinds
do
315 if (Length(bind
.key
) = 0) then continue
;
316 if cmdlist
.get(bind
.cmdName
, cmd
) then
318 if (Length(cmd
.help
) > 0) then
321 //while (Length(s) < maxkeylen) do s += ' ';
322 //s := ' '+s+' -- '+cmd.help;
324 addHelpKey(bind
.key
, cmd
.help
);
329 //winHelp.appendChild(llb);
331 uiLayoutCtl(winHelp
);
332 winHelp
.centerInScreen();
336 procedure winLayersClosed (me
: TUIControl
); begin showLayersWindow
:= false; end;
337 procedure winOutlinesClosed (me
: TUIControl
); begin showOutlineWindow
:= false; end;
339 procedure addCheckBox (parent
: TUIControl
; const text: AnsiString; pvar
: PBoolean);
343 cb
:= TUICheckBox
.Create();
347 parent
.appendChild(cb
);
350 procedure addButton (parent
: TUIControl
; const text: AnsiString; cb
: TUIControl
.TActionCB
);
354 but
:= TUIButton
.Create();
355 //but.flExpand := true;
358 parent
.appendChild(but
);
362 procedure createLayersWindow ();
366 winLayers
:= TUITopWindow
.Create('layers');
367 winLayers
.flHoriz
:= false;
370 winLayers
.flHoriz
:= false;
371 winLayers
.escClose
:= true;
372 winLayers
.closeCB
:= winLayersClosed
;
374 box
:= TUIVBox
.Create();
375 addCheckBox(box
, '~background', @g_rlayer_back
);
376 addCheckBox(box
, '~steps', @g_rlayer_step
);
377 addCheckBox(box
, '~walls', @g_rlayer_wall
);
378 addCheckBox(box
, '~doors', @g_rlayer_door
);
379 addCheckBox(box
, 'acid~1', @g_rlayer_acid1
);
380 addCheckBox(box
, 'acid~2', @g_rlayer_acid2
);
381 addCheckBox(box
, 'wate~r', @g_rlayer_water
);
382 addCheckBox(box
, '~foreground', @g_rlayer_fore
);
383 winLayers
.appendChild(box
);
385 uiLayoutCtl(winLayers
);
389 procedure createOutlinesWindow ();
393 winOutlines
:= TUITopWindow
.Create('outlines');
394 winOutlines
.flHoriz
:= false;
395 winOutlines
.x0
:= 100;
396 winOutlines
.y0
:= 30;
397 winOutlines
.flHoriz
:= false;
398 winOutlines
.escClose
:= true;
399 winOutlines
.closeCB
:= winOutlinesClosed
;
401 box
:= TUIVBox
.Create();
402 box
.hasFrame
:= true;
403 box
.caption
:= 'layers';
404 addCheckBox(box
, '~background', @g_ol_rlayer_back
);
405 addCheckBox(box
, '~steps', @g_ol_rlayer_step
);
406 addCheckBox(box
, '~walls', @g_ol_rlayer_wall
);
407 addCheckBox(box
, '~doors', @g_ol_rlayer_door
);
408 addCheckBox(box
, 'acid~1', @g_ol_rlayer_acid1
);
409 addCheckBox(box
, 'acid~2', @g_ol_rlayer_acid2
);
410 addCheckBox(box
, 'wate~r', @g_ol_rlayer_water
);
411 addCheckBox(box
, '~foreground', @g_ol_rlayer_fore
);
412 winOutlines
.appendChild(box
);
414 box
:= TUIVBox
.Create();
415 box
.hasFrame
:= true;
416 box
.caption
:= 'options';
417 addCheckBox(box
, 'fi~ll walls', @g_ol_fill_walls
);
418 addCheckBox(box
, 'con~tours', @g_ol_nice
);
419 winOutlines
.appendChild(box
);
421 uiLayoutCtl(winOutlines
);
425 procedure createOptionsWindow ();
430 winOptions
:= TUITopWindow
.Create('Holmes Options');
431 winOptions
.flHoriz
:= false;
432 winOptions
.flHoriz
:= false;
433 winOptions
.escClose
:= true;
435 box
:= TUIVBox
.Create();
436 box
.hasFrame
:= true;
437 box
.caption
:= 'visual';
438 addCheckBox(box
, 'map ~grid', @showGrid
);
439 addCheckBox(box
, 'cursor ~position on map', @showMapCurPos
);
440 addCheckBox(box
, '~monster info', @showMonsInfo
);
441 addCheckBox(box
, 'monster LO~S to player', @showMonsLOS2Plr
);
442 addCheckBox(box
, 'monster ~cells (SLOW!)', @showAllMonsCells
);
443 addCheckBox(box
, 'draw ~triggers (SLOW!)', @showTriggers
);
444 winOptions
.appendChild(box
);
446 box
:= TUIHBox
.Create();
447 box
.hasFrame
:= true;
448 box
.caption
:= 'windows';
449 box
.captionAlign
:= 0;
451 addButton(box
, '~layers', toggleLayersWindowCB
);
452 span
:= TUISpan
.Create();
453 span
.flExpand
:= true;
454 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
455 box
.appendChild(span
);
456 addButton(box
, '~outline', toggleOutlineWindowCB
);
457 winOptions
.appendChild(box
);
459 uiLayoutCtl(winOptions
);
460 winOptions
.centerInScreen();
464 procedure toggleLayersWindow (arg
: Integer=-1);
466 if (arg
< 0) then showLayersWindow
:= not showLayersWindow
else showLayersWindow
:= (arg
> 0);
467 showLayersWindow
:= not showLayersWindow
; // hack for callback
468 toggleLayersWindowCB(nil);
471 procedure toggleOutlineWindow (arg
: Integer=-1);
473 if (arg
< 0) then showOutlineWindow
:= not showOutlineWindow
else showOutlineWindow
:= (arg
> 0);
474 showOutlineWindow
:= not showOutlineWindow
; // hack for callback
475 toggleOutlineWindowCB(nil);
478 procedure toggleHelpWindow (arg
: Integer=-1);
480 if (winHelp
= nil) then createHelpWindow();
481 if (arg
< 0) then begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
); end
482 else if (arg
= 0) then begin if uiVisibleWindow(winHelp
) then uiRemoveWindow(winHelp
); end
483 else begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
); end
486 procedure toggleOptionsWindow (arg
: Integer=-1);
488 if (winOptions
= nil) then createOptionsWindow();
489 if (arg
< 0) then begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
); end
490 else if (arg
= 0) then begin if uiVisibleWindow(winOptions
) then uiRemoveWindow(winOptions
); end
491 else begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
); end
495 // ////////////////////////////////////////////////////////////////////////// //
497 vpSet
: Boolean = false;
500 laserSet
: Boolean = false;
501 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
502 monMarkedUID
: Integer = -1;
503 platMarkedGUID
: Integer = -1;
506 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
513 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
520 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
527 laserSet
:= laserSet
; // shut up, fpc!
531 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
532 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
535 procedure plrDebugMouse (var ev
: THMouseEvent
);
537 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
538 if (gPlayer1
= nil) or not vpSet
then exit
;
539 //if (ev.kind <> THMouseEvent.Press) then exit;
540 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
545 {$IFDEF HOLMES_OLD_OUTLINES}
547 edgeBmp
: array of Byte = nil;
550 procedure drawOutlines ();
554 procedure clearEdgeBmp ();
556 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
557 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
560 procedure drawPanel (pan
: TPanel
);
562 sx
, len
, y0
, y1
: Integer;
564 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
565 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
566 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
567 if g_ol_nice
or g_ol_fill_walls
then
571 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
572 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
573 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
574 if (len
< 1) then exit
;
576 assert(sx
+len
<= gWinSizeX
+4);
579 if (y0
< 0) then y0
:= 0;
580 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
583 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
589 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
598 procedure flushLine ();
600 if (lsy
> 0) and (lsx
> 0) then
605 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
611 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
612 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
620 procedure startLine (y
: Integer);
626 procedure putPixel (x
: Integer);
628 if (x
< 1) then exit
;
629 if (lex
+1 <> x
) then flushLine();
630 if (lsx
< 0) then lsx
:= x
;
634 procedure drawEdges ();
640 glDisable(GL_TEXTURE_2D
);
643 glDisable(GL_LINE_SMOOTH
);
644 glDisable(GL_POLYGON_SMOOTH
);
645 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
648 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
654 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
655 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
656 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
667 procedure drawFilledWalls ();
673 glDisable(GL_TEXTURE_2D
);
676 glDisable(GL_LINE_SMOOTH
);
677 glDisable(GL_POLYGON_SMOOTH
);
678 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
681 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
685 if (a
[0] <> 0) then putPixel(x
);
692 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
700 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
701 for f
:= 0 to High(parr
) do
704 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
705 if ((pan
.PanelType
and ptype
) = 0) then continue
;
708 if g_ol_nice
then drawEdges();
709 if g_ol_fill_walls
then drawFilledWalls();
715 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
717 result
:= false; // don't stop
718 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
719 if ((pan
.PanelType
and xptag
) = 0) then exit
;
723 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
729 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
730 else panelTypeToTag(ptype
);
731 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
732 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
733 if g_ol_nice
then drawEdges();
734 if g_ol_fill_walls
then drawFilledWalls();
738 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
739 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
740 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
741 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
742 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
743 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
744 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
745 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
750 oliner
: TOutliner
= nil;
752 procedure drawOutlines ();
756 procedure clearOliner ();
758 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
759 if (oliner
= nil) then oliner
:= TOutliner
.Create(vpw
+2, vph
+2) else oliner
.setup(vpw
+2, vph
+2);
762 procedure drawOutline (ol
: TOutliner
; sx
, sy
: Integer);
763 procedure xline (x0
, x1
, y
: Integer);
767 if (g_dbg_scale
< 1.0) then
770 for x
:= x0
to x1
do glVertex2f(sx
+x
+0.375, sy
+y
+0.375);
776 glVertex2f(sx
+x0
+0, sy
+y
+0);
777 glVertex2f(sx
+x1
+1, sy
+y
+0);
778 glVertex2f(sx
+x1
+1, sy
+y
+1);
779 glVertex2f(sx
+x0
+0, sy
+y
+1);
785 sp
: TOutliner
.TSpanX
;
787 if (ol
= nil) then exit
;
789 glDisable(GL_POINT_SMOOTH
);
790 for y
:= 0 to ol
.height
-1 do
792 for sp
in ol
.eachSpanAtY(y
) do
794 if (g_dbg_scale
<= 1.0) then
797 glVertex2f(sx
+sp
.x0
+0.375, sy
+y
+0.375);
798 glVertex2f(sx
+sp
.x1
+0.375, sy
+y
+0.375);
804 glVertex2f(sx
+sp
.x0
+0, sy
+y
+0);
805 glVertex2f(sx
+sp
.x0
+1, sy
+y
+0);
806 glVertex2f(sx
+sp
.x0
+1, sy
+y
+1);
807 glVertex2f(sx
+sp
.x0
+0, sy
+y
+1);
809 glVertex2f(sx
+sp
.x1
+0, sy
+y
+0);
810 glVertex2f(sx
+sp
.x1
+1, sy
+y
+0);
811 glVertex2f(sx
+sp
.x1
+1, sy
+y
+1);
812 glVertex2f(sx
+sp
.x1
+0, sy
+y
+1);
816 for sp
in ol
.eachSpanEdgeAtY(y
, -1) do
818 xline(sp
.x0
, sp
.x1
, y
);
821 glVertex2f(sx+sp.x0+0, sy+y+0);
822 glVertex2f(sx+sp.x1+1, sy+y+0);
823 glVertex2f(sx+sp.x1+1, sy+y+1);
824 glVertex2f(sx+sp.x0+0, sy+y+1);
828 for sp
in ol
.eachSpanEdgeAtY(y
, +1) do
830 xline(sp
.x0
, sp
.x1
, y
);
833 glVertex2f(sx+sp.x0+0, sy+y+0);
834 glVertex2f(sx+sp.x1+1, sy+y+0);
835 glVertex2f(sx+sp.x1+1, sy+y+1);
836 glVertex2f(sx+sp.x0+0, sy+y+1);
843 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
851 if g_ol_nice
then clearOliner();
852 for f
:= 0 to High(parr
) do
855 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
856 if ((pan
.PanelType
and ptype
) = 0) then continue
;
857 if (pan
.X
> vpx
+vpw
+41) or (pan
.Y
> vpy
+vph
+41) then continue
;
858 if (pan
.X
+pan
.Width
< vpx
-41) then continue
;
859 if (pan
.Y
+pan
.Height
< vpy
-41) then continue
;
862 oliner
.addRect(pan
.X
-(vpx
+1), pan
.Y
-(vpy
+1), pan
.Width
, pan
.Height
);
864 if g_ol_fill_walls
then
866 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(r
, g
, b
));
868 else if not g_ol_nice
then
870 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(r
, g
, b
));
875 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
876 drawOutline(oliner
, vpx
+1, vpy
+1);
881 if (vpw
< 2) or (vph
< 2) then exit
;
882 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
883 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
884 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
885 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
886 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
887 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
888 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
889 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
894 procedure plrDebugDraw ();
895 procedure drawTileGrid ();
899 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
901 drawLine(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, TGxRGBA
.Create(96, 96, 96));
904 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
906 drawLine(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
, TGxRGBA
.Create(96, 96, 96));
910 procedure drawAwakeCells ();
914 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
916 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
918 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
920 fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(128, 0, 128, 64));
926 procedure drawTraceBox ();
929 px
, py
, pw
, ph
: Integer;
934 if (Length(gPlayers
) < 1) then exit
;
936 if (plr
= nil) then exit
;
937 plr
.getMapBox(px
, py
, pw
, ph
);
938 drawRect(px
, py
, pw
, ph
, TGxRGBA
.Create(255, 0, 255, 200));
939 pdx
:= pmsCurMapX
-(px
+pw
div 2);
940 pdy
:= pmsCurMapY
-(py
+ph
div 2);
941 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));
942 pan
:= mapGrid
.traceBox(ex
, ey
, px
, py
, pw
, ph
, pdx
, pdy
, nil, GridTagObstacle
);
945 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, TGxRGBA
.Create(255, 255, 255, 180));
949 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, TGxRGBA
.Create(255, 255, 0, 180));
951 drawRect(ex
, ey
, pw
, ph
, TGxRGBA
.Create(255, 127, 0, 180));
954 procedure hilightCell (cx
, cy
: Integer);
956 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(0, 128, 0, 64));
959 procedure hilightCell1 (cx
, cy
: Integer);
961 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
962 cx
:= cx
and (not (monsGrid
.tileSize
-1));
963 cy
:= cy
and (not (monsGrid
.tileSize
-1));
964 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, TGxRGBA
.Create(255, 255, 0, 92));
967 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
969 result
:= false; // don't stop
970 if (pan
= nil) then exit
; // cell completion, ignore
971 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
972 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, TGxRGBA
.Create(0, 128, 128, 64));
975 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
978 mx
, my
, mw
, mh
: Integer;
981 mon
.getMapBox(mx
, my
, mw
, mh
);
982 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
983 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
985 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
989 procedure drawMonsterInfo (mon
: TMonster
);
991 mx
, my
, mw
, mh
: Integer;
993 procedure drawMonsterTargetLine ();
995 emx
, emy
, emw
, emh
: Integer;
1000 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
1002 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
1003 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1005 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
1007 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
1008 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1014 mon
.getMapBox(mx
, my
, mw
, mh
);
1015 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, TGxRGBA
.Create(255, 0, 0));
1016 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1018 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, TGxRGBA
.Create(0, 255, 0));
1022 procedure drawLOS2Plr ();
1024 emx
, emy
, emw
, emh
: Integer;
1028 eplr
:= gPlayers
[0];
1029 if (eplr
= nil) then exit
;
1030 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1031 mon
.getMapBox(mx
, my
, mw
, mh
);
1032 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, TGxRGBA
.Create(255, 0, 0));
1033 {$IF DEFINED(D2F_DEBUG)}
1034 mapGrid
.dbgRayTraceTileHitCB
:= hilightCell1
;
1036 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1037 //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
1039 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, TGxRGBA
.Create(0, 255, 0));
1041 {$IF DEFINED(D2F_DEBUG)}
1042 mapGrid
.dbgRayTraceTileHitCB
:= nil;
1047 if (mon
= nil) then exit
;
1048 mon
.getMapBox(mx
, my
, mw
, mh
);
1051 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1053 if showMonsInfo
then
1055 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1056 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
1061 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1063 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1065 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1067 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1069 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1071 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1072 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), TGxRGBA
.Create(255, 127, 0)); my
-= 8;
1075 drawMonsterTargetLine();
1076 if showMonsLOS2Plr
then drawLOS2Plr();
1078 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1079 property MonsterPain: Integer read FPain write FPain;
1080 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1084 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1086 result
:= false; // don't stop
1087 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1090 procedure drawSelectedPlatformCells ();
1094 if not showGrid
then exit
;
1095 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1096 if (pan
= nil) then exit
;
1097 mapGrid
.forEachBodyCell(pan
.proxyId
, hilightCell
);
1098 drawRect(pan
.x
, pan
.y
, pan
.width
, pan
.height
, TGxRGBA
.Create(0, 200, 0, 200));
1101 procedure drawTrigger (var trig
: TTrigger
);
1103 procedure drawPanelDest (pguid
: Integer);
1107 pan
:= g_Map_PanelByGUID(pguid
);
1108 if (pan
= nil) then exit
;
1110 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1111 pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2,
1112 TGxRGBA
.Create(255, 0, 255, 220));
1119 fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
, TGxRGBA
.Create(255, 0, 255, 96));
1120 tts
:= trigType2Str(trig
.TriggerType
);
1121 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1122 darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1123 drawText6(tx
, trig
.y
-9, tts
, TGxRGBA
.Create(255, 127, 0));
1124 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1125 darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1126 drawText6(tx
, trig
.y
-19, trig
.mapId
, TGxRGBA
.Create(255, 255, 0));
1127 drawPanelDest(trig
.trigPanelGUID
);
1128 case trig
.TriggerType
of
1129 TRIGGER_NONE
: begin end;
1130 TRIGGER_EXIT
: begin end;
1131 TRIGGER_TELEPORT
: begin end;
1132 TRIGGER_OPENDOOR
: begin end;
1133 TRIGGER_CLOSEDOOR
: begin end;
1134 TRIGGER_DOOR
: begin end;
1135 TRIGGER_DOOR5
: begin end;
1136 TRIGGER_CLOSETRAP
: begin end;
1137 TRIGGER_TRAP
: begin end;
1138 TRIGGER_SECRET
: begin end;
1139 TRIGGER_LIFTUP
: begin end;
1140 TRIGGER_LIFTDOWN
: begin end;
1141 TRIGGER_LIFT
: begin end;
1142 TRIGGER_TEXTURE
: begin end;
1143 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1145 if (trig
.trigDataRec
.trigTWidth
> 0) and (trig
.trigDataRec
.trigTHeight
> 0) then
1148 trig
.trigDataRec
.trigTX
, trig
.trigDataRec
.trigTY
,
1149 trig
.trigDataRec
.trigTWidth
, trig
.trigDataRec
.trigTHeight
,
1150 TGxRGBA
.Create(0, 255, 255, 42));
1152 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1153 trig
.trigDataRec
.trigTX
+trig
.trigDataRec
.trigTWidth
div 2,
1154 trig
.trigDataRec
.trigTY
+trig
.trigDataRec
.trigTHeight
div 2,
1155 TGxRGBA
.Create(255, 0, 255, 220));
1158 TRIGGER_SOUND
: begin end;
1159 TRIGGER_SPAWNMONSTER
: begin end;
1160 TRIGGER_SPAWNITEM
: begin end;
1161 TRIGGER_MUSIC
: begin end;
1162 TRIGGER_PUSH
: begin end;
1163 TRIGGER_SCORE
: begin end;
1164 TRIGGER_MESSAGE
: begin end;
1165 TRIGGER_DAMAGE
: begin end;
1166 TRIGGER_HEALTH
: begin end;
1167 TRIGGER_SHOT
: begin end;
1168 TRIGGER_EFFECT
: begin end;
1169 TRIGGER_SCRIPT
: begin end;
1172 //trigPanelId: Integer;
1175 procedure drawTriggers ();
1179 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1182 procedure drawGibsBoxes ();
1185 px
, py
, pw
, ph
: Integer;
1188 for f
:= 0 to High(gGibs
) do
1193 gib
.getMapBox(px
, py
, pw
, ph
);
1194 drawRect(px
, py
, pw
, ph
, TGxRGBA
.Create(255, 0, 255));
1200 scisave
: TScissorSave
;
1202 mx
, my
, mw
, mh
: Integer;
1206 if (gPlayer1
= nil) then exit
;
1208 scisave
.save(true); // enable scissoring
1211 //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
1212 glScissor(0, gScreenHeight
-gPlayerScreenSize
.Y
-1, gPlayerScreenSize
.X
, gPlayerScreenSize
.Y
);
1214 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
1215 glTranslatef(-vpx
, -vpy
, 0);
1217 if (showGrid
) then drawTileGrid();
1220 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
1222 if (monMarkedUID
<> -1) then
1224 mon
:= g_Monsters_ByUID(monMarkedUID
);
1225 if (mon
<> nil) then
1227 mon
.getMapBox(mx
, my
, mw
, mh
);
1228 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
1229 drawMonsterInfo(mon
);
1233 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1234 if showTriggers
then drawTriggers();
1235 if showGrid
then drawSelectedPlatformCells();
1239 if showTraceBox
then drawTraceBox();
1244 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1246 {$IF DEFINED(D2F_DEBUG)}
1247 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1249 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1250 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1251 {$IF DEFINED(D2F_DEBUG)}
1252 mapGrid.dbgRayTraceTileHitCB := nil;
1255 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1256 if (pan <> nil) then writeln('hit!');
1264 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), TGxRGBA
.Create(255, 255, 0));
1268 // ////////////////////////////////////////////////////////////////////////// //
1269 procedure g_Holmes_MouseEvent (var ev
: THMouseEvent
);
1273 if g_Game_IsNet
then exit
;
1274 if not g_holmes_enabled
then exit
;
1276 holmesInitCommands();
1287 if (not he
.eaten
) then plrDebugMouse(he
);
1292 // ////////////////////////////////////////////////////////////////////////// //
1293 procedure g_Holmes_KeyEvent (var ev
: THKeyEvent
);
1295 doeat
: Boolean = false;
1296 {$IF DEFINED(D2F_DEBUG)}
1302 procedure dummyWallTrc (cx
, cy
: Integer);
1307 if g_Game_IsNet
then exit
;
1308 if not g_holmes_enabled
then exit
;
1310 holmesInitCommands();
1316 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1317 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1318 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1323 if (ev
.eaten
) then exit
;
1324 if keybindExecute(ev
) then begin ev
.eat(); exit
; end;
1328 {$IF DEFINED(D2F_DEBUG)}
1329 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1330 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
1331 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
1337 SDL_SCANCODE_UP
: dy
-= 120;
1338 SDL_SCANCODE_DOWN
: dy
+= 120;
1339 SDL_SCANCODE_LEFT
: dx
-= 120;
1340 SDL_SCANCODE_RIGHT
: dx
+= 120;
1342 {$IF DEFINED(D2F_DEBUG)}
1343 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1344 mapGrid
.dbgShowTraceLog
:= true;
1346 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1347 {$IF DEFINED(D2F_DEBUG)}
1348 //mapGrid.dbgRayTraceTileHitCB := nil;
1349 mapGrid
.dbgShowTraceLog
:= false;
1351 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1356 if (doeat
) then ev
.eat();
1360 // ////////////////////////////////////////////////////////////////////////// //
1361 procedure g_Holmes_Draw ();
1363 if g_Game_IsNet
then exit
;
1365 {$IF not DEFINED(HEADLESS)}
1366 holmesInitCommands();
1369 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1370 glDisable(GL_STENCIL_TEST
);
1371 glDisable(GL_BLEND
);
1372 glDisable(GL_SCISSOR_TEST
);
1373 glDisable(GL_TEXTURE_2D
);
1375 if gGameOn
then plrDebugDraw();
1382 procedure g_Holmes_DrawUI ();
1384 if g_Game_IsNet
then exit
;
1385 if not g_holmes_enabled
then exit
;
1386 {$IF not DEFINED(HEADLESS)}
1387 gGfxDoClear
:= false;
1388 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1390 glMatrixMode(GL_MODELVIEW
);
1394 if assigned(postrenderFrameCB
) then postrenderFrameCB();
1402 // ////////////////////////////////////////////////////////////////////////// //
1403 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1404 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1405 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1407 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1408 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1409 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1410 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1412 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1413 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1415 procedure bcMonsterSpawn (s
: AnsiString);
1419 if not gGameOn
or g_Game_IsClient
then
1421 conwriteln('cannot spawn monster in this mode');
1424 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1425 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1426 monMarkedUID
:= mon
.UID
;
1429 procedure bcMonsterWakeup ();
1433 if (monMarkedUID
<> -1) then
1435 mon
:= g_Monsters_ByUID(monMarkedUID
);
1436 if (mon
<> nil) then mon
.WakeUp();
1440 procedure bcPlayerTeleport ();
1442 x
, y
, w
, h
: Integer;
1444 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1445 if (gPlayers
[0] <> nil) then
1447 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1448 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1452 procedure dbgToggleTraceBox (arg
: Integer=-1); begin if (arg
< 0) then showTraceBox
:= not showTraceBox
else showTraceBox
:= (arg
> 0); end;
1454 procedure dbgToggleHolmesPause (arg
: Integer=-1); begin if (arg
< 0) then g_Game_HolmesPause(not gPauseHolmes
) else g_Game_HolmesPause(arg
> 0); end;
1456 procedure cbAtcurSelectMonster ();
1457 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1459 result
:= true; // stop
1460 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1461 monMarkedUID
:= mon
.UID
;
1462 dumpPublishedProperties(mon
);
1466 x
, y
, w
, h
: Integer;
1469 if (Length(gPlayers
) > 0) then
1472 if (plr
<> nil) then
1474 plr
.getMapBox(x
, y
, w
, h
);
1475 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1477 dumpPublishedProperties(plr
);
1481 //e_WriteLog('===========================', MSG_NOTIFY);
1482 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1483 //e_WriteLog('---------------------------', MSG_NOTIFY);
1486 procedure cbAtcurDumpMonsters ();
1487 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1489 result
:= false; // don't stop
1490 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1493 e_WriteLog('===========================', TMsgType
.Notify
);
1494 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1495 e_WriteLog('---------------------------', TMsgType
.Notify
);
1498 procedure cbAtcurDumpWalls ();
1499 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1501 result
:= false; // don't stop
1502 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1503 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
]);
1504 dumpPublishedProperties(pan
);
1507 hasTrigs
: Boolean = false;
1511 platMarkedGUID
:= -1;
1512 e_WriteLog('=== TOGGLE WALL ===', TMsgType
.Notify
);
1513 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1514 e_WriteLog('--- toggle wall ---', TMsgType
.Notify
);
1515 if showTriggers
then
1517 for f
:= 0 to High(gTriggers
) do
1519 trig
:= @gTriggers
[f
];
1520 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1522 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1523 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1526 if hasTrigs
then writeln('--- triggers ---');
1530 procedure cbAtcurToggleWalls ();
1531 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1533 result
:= false; // don't stop
1534 //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);
1535 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1538 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1539 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1540 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1544 // ////////////////////////////////////////////////////////////////////////// //
1545 procedure holmesInitCommands ();
1547 if (cmdlist
<> nil) then exit
;
1548 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1549 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1550 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1551 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1553 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1554 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1555 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1556 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1557 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'wake up selected monster', 'monster control');
1559 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1561 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1562 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1564 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1566 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1567 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1568 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1570 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1571 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1572 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1573 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1575 cmdAdd('dbg_tracebox', dbgToggleTraceBox
, 'test traceBox()', 'player control');
1577 cmdAdd('hlm_pause', dbgToggleHolmesPause
, '"Holmes" pause mode', 'game control');
1581 procedure holmesInitBinds ();
1584 pr
: TTextParser
= nil;
1585 s
, kn
, v
: AnsiString;
1590 if not keybindsInited
then
1593 keybindAdd('F1', 'win_help');
1594 keybindAdd('M-F1', 'win_options');
1595 keybindAdd('C-O', 'win_outline');
1596 keybindAdd('C-L', 'win_layers');
1598 keybindAdd('M-M', 'mon_think_step');
1599 keybindAdd('M-I', 'mon_info');
1600 keybindAdd('M-L', 'mon_los_plr');
1601 keybindAdd('M-G', 'mon_cells');
1602 keybindAdd('M-A', 'mon_wakeup');
1604 keybindAdd('M-P', 'mplat_step');
1605 keybindAdd('M-O', 'mplat_toggle');
1607 keybindAdd('C-T', 'plr_teleport');
1608 keybindAdd('M-T', 'dbg_tracebox');
1610 keybindAdd('C-P', 'dbg_curpos');
1611 keybindAdd('C-G', 'dbg_grid');
1612 keybindAdd('C-X', 'dbg_triggers');
1614 keybindAdd('C-1', 'mon_spawn zombie');
1616 keybindAdd('C-S-P', 'hlm_pause');
1619 msbindAdd('LMB', 'atcur_select_monster');
1620 msbindAdd('M-LMB', 'atcur_dump_monsters');
1621 msbindAdd('RMB', 'atcur_dump_walls');
1622 msbindAdd('M-RMB', 'atcur_disable_walls');
1624 // load bindings from file
1626 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1627 pr
:= TFileTextParser
.Create(st
);
1628 conwriteln('parsing "holmes.rc"...');
1629 while (pr
.tokType
<> pr
.TTEOF
) do
1632 if (s
= 'stop') then break
1633 else if (s
= 'unbind_keys') then keybinds
:= nil
1634 else if (s
= 'unbind_mouse') then msbinds
:= nil
1635 else if (s
= 'bind') then
1637 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1638 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1639 else s
:= pr
.expectId();
1641 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1642 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1643 else v
:= pr
.expectId();
1645 kn
:= parseModKeys(s
, kmods
, mbuts
);
1646 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1656 except on e
: Exception
do // sorry
1657 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1659 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1664 procedure onMouseEvent (var ev
: THMouseEvent
);
1666 if not g_holmes_enabled
then exit
;
1667 g_Holmes_MouseEvent(ev
);
1670 procedure onKeyEvent (var ev
: THKeyEvent
);
1672 if not g_holmes_enabled
then exit
;
1673 g_Holmes_KeyEvent(ev
);
1678 evMouseCB
:= onMouseEvent
;
1679 evKeyCB
:= onKeyEvent
;
1681 conRegVar('hlm_ui_scale', @fuiRenderScale
, 0.01, 5.0, 'Holmes UI scale', '', false);