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_basic
, g_phys
, g_grid
, g_player
, g_monsters
,
24 g_map
, g_triggers
, g_items
, g_game
, g_panel
, g_console
,
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}
57 {rttiobj,} typinfo
, e_res
,
58 SysUtils
, Classes
, SDL2
,
60 utils
, hashtable
, xparser
;
64 hlmContext
: TGxContext
= nil;
65 //globalInited: Boolean = false;
68 msB
: Word = 0; // button state
69 kbS
: Word = 0; // keyboard modifiers state
70 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
71 showMonsInfo
: Boolean = false;
72 showMonsLOS2Plr
: Boolean = false;
73 showAllMonsCells
: Boolean = false;
74 showMapCurPos
: Boolean = false;
75 showLayersWindow
: Boolean = false;
76 showOutlineWindow
: Boolean = false;
77 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
78 showTraceBox
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
81 // ////////////////////////////////////////////////////////////////////////// //
82 {$INCLUDE g_holmes.inc}
83 {$INCLUDE g_holmes_ol.inc} // outliner
86 // ////////////////////////////////////////////////////////////////////////// //
87 {$INCLUDE g_holmes_cmd.inc}
88 procedure holmesInitCommands (); forward;
89 procedure holmesInitBinds (); forward;
92 // ////////////////////////////////////////////////////////////////////////// //
94 g_ol_nice
: Boolean = false;
95 g_ol_fill_walls
: Boolean = false;
96 g_ol_rlayer_back
: Boolean = false;
97 g_ol_rlayer_step
: Boolean = false;
98 g_ol_rlayer_wall
: Boolean = false;
99 g_ol_rlayer_door
: Boolean = false;
100 g_ol_rlayer_acid1
: Boolean = false;
101 g_ol_rlayer_acid2
: Boolean = false;
102 g_ol_rlayer_water
: Boolean = false;
103 g_ol_rlayer_fore
: Boolean = false;
106 // ////////////////////////////////////////////////////////////////////////// //
108 winHelp
: TUITopWindow
= nil;
109 winOptions
: TUITopWindow
= nil;
110 winLayers
: TUITopWindow
= nil;
111 winOutlines
: TUITopWindow
= nil;
114 procedure createHelpWindow (); forward;
115 procedure createOptionsWindow (); forward;
116 procedure createLayersWindow (); forward;
117 procedure createOutlinesWindow (); forward;
120 procedure toggleLayersWindowCB (me
: TUIControl
);
122 showLayersWindow
:= not showLayersWindow
;
123 if showLayersWindow
then
125 if (winLayers
= nil) then createLayersWindow();
126 uiAddWindow(winLayers
);
130 uiRemoveWindow(winLayers
);
134 procedure toggleOutlineWindowCB (me
: TUIControl
);
136 showOutlineWindow
:= not showOutlineWindow
;
137 if showOutlineWindow
then
139 if (winOutlines
= nil) then createOutlinesWindow();
140 uiAddWindow(winOutlines
);
144 uiRemoveWindow(winOutlines
);
149 procedure createHelpWindow ();
150 procedure addHelpEmptyLine ();
154 stx
:= TUIStaticText
.Create();
155 stx
.flExpand
:= true;
156 stx
.halign
:= 0; // center
160 winHelp
.appendChild(stx
);
163 procedure addHelpCaptionLine (const txt
: AnsiString);
167 stx
:= TUIStaticText
.Create();
168 stx
.flExpand
:= true;
169 stx
.halign
:= 0; // center
173 winHelp
.appendChild(stx
);
176 procedure addHelpCaption (const txt
: AnsiString);
180 stx
:= TUIStaticText
.Create();
181 stx
.flExpand
:= true;
182 stx
.halign
:= 0; // center
186 winHelp
.appendChild(stx
);
189 procedure addHelpKeyMouse (const key
, txt
, grp
: AnsiString);
195 box
:= TUIHBox
.Create();
196 box
.flExpand
:= true;
198 stx
:= TUIStaticText
.Create();
199 stx
.flExpand
:= true;
200 stx
.halign
:= 1; // right
201 stx
.valign
:= 0; // center
206 box
.appendChild(stx
);
208 span
:= TUISpan
.Create();
209 span
.flDefaultSize
:= TLaySize
.Create(12, 1);
210 span
.flExpand
:= true;
211 box
.appendChild(span
);
213 stx
:= TUIStaticText
.Create();
214 stx
.flExpand
:= true;
215 stx
.halign
:= -1; // left
216 stx
.valign
:= 0; // center
220 box
.appendChild(stx
);
221 winHelp
.appendChild(box
);
224 procedure addHelpKey (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-keys'); end;
225 procedure addHelpMouse (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-mouse'); end;
228 slist
: array of AnsiString = nil;
230 bind
: THolmesBinding
;
238 winHelp
:= TUITopWindow
.Create('Holmes Help');
239 winHelp
.escClose
:= true;
240 winHelp
.flHoriz
:= false;
243 for cmd
in cmdlist
do cmd
.helpmark
:= false;
246 for bind
in keybinds
do
248 if (Length(bind
.key
) = 0) then continue
;
249 if cmdlist
.get(bind
.cmdName
, cmd
) then
251 if (Length(cmd
.help
) > 0) then
253 cmd
.helpmark
:= true;
254 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
259 for cmd
in cmdlist
do
261 if not cmd
.helpmark
then continue
;
262 if (Length(cmd
.help
) = 0) then begin cmd
.helpmark
:= false; continue
; end;
264 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
265 if (f
= Length(slist
)) then
267 SetLength(slist
, Length(slist
)+1);
268 slist
[High(slist
)] := cmd
.section
;
272 addHelpCaptionLine('KEYBOARD');
273 //llb := TUISimpleText.Create(0, 0);
274 for f
:= 0 to High(slist
) do
276 //if (f > 0) then llb.appendItem('');
277 if (f
> 0) then addHelpEmptyLine();
278 //llb.appendItem(slist[f], true, true);
279 addHelpCaption(slist
[f
]);
280 for cmd
in cmdlist
do
282 if not cmd
.helpmark
then continue
;
283 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
284 for bind
in keybinds
do
286 if (Length(bind
.key
) = 0) then continue
;
287 if (cmd
.name
= bind
.cmdName
) then
290 //while (Length(s) < maxkeylen) do s += ' ';
291 //s := ' '+s+' -- '+cmd.help;
293 addHelpMouse(bind
.key
, cmd
.help
);
300 for cmd
in cmdlist
do cmd
.helpmark
:= false;
303 for bind
in msbinds
do
305 if (Length(bind
.key
) = 0) then continue
;
306 if cmdlist
.get(bind
.cmdName
, cmd
) then
308 if (Length(cmd
.help
) > 0) then
310 cmd
.helpmark
:= true;
311 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
316 //llb.appendItem('');
317 //llb.appendItem('mouse', true, true);
318 if (f
> 0) then addHelpEmptyLine();
319 addHelpCaptionLine('MOUSE');
320 for bind
in msbinds
do
322 if (Length(bind
.key
) = 0) then continue
;
323 if cmdlist
.get(bind
.cmdName
, cmd
) then
325 if (Length(cmd
.help
) > 0) then
328 //while (Length(s) < maxkeylen) do s += ' ';
329 //s := ' '+s+' -- '+cmd.help;
331 addHelpKey(bind
.key
, cmd
.help
);
336 //winHelp.appendChild(llb);
338 uiLayoutCtl(winHelp
);
339 winHelp
.escClose
:= true;
340 winHelp
.centerInScreen();
344 procedure winLayersClosed (me
: TUIControl
); begin showLayersWindow
:= false; end;
345 procedure winOutlinesClosed (me
: TUIControl
); begin showOutlineWindow
:= false; end;
347 procedure addCheckBox (parent
: TUIControl
; const text: AnsiString; pvar
: PBoolean; const aid
: AnsiString='');
351 cb
:= TUICheckBox
.Create();
356 parent
.appendChild(cb
);
359 procedure addButton (parent
: TUIControl
; const text: AnsiString; cb
: TUIControl
.TActionCB
);
363 but
:= TUIButton
.Create();
364 //but.flExpand := true;
367 parent
.appendChild(but
);
371 procedure actionFillWalls (cb
: TUIControl
);
373 TUICheckBox(cb
).checked
:= not TUICheckBox(cb
).checked
;
374 TUICheckBox(cb
.topLevel
['cbcontour']).enabled
:= not TUICheckBox(cb
).checked
;
377 procedure createLayersWindow ();
381 winLayers
:= TUITopWindow
.Create('layers');
382 winLayers
.flHoriz
:= false;
385 winLayers
.flHoriz
:= false;
386 winLayers
.escClose
:= true;
387 winLayers
.closeCB
:= winLayersClosed
;
389 box
:= TUIVBox
.Create();
390 addCheckBox(box
, '~background', @g_rlayer_back
);
391 addCheckBox(box
, '~steps', @g_rlayer_step
);
392 addCheckBox(box
, '~walls', @g_rlayer_wall
);
393 addCheckBox(box
, '~doors', @g_rlayer_door
);
394 addCheckBox(box
, 'acid~1', @g_rlayer_acid1
);
395 addCheckBox(box
, 'acid~2', @g_rlayer_acid2
);
396 addCheckBox(box
, 'wate~r', @g_rlayer_water
);
397 addCheckBox(box
, '~foreground', @g_rlayer_fore
);
398 winLayers
.appendChild(box
);
400 uiLayoutCtl(winLayers
);
404 procedure createOutlinesWindow ();
408 winOutlines
:= TUITopWindow
.Create('outlines');
409 winOutlines
.flHoriz
:= false;
410 winOutlines
.x0
:= 100;
411 winOutlines
.y0
:= 30;
412 winOutlines
.flHoriz
:= false;
413 winOutlines
.escClose
:= true;
414 winOutlines
.closeCB
:= winOutlinesClosed
;
416 box
:= TUIVBox
.Create();
417 box
.hasFrame
:= true;
418 box
.caption
:= 'layers';
419 addCheckBox(box
, '~background', @g_ol_rlayer_back
);
420 addCheckBox(box
, '~steps', @g_ol_rlayer_step
);
421 addCheckBox(box
, '~walls', @g_ol_rlayer_wall
);
422 addCheckBox(box
, '~doors', @g_ol_rlayer_door
);
423 addCheckBox(box
, 'acid~1', @g_ol_rlayer_acid1
);
424 addCheckBox(box
, 'acid~2', @g_ol_rlayer_acid2
);
425 addCheckBox(box
, 'wate~r', @g_ol_rlayer_water
);
426 addCheckBox(box
, '~foreground', @g_ol_rlayer_fore
);
427 winOutlines
.appendChild(box
);
429 box
:= TUIVBox
.Create();
430 box
.hasFrame
:= true;
431 box
.caption
:= 'options';
432 addCheckBox(box
, 'fi~ll walls', @g_ol_fill_walls
, 'cbfill');
433 addCheckBox(box
, 'con~tours', @g_ol_nice
, 'cbcontour');
434 winOutlines
.appendChild(box
);
436 winOutlines
.setActionCBFor('cbfill', actionFillWalls
);
438 uiLayoutCtl(winOutlines
);
442 procedure createOptionsWindow ();
447 winOptions
:= TUITopWindow
.Create('Holmes Options');
448 winOptions
.flHoriz
:= false;
449 winOptions
.flHoriz
:= false;
450 winOptions
.escClose
:= true;
452 box
:= TUIVBox
.Create();
453 box
.hasFrame
:= true;
454 box
.caption
:= 'visual';
455 addCheckBox(box
, 'map ~grid', @showGrid
);
456 addCheckBox(box
, 'cursor ~position on map', @showMapCurPos
);
457 addCheckBox(box
, '~monster info', @showMonsInfo
);
458 addCheckBox(box
, 'monster LO~S to player', @showMonsLOS2Plr
);
459 addCheckBox(box
, 'monster ~cells (SLOW!)', @showAllMonsCells
);
460 addCheckBox(box
, 'draw ~triggers (SLOW!)', @showTriggers
);
461 winOptions
.appendChild(box
);
463 box
:= TUIHBox
.Create();
464 box
.hasFrame
:= true;
465 box
.caption
:= 'windows';
466 box
.captionAlign
:= 0;
468 addButton(box
, '~layers', toggleLayersWindowCB
);
469 span
:= TUISpan
.Create();
470 span
.flExpand
:= true;
471 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
472 box
.appendChild(span
);
473 addButton(box
, '~outline', toggleOutlineWindowCB
);
474 winOptions
.appendChild(box
);
476 uiLayoutCtl(winOptions
);
477 winOptions
.centerInScreen();
481 procedure toggleLayersWindow (arg
: Integer=-1);
483 if (arg
< 0) then showLayersWindow
:= not showLayersWindow
else showLayersWindow
:= (arg
> 0);
484 showLayersWindow
:= not showLayersWindow
; // hack for callback
485 toggleLayersWindowCB(nil);
488 procedure toggleOutlineWindow (arg
: Integer=-1);
490 if (arg
< 0) then showOutlineWindow
:= not showOutlineWindow
else showOutlineWindow
:= (arg
> 0);
491 showOutlineWindow
:= not showOutlineWindow
; // hack for callback
492 toggleOutlineWindowCB(nil);
495 procedure toggleHelpWindow (arg
: Integer=-1);
497 if (winHelp
= nil) then
499 if (arg
= 0) then exit
;
502 if (arg
< 0) then begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
); end
503 else if (arg
= 0) then begin if uiVisibleWindow(winHelp
) then uiRemoveWindow(winHelp
); end
504 else begin if (not uiVisibleWindow(winHelp
)) then uiAddWindow(winHelp
); end;
505 if (not uiVisibleWindow(winHelp
)) then FreeAndNil(winHelp
);
508 procedure toggleOptionsWindow (arg
: Integer=-1);
510 if (winOptions
= nil) then createOptionsWindow();
511 if (arg
< 0) then begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
); end
512 else if (arg
= 0) then begin if uiVisibleWindow(winOptions
) then uiRemoveWindow(winOptions
); end
513 else begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
); end
517 // ////////////////////////////////////////////////////////////////////////// //
519 vpSet
: Boolean = false;
522 laserSet
: Boolean = false;
523 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
524 monMarkedUID
: Integer = -1;
525 platMarkedGUID
: Integer = -1;
528 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
535 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
542 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
549 laserSet
:= laserSet
; // shut up, fpc!
553 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
554 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
557 {$IFDEF HOLMES_OLD_OUTLINES}
559 edgeBmp
: array of Byte = nil;
562 procedure drawOutlines ();
566 procedure clearEdgeBmp ();
568 SetLength(edgeBmp
, (gScreenWidth
+4)*(gScreenHeight
+4));
569 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
572 procedure drawPanel (pan
: TPanel
);
574 sx
, len
, y0
, y1
: Integer;
576 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
577 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
578 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
579 if g_ol_nice
or g_ol_fill_walls
then
583 if (len
> gScreenWidth
+4) then len
:= gScreenWidth
+4;
584 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
585 if (sx
+len
> gScreenWidth
+4) then len
:= gScreenWidth
+4-sx
;
586 if (len
< 1) then exit
;
588 assert(sx
+len
<= gScreenWidth
+4);
591 if (y0
< 0) then y0
:= 0;
592 if (y1
> gScreenHeight
+4) then y1
:= gScreenHeight
+4;
595 FillChar(edgeBmp
[y0
*(gScreenWidth
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
601 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
610 procedure flushLine ();
612 if (lsy
> 0) and (lsx
> 0) then
617 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
623 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
624 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
632 procedure startLine (y
: Integer);
638 procedure putPixel (x
: Integer);
640 if (x
< 1) then exit
;
641 if (lex
+1 <> x
) then flushLine();
642 if (lsx
< 0) then lsx
:= x
;
646 procedure drawEdges ();
652 glDisable(GL_TEXTURE_2D
);
655 glDisable(GL_LINE_SMOOTH
);
656 glDisable(GL_POLYGON_SMOOTH
);
657 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
660 a
:= @edgeBmp
[y
*(gScreenWidth
+4)+1];
666 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gScreenWidth
+4)] = 0) or (a
[gScreenWidth
+4] = 0) or
667 (a
[-(gScreenWidth
+4)-1] = 0) or (a
[-(gScreenWidth
+4)+1] = 0) or
668 (a
[gScreenWidth
+4-1] = 0) or (a
[gScreenWidth
+4+1] = 0) then
679 procedure drawFilledWalls ();
685 glDisable(GL_TEXTURE_2D
);
688 glDisable(GL_LINE_SMOOTH
);
689 glDisable(GL_POLYGON_SMOOTH
);
690 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
693 a
:= @edgeBmp
[y
*(gScreenWidth
+4)+1];
697 if (a
[0] <> 0) then putPixel(x
);
704 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
712 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
713 for f
:= 0 to High(parr
) do
716 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
717 if ((pan
.PanelType
and ptype
) = 0) then continue
;
720 if g_ol_nice
then drawEdges();
721 if g_ol_fill_walls
then drawFilledWalls();
727 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
729 result
:= false; // don't stop
730 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
731 if ((pan
.PanelType
and xptag
) = 0) then exit
;
735 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
741 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
742 else panelTypeToTag(ptype
);
743 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
744 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
745 if g_ol_nice
then drawEdges();
746 if g_ol_fill_walls
then drawFilledWalls();
750 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
751 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
752 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
753 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
754 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
755 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
756 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
757 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
762 oliner
: TOutliner
= nil;
764 procedure drawOutlines ();
768 procedure clearOliner ();
770 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
771 if (oliner
= nil) then oliner
:= TOutliner
.Create(vpw
+2, vph
+2) else oliner
.setup(vpw
+2, vph
+2);
774 procedure drawOutline (ol
: TOutliner
; sx
, sy
: Integer);
775 procedure xline (x0
, x1
, y
: Integer);
779 if (g_dbg_scale
< 1.0) then
782 for x
:= x0
to x1
do glVertex2f(sx
+x
+0.375, sy
+y
+0.375);
788 glVertex2f(sx
+x0
+0, sy
+y
+0);
789 glVertex2f(sx
+x1
+1, sy
+y
+0);
790 glVertex2f(sx
+x1
+1, sy
+y
+1);
791 glVertex2f(sx
+x0
+0, sy
+y
+1);
797 sp
: TOutliner
.TSpanX
;
799 if (ol
= nil) then exit
;
801 glDisable(GL_POINT_SMOOTH
);
802 for y
:= 0 to ol
.height
-1 do
804 for sp
in ol
.eachSpanAtY(y
) do
806 if (g_dbg_scale
<= 1.0) then
809 glVertex2f(sx
+sp
.x0
+0.375, sy
+y
+0.375);
810 glVertex2f(sx
+sp
.x1
+0.375, sy
+y
+0.375);
816 glVertex2f(sx
+sp
.x0
+0, sy
+y
+0);
817 glVertex2f(sx
+sp
.x0
+1, sy
+y
+0);
818 glVertex2f(sx
+sp
.x0
+1, sy
+y
+1);
819 glVertex2f(sx
+sp
.x0
+0, sy
+y
+1);
821 glVertex2f(sx
+sp
.x1
+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
.x1
+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);
840 for sp
in ol
.eachSpanEdgeAtY(y
, +1) do
842 xline(sp
.x0
, sp
.x1
, y
);
845 glVertex2f(sx+sp.x0+0, sy+y+0);
846 glVertex2f(sx+sp.x1+1, sy+y+0);
847 glVertex2f(sx+sp.x1+1, sy+y+1);
848 glVertex2f(sx+sp.x0+0, sy+y+1);
855 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
863 if g_ol_nice
then clearOliner();
864 hlmContext
.color
:= TGxRGBA
.Create(r
, g
, b
);
865 for f
:= 0 to High(parr
) do
868 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
869 if ((pan
.PanelType
and ptype
) = 0) then continue
;
870 if (pan
.X
> vpx
+vpw
+41) or (pan
.Y
> vpy
+vph
+41) then continue
;
871 if (pan
.X
+pan
.Width
< vpx
-41) then continue
;
872 if (pan
.Y
+pan
.Height
< vpy
-41) then continue
;
875 oliner
.addRect(pan
.X
-(vpx
+1), pan
.Y
-(vpy
+1), pan
.Width
, pan
.Height
);
877 if g_ol_fill_walls
then
879 hlmContext
.fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
881 else if not g_ol_nice
then
883 hlmContext
.rect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
888 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
889 drawOutline(oliner
, vpx
+1, vpy
+1);
894 if (vpw
< 2) or (vph
< 2) then exit
;
895 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
896 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
897 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
898 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
899 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
900 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
901 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
902 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
907 procedure plrDebugDraw ();
908 procedure drawTileGrid ();
912 hlmContext
.color
:= TGxRGBA
.Create(96, 96, 96);
913 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
915 hlmContext
.line(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
);
918 hlmContext
.color
:= TGxRGBA
.Create(96, 96, 96);
919 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
921 hlmContext
.line(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
);
926 procedure drawAwakeCells ();
930 hlmContext
.color
:= TGxRGBA
.Create(128, 0, 128, 64);
931 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
933 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
935 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
937 hlmContext
.fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
);
944 procedure drawTraceBox ();
947 px
, py
, pw
, ph
: Integer;
952 if (Length(gPlayers
) < 1) then exit
;
954 if (plr
= nil) then exit
;
955 plr
.getMapBox(px
, py
, pw
, ph
);
956 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 200);
957 hlmContext
.rect(px
, py
, pw
, ph
);
958 pdx
:= pmsCurMapX
-(px
+pw
div 2);
959 pdy
:= pmsCurMapY
-(py
+ph
div 2);
960 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 200);
961 hlmContext
.line(px
+pw
div 2, py
+ph
div 2, px
+pw
div 2+pdx
, py
+ph
div 2+pdy
);
962 pan
:= mapGrid
.traceBox(ex
, ey
, px
, py
, pw
, ph
, pdx
, pdy
, GridTagObstacle
);
965 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 255, 180);
966 hlmContext
.rect(px
+pdx
, py
+pdy
, pw
, ph
);
970 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 180);
971 hlmContext
.rect(px
+pdx
, py
+pdy
, pw
, ph
);
973 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0, 180);
974 hlmContext
.rect(ex
, ey
, pw
, ph
);
977 procedure hilightCell (cx
, cy
: Integer);
979 hlmContext
.color
:= TGxRGBA
.Create(0, 128, 0, 64);
980 hlmContext
.fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
);
983 procedure hilightBodyCells (proxyId
: Integer);
986 pcellxy
: PGridCellCoord
;
988 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
989 it
:= monsGrid
.forEachBodyCell(proxyId
);
990 for pcellxy
in it
do hilightCell(pcellxy
^.x
, pcellxy
^.y
);
994 procedure hilightCell1 (cx
, cy
: Integer);
996 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
997 cx
:= cx
and (not (monsGrid
.tileSize
-1));
998 cy
:= cy
and (not (monsGrid
.tileSize
-1));
999 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 92);
1000 hlmContext
.fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
);
1003 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
1005 result
:= false; // don't stop
1006 if (pan
= nil) then exit
; // cell completion, ignore
1007 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
1008 hlmContext
.color
:= TGxRGBA
.Create(0, 128, 128, 64);
1009 hlmContext
.fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
1012 procedure monsCollector (mon
: TMonster
);
1015 mx
, my
, mw
, mh
: Integer;
1017 mon
.getMapBox(mx
, my
, mw
, mh
);
1018 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 160);
1019 hlmContext
.rect(mx
, my
, mw
, mh
);
1020 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
1021 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
1023 //e_DrawPoint(8, ex, ey, 0, 255, 0);
1024 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0, 220);
1025 hlmContext
.fillRect(ex
-2, ey
-2, 7, 7);
1029 procedure drawMonsterInfo (mon
: TMonster
);
1031 mx
, my
, mw
, mh
: Integer;
1033 procedure drawMonsterTargetLine ();
1035 emx
, emy
, emw
, emh
: Integer;
1040 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
1042 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
1043 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1045 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
1047 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
1048 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1054 mon
.getMapBox(mx
, my
, mw
, mh
);
1055 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0);
1056 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2);
1057 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1059 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0);
1060 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, ex
, ey
);
1064 procedure drawLOS2Plr ();
1066 emx
, emy
, emw
, emh
: Integer;
1070 eplr
:= gPlayers
[0];
1071 if (eplr
= nil) then exit
;
1072 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1073 mon
.getMapBox(mx
, my
, mw
, mh
);
1074 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0);
1075 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2);
1076 {$IF DEFINED(D2F_DEBUG)}
1077 mapGrid
.dbgRayTraceTileHitCB
:= hilightCell1
;
1079 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1080 //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
1082 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0);
1083 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, ex
, ey
);
1085 {$IF DEFINED(D2F_DEBUG)}
1086 mapGrid
.dbgRayTraceTileHitCB
:= nil;
1091 if (mon
= nil) then exit
;
1092 mon
.getMapBox(mx
, my
, mw
, mh
);
1095 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1096 hilightBodyCells(mon
.proxyId
);
1098 if showMonsInfo
then
1100 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1101 hlmContext
.font
:= 'msx6';
1102 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0);
1104 hlmContext
.darkenRect(mx
-4, my
-7*hlmContext
.charWidth(' ')-6, 110, 7*hlmContext
.charWidth(' ')+6, 128);
1109 hlmContext
.drawText(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
])); my
-= hlmContext
.charWidth(' ');
1111 hlmContext
.drawText(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)])); my
-= hlmContext
.charWidth(' ');
1113 hlmContext
.drawText(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
])); my
-= hlmContext
.charWidth(' ');
1115 hlmContext
.drawText(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
])); my
-= hlmContext
.charWidth(' ');
1117 hlmContext
.drawText(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
])); my
-= hlmContext
.charWidth(' ');
1119 hlmContext
.drawText(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
])); my
-= hlmContext
.charWidth(' ');
1120 hlmContext
.drawText(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
])); my
-= hlmContext
.charWidth(' ');
1123 drawMonsterTargetLine();
1124 if showMonsLOS2Plr
then drawLOS2Plr();
1126 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1127 property MonsterPain: Integer read FPain write FPain;
1128 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1132 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1134 result
:= false; // don't stop
1135 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1136 hilightBodyCells(mon
.proxyId
);
1139 procedure drawSelectedPlatformCells ();
1143 if not showGrid
then exit
;
1144 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1145 if (pan
= nil) then exit
;
1146 //mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
1147 hilightBodyCells(pan
.proxyId
);
1148 hlmContext
.color
:= TGxRGBA
.Create(0, 200, 0, 200);
1149 hlmContext
.rect(pan
.x
, pan
.y
, pan
.width
, pan
.height
);
1152 procedure drawTrigger (var trig
: TTrigger
);
1154 procedure drawPanelDest (pguid
: Integer);
1158 pan
:= g_Map_PanelByGUID(pguid
);
1159 if (pan
= nil) then exit
;
1160 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 220);
1161 hlmContext
.line(trig
.trigCenter
.x
, trig
.trigCenter
.y
, pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2);
1168 hlmContext
.font
:= 'msx6';
1169 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 96);
1170 hlmContext
.fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
);
1171 tts
:= trigType2Str(trig
.TriggerType
);
1172 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1173 hlmContext
.darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1174 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0);
1175 hlmContext
.drawText(tx
, trig
.y
-9, tts
);
1176 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1177 hlmContext
.darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1178 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0);
1179 hlmContext
.drawText(tx
, trig
.y
-19, trig
.mapId
);
1180 drawPanelDest(trig
.trigPanelGUID
);
1181 case trig
.TriggerType
of
1182 TRIGGER_NONE
: begin end;
1183 TRIGGER_EXIT
: begin end;
1184 TRIGGER_TELEPORT
: begin end;
1185 TRIGGER_OPENDOOR
: begin end;
1186 TRIGGER_CLOSEDOOR
: begin end;
1187 TRIGGER_DOOR
: begin end;
1188 TRIGGER_DOOR5
: begin end;
1189 TRIGGER_CLOSETRAP
: begin end;
1190 TRIGGER_TRAP
: begin end;
1191 TRIGGER_SECRET
: begin end;
1192 TRIGGER_LIFTUP
: begin end;
1193 TRIGGER_LIFTDOWN
: begin end;
1194 TRIGGER_LIFT
: begin end;
1195 TRIGGER_TEXTURE
: begin end;
1196 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1198 if (trig
.trigDataRec
.trigTWidth
> 0) and (trig
.trigDataRec
.trigTHeight
> 0) then
1200 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 255, 42);
1201 hlmContext
.fillRect(
1202 trig
.trigDataRec
.trigTX
, trig
.trigDataRec
.trigTY
,
1203 trig
.trigDataRec
.trigTWidth
, trig
.trigDataRec
.trigTHeight
);
1204 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 220);
1206 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1207 trig
.trigDataRec
.trigTX
+trig
.trigDataRec
.trigTWidth
div 2,
1208 trig
.trigDataRec
.trigTY
+trig
.trigDataRec
.trigTHeight
div 2);
1211 TRIGGER_SOUND
: begin end;
1212 TRIGGER_SPAWNMONSTER
: begin end;
1213 TRIGGER_SPAWNITEM
: begin end;
1214 TRIGGER_MUSIC
: begin end;
1215 TRIGGER_PUSH
: begin end;
1216 TRIGGER_SCORE
: begin end;
1217 TRIGGER_MESSAGE
: begin end;
1218 TRIGGER_DAMAGE
: begin end;
1219 TRIGGER_HEALTH
: begin end;
1220 TRIGGER_SHOT
: begin end;
1221 TRIGGER_EFFECT
: begin end;
1222 TRIGGER_SCRIPT
: begin end;
1225 //trigPanelId: Integer;
1228 procedure drawTriggers ();
1232 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1235 {$IFDEF ENABLE_GIBS}
1236 procedure drawGibsBoxes ();
1239 px
, py
, pw
, ph
: Integer;
1242 for f
:= 0 to High(gGibs
) do
1247 gib
.getMapBox(px
, py
, pw
, ph
);
1248 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255);
1249 hlmContext
.rect(px
, py
, pw
, ph
);
1258 it
: TMonsterGrid
.Iter
;
1259 mx
, my
, mw
, mh
: Integer;
1265 if (gPlayer1
= nil) then exit
;
1267 if (hlmContext
= nil) then hlmContext
:= TGxContext
.Create();
1269 gxSetContext(hlmContext
);
1271 //glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, vpw, vph);
1272 //hlmContext.clip := TGxRect.Create(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1275 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
1276 glTranslatef(-vpx, -vpy, 0);
1278 hlmContext
.glSetScaleTrans(g_dbg_scale
, -vpx
, -vpy
);
1279 glEnable(GL_SCISSOR_TEST
);
1280 glScissor(0, gScreenHeight
-gPlayerScreenSize
.Y
-1, gPlayerScreenSize
.X
, gPlayerScreenSize
.Y
);
1282 if (showGrid
) then drawTileGrid();
1287 //g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
1288 it
:= monsGrid
.forEachAlongLine(laserX0
, laserY0
, laserX1
, laserY1
, -1, true);
1289 for mit
in it
do monsCollector(mit
^);
1293 if (monMarkedUID
<> -1) then
1295 mon
:= g_Monsters_ByUID(monMarkedUID
);
1296 if (mon
<> nil) then
1298 mon
.getMapBox(mx
, my
, mw
, mh
);
1299 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
1300 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0, 220);
1301 hlmContext
.rect(mx
, my
, mw
, mh
);
1302 drawMonsterInfo(mon
);
1306 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1307 if showTriggers
then drawTriggers();
1308 if showGrid
then drawSelectedPlatformCells();
1311 // drawAwakeCells();
1314 if showTraceBox
then drawTraceBox();
1316 {$IFDEF ENABLE_GIBS}
1320 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1322 {$IF DEFINED(D2F_DEBUG)}
1323 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1325 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1326 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1327 {$IF DEFINED(D2F_DEBUG)}
1328 mapGrid.dbgRayTraceTileHitCB := nil;
1331 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1332 if (pan <> nil) then writeln('hit!');
1339 if showMapCurPos
then
1341 s
:= Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]);
1342 gxSetContext(hlmContext
);
1343 hlmContext
.font
:= 'win8';
1344 hlmContext
.color
:= TGxRGBA
.Create(0, 0, 0);
1345 for dy
:= -1 to 1 do
1347 for dx
:= -1 to 1 do
1349 if (dx
<> 0) or (dy
<> 0) then hlmContext
.drawText(4+dx
, gScreenHeight
-10+dy
, s
);
1352 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0);
1353 hlmContext
.drawText(4, gScreenHeight
-10, s
);
1359 // ////////////////////////////////////////////////////////////////////////// //
1360 procedure onKeyEvent (var ev
: TFUIEvent
);
1361 {$IF DEFINED(D2F_DEBUG)}
1368 procedure dummyWallTrc (cx
, cy
: Integer);
1376 {$IF DEFINED(D2F_DEBUG)}
1377 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1378 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
1379 ((ev
.kstate
and TFUIEvent
.ModCtrl
) <> 0) then
1385 SDL_SCANCODE_UP
: dy
-= 120;
1386 SDL_SCANCODE_DOWN
: dy
+= 120;
1387 SDL_SCANCODE_LEFT
: dx
-= 120;
1388 SDL_SCANCODE_RIGHT
: dx
+= 120;
1390 {$IF DEFINED(D2F_DEBUG)}
1391 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1392 mapGrid
.dbgShowTraceLog
:= true;
1394 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1395 {$IF DEFINED(D2F_DEBUG)}
1396 //mapGrid.dbgRayTraceTileHitCB := nil;
1397 mapGrid
.dbgShowTraceLog
:= false;
1399 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1407 // ////////////////////////////////////////////////////////////////////////// //
1408 procedure g_Holmes_OnEvent (var ev
: TFUIEvent
);
1409 var doeat
: Boolean = false;
1411 if g_Game_IsNet
then exit
;
1412 if not g_holmes_enabled
then exit
;
1413 if g_holmes_imfunctional
then exit
;
1415 holmesInitCommands();
1425 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1426 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1427 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1432 else if (ev
.mouse
) then
1441 uiDispatchEvent(ev
);
1442 if (not ev
.alive
) then exit
;
1446 if (gPlayer1
<> nil) and (vpSet
) then msbindExecute(ev
);
1451 if keybindExecute(ev
) then ev
.eat();
1452 if (ev
.alive
) then onKeyEvent(ev
);
1455 if (doeat
) then ev
.eat();
1459 // ////////////////////////////////////////////////////////////////////////// //
1460 procedure g_Holmes_Draw ();
1462 if g_Game_IsNet
then exit
;
1463 if not g_holmes_enabled
then exit
;
1464 if g_holmes_imfunctional
then exit
;
1466 holmesInitCommands();
1469 {$IFDEF ENABLE_RENDER}
1470 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1471 glDisable(GL_STENCIL_TEST
);
1472 glDisable(GL_BLEND
);
1473 glDisable(GL_SCISSOR_TEST
);
1474 glDisable(GL_TEXTURE_2D
);
1476 if gGameOn
then plrDebugDraw();
1483 procedure g_Holmes_DrawUI ();
1485 if g_Game_IsNet
then exit
;
1486 if not g_holmes_enabled
then exit
;
1487 if g_holmes_imfunctional
then exit
;
1489 gGfxDoClear
:= false;
1491 {$IFDEF ENABLE_RENDER}
1492 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1494 glMatrixMode(GL_MODELVIEW
);
1498 if assigned(postrenderFrameCB
) then postrenderFrameCB();
1506 // ////////////////////////////////////////////////////////////////////////// //
1507 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1508 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1509 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1511 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1512 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1513 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1514 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1516 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1517 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1519 procedure bcMonsterSpawn (s
: AnsiString);
1523 if not gGameOn
or g_Game_IsClient
then
1525 conwriteln('cannot spawn monster in this mode');
1528 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1529 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1530 monMarkedUID
:= mon
.UID
;
1533 procedure bcMonsterWakeup ();
1537 if (monMarkedUID
<> -1) then
1539 mon
:= g_Monsters_ByUID(monMarkedUID
);
1540 if (mon
<> nil) then mon
.WakeUp();
1544 procedure bcPlayerTeleport ();
1546 x
, y
, w
, h
: Integer;
1548 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1549 if (gPlayers
[0] <> nil) then
1551 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1552 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1556 procedure dbgToggleTraceBox (arg
: Integer=-1); begin if (arg
< 0) then showTraceBox
:= not showTraceBox
else showTraceBox
:= (arg
> 0); end;
1558 procedure dbgToggleHolmesPause (arg
: Integer=-1); begin if (arg
< 0) then g_Game_HolmesPause(not gPauseHolmes
) else g_Game_HolmesPause(arg
> 0); end;
1560 procedure cbAtcurSelectMonster ();
1561 function monsAtDump (mon
: TMonster
{; tag: Integer}): Boolean;
1563 result
:= true; // stop
1564 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1565 monMarkedUID
:= mon
.UID
;
1566 dumpPublishedProperties(mon
);
1570 x
, y
, w
, h
: Integer;
1572 it
: TMonsterGrid
.Iter
;
1575 if (Length(gPlayers
) > 0) then
1578 if (plr
<> nil) then
1580 plr
.getMapBox(x
, y
, w
, h
);
1581 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1583 dumpPublishedProperties(plr
);
1587 //e_WriteLog('===========================', MSG_NOTIFY);
1588 it
:= monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
);
1589 for mit
in it
do monsAtDump(mit
^);
1591 //e_WriteLog('---------------------------', MSG_NOTIFY);
1594 procedure cbAtcurDumpMonsters ();
1595 function monsAtDump (mon
: TMonster
{; tag: Integer}): Boolean;
1597 result
:= false; // don't stop
1598 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1602 it
: TMonsterGrid
.Iter
;
1604 it
:= monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
);
1605 if (it
.length
> 0) then
1607 e_WriteLog('===========================', TMsgType
.Notify
);
1608 for mit
in it
do monsAtDump(mit
^);
1609 e_WriteLog('---------------------------', TMsgType
.Notify
);
1614 procedure cbAtcurDumpWalls ();
1615 function wallToggle (pan
: TPanel
{; tag: Integer}): Boolean;
1617 result
:= false; // don't stop
1618 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1619 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
]);
1620 dumpPublishedProperties(pan
);
1623 hasTrigs
: Boolean = false;
1627 it
: TPanelGrid
.Iter
;
1629 platMarkedGUID
:= -1;
1630 it
:= mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, (GridTagWall
or GridTagDoor
));
1631 if (it
.length
> 0) then
1633 e_WriteLog('=== TOGGLE WALL ===', TMsgType
.Notify
);
1634 for mwit
in it
do wallToggle(mwit
^);
1635 e_WriteLog('--- toggle wall ---', TMsgType
.Notify
);
1638 if showTriggers
then
1640 for f
:= 0 to High(gTriggers
) do
1642 trig
:= @gTriggers
[f
];
1643 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1645 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1646 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1649 if hasTrigs
then writeln('--- triggers ---');
1653 procedure cbAtcurToggleWalls ();
1654 function wallToggle (pan
: TPanel
{; tag: Integer}): Boolean;
1656 result
:= false; // don't stop
1657 //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);
1658 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1662 it
: TPanelGrid
.Iter
;
1664 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1665 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1666 it
:= mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, (GridTagWall
or GridTagDoor
));
1667 for mwit
in it
do wallToggle(mwit
^);
1672 // ////////////////////////////////////////////////////////////////////////// //
1673 procedure holmesInitCommands ();
1675 if (cmdlist
<> nil) then exit
;
1676 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1677 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1678 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1679 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1681 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1682 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1683 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1684 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1685 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'wake up selected monster', 'monster control');
1687 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1689 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1690 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1692 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1694 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1695 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1696 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1698 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1699 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1700 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1701 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1703 cmdAdd('dbg_tracebox', dbgToggleTraceBox
, 'test traceBox()', 'player control');
1705 cmdAdd('hlm_pause', dbgToggleHolmesPause
, '"Holmes" pause mode', 'game control');
1709 procedure holmesInitBinds ();
1712 pr
: TTextParser
= nil;
1713 s
, kn
, v
: AnsiString;
1718 if not keybindsInited
then
1721 keybindAdd('F1', 'win_help');
1722 keybindAdd('M-F1', 'win_options');
1723 keybindAdd('C-O', 'win_outline');
1724 keybindAdd('C-L', 'win_layers');
1726 keybindAdd('M-M', 'mon_think_step');
1727 keybindAdd('M-I', 'mon_info');
1728 keybindAdd('M-L', 'mon_los_plr');
1729 keybindAdd('M-G', 'mon_cells');
1730 keybindAdd('M-A', 'mon_wakeup');
1732 keybindAdd('M-P', 'mplat_step');
1733 keybindAdd('M-O', 'mplat_toggle');
1735 keybindAdd('C-T', 'plr_teleport');
1736 keybindAdd('M-T', 'dbg_tracebox');
1738 keybindAdd('C-P', 'dbg_curpos');
1739 keybindAdd('C-G', 'dbg_grid');
1740 keybindAdd('C-X', 'dbg_triggers');
1742 keybindAdd('C-1', 'mon_spawn zombie');
1744 keybindAdd('C-S-P', 'hlm_pause');
1747 msbindAdd('LMB', 'atcur_select_monster');
1748 msbindAdd('M-LMB', 'atcur_dump_monsters');
1749 msbindAdd('RMB', 'atcur_dump_walls');
1750 msbindAdd('M-RMB', 'atcur_disable_walls');
1752 // load bindings from file
1754 st
:= e_OpenResourceRO(ConfigDirs
, 'holmes.rc');
1755 pr
:= TFileTextParser
.Create(st
);
1756 conwriteln('parsing "holmes.rc"...');
1757 while (pr
.tokType
<> pr
.TTEOF
) do
1760 if (s
= 'stop') then break
1761 else if (s
= 'unbind_keys') then keybinds
:= nil
1762 else if (s
= 'unbind_mouse') then msbinds
:= nil
1763 else if (s
= 'bind') then
1765 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1766 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1767 else s
:= pr
.expectId();
1769 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1770 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1771 else v
:= pr
.expectId();
1773 kn
:= parseModKeys(s
, kmods
, mbuts
);
1774 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1784 except on e
: Exception
do // sorry
1785 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1787 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1797 fuiEventCB
:= g_Holmes_OnEvent
;
1798 //uiContext.font := 'win14';
1800 conRegVar('hlm_ui_scale', @fuiRenderScale
, 0.01, 5.0, 'Holmes UI scale', '', false);