83b74acc2ba7c6d00f9cbee483d13832f3adf8b1
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}
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_OnEvent (var ev
: TFUIEvent
);
38 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
39 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
40 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
44 g_holmes_imfunctional
: Boolean = false;
45 g_holmes_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
56 {rttiobj,} typinfo
, e_texture
,
57 SysUtils
, Classes
, SDL2
,
58 MAPDEF
, g_main
, g_options
,
59 utils
, hashtable
, xparser
;
63 hlmContext
: TGxContext
= nil;
64 //globalInited: Boolean = false;
67 msB
: Word = 0; // button state
68 kbS
: Word = 0; // keyboard modifiers state
69 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
70 showMonsInfo
: Boolean = false;
71 showMonsLOS2Plr
: Boolean = false;
72 showAllMonsCells
: Boolean = false;
73 showMapCurPos
: Boolean = false;
74 showLayersWindow
: Boolean = false;
75 showOutlineWindow
: Boolean = false;
76 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
77 showTraceBox
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
80 // ////////////////////////////////////////////////////////////////////////// //
81 {$INCLUDE g_holmes.inc}
82 {$INCLUDE g_holmes_ol.inc} // outliner
85 // ////////////////////////////////////////////////////////////////////////// //
86 {$INCLUDE g_holmes_cmd.inc}
87 procedure holmesInitCommands (); forward;
88 procedure holmesInitBinds (); forward;
91 // ////////////////////////////////////////////////////////////////////////// //
93 g_ol_nice
: Boolean = false;
94 g_ol_fill_walls
: Boolean = false;
95 g_ol_rlayer_back
: Boolean = false;
96 g_ol_rlayer_step
: Boolean = false;
97 g_ol_rlayer_wall
: Boolean = false;
98 g_ol_rlayer_door
: Boolean = false;
99 g_ol_rlayer_acid1
: Boolean = false;
100 g_ol_rlayer_acid2
: Boolean = false;
101 g_ol_rlayer_water
: Boolean = false;
102 g_ol_rlayer_fore
: Boolean = false;
105 // ////////////////////////////////////////////////////////////////////////// //
107 winHelp
: TUITopWindow
= nil;
108 winOptions
: TUITopWindow
= nil;
109 winLayers
: TUITopWindow
= nil;
110 winOutlines
: TUITopWindow
= nil;
113 procedure createHelpWindow (); forward;
114 procedure createOptionsWindow (); forward;
115 procedure createLayersWindow (); forward;
116 procedure createOutlinesWindow (); forward;
119 procedure toggleLayersWindowCB (me
: TUIControl
);
121 showLayersWindow
:= not showLayersWindow
;
122 if showLayersWindow
then
124 if (winLayers
= nil) then createLayersWindow();
125 uiAddWindow(winLayers
);
129 uiRemoveWindow(winLayers
);
133 procedure toggleOutlineWindowCB (me
: TUIControl
);
135 showOutlineWindow
:= not showOutlineWindow
;
136 if showOutlineWindow
then
138 if (winOutlines
= nil) then createOutlinesWindow();
139 uiAddWindow(winOutlines
);
143 uiRemoveWindow(winOutlines
);
148 procedure createHelpWindow ();
149 procedure addHelpEmptyLine ();
153 stx
:= TUIStaticText
.Create();
154 stx
.flExpand
:= true;
155 stx
.halign
:= 0; // center
159 winHelp
.appendChild(stx
);
162 procedure addHelpCaptionLine (const txt
: AnsiString);
166 stx
:= TUIStaticText
.Create();
167 stx
.flExpand
:= true;
168 stx
.halign
:= 0; // center
172 winHelp
.appendChild(stx
);
175 procedure addHelpCaption (const txt
: AnsiString);
179 stx
:= TUIStaticText
.Create();
180 stx
.flExpand
:= true;
181 stx
.halign
:= 0; // center
185 winHelp
.appendChild(stx
);
188 procedure addHelpKeyMouse (const key
, txt
, grp
: AnsiString);
194 box
:= TUIHBox
.Create();
195 box
.flExpand
:= true;
197 stx
:= TUIStaticText
.Create();
198 stx
.flExpand
:= true;
199 stx
.halign
:= 1; // right
200 stx
.valign
:= 0; // center
205 box
.appendChild(stx
);
207 span
:= TUISpan
.Create();
208 span
.flDefaultSize
:= TLaySize
.Create(12, 1);
209 span
.flExpand
:= true;
210 box
.appendChild(span
);
212 stx
:= TUIStaticText
.Create();
213 stx
.flExpand
:= true;
214 stx
.halign
:= -1; // left
215 stx
.valign
:= 0; // center
219 box
.appendChild(stx
);
220 winHelp
.appendChild(box
);
223 procedure addHelpKey (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-keys'); end;
224 procedure addHelpMouse (const key
, txt
: AnsiString); begin addHelpKeyMouse(key
, txt
, 'help-mouse'); end;
227 slist
: array of AnsiString = nil;
229 bind
: THolmesBinding
;
237 winHelp
:= TUITopWindow
.Create('Holmes Help');
238 winHelp
.escClose
:= true;
239 winHelp
.flHoriz
:= false;
242 for cmd
in cmdlist
do cmd
.helpmark
:= false;
245 for bind
in keybinds
do
247 if (Length(bind
.key
) = 0) then continue
;
248 if cmdlist
.get(bind
.cmdName
, cmd
) then
250 if (Length(cmd
.help
) > 0) then
252 cmd
.helpmark
:= true;
253 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
258 for cmd
in cmdlist
do
260 if not cmd
.helpmark
then continue
;
261 if (Length(cmd
.help
) = 0) then begin cmd
.helpmark
:= false; continue
; end;
263 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
264 if (f
= Length(slist
)) then
266 SetLength(slist
, Length(slist
)+1);
267 slist
[High(slist
)] := cmd
.section
;
271 addHelpCaptionLine('KEYBOARD');
272 //llb := TUISimpleText.Create(0, 0);
273 for f
:= 0 to High(slist
) do
275 //if (f > 0) then llb.appendItem('');
276 if (f
> 0) then addHelpEmptyLine();
277 //llb.appendItem(slist[f], true, true);
278 addHelpCaption(slist
[f
]);
279 for cmd
in cmdlist
do
281 if not cmd
.helpmark
then continue
;
282 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
283 for bind
in keybinds
do
285 if (Length(bind
.key
) = 0) then continue
;
286 if (cmd
.name
= bind
.cmdName
) then
289 //while (Length(s) < maxkeylen) do s += ' ';
290 //s := ' '+s+' -- '+cmd.help;
292 addHelpMouse(bind
.key
, cmd
.help
);
299 for cmd
in cmdlist
do cmd
.helpmark
:= false;
302 for bind
in msbinds
do
304 if (Length(bind
.key
) = 0) then continue
;
305 if cmdlist
.get(bind
.cmdName
, cmd
) then
307 if (Length(cmd
.help
) > 0) then
309 cmd
.helpmark
:= true;
310 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
315 //llb.appendItem('');
316 //llb.appendItem('mouse', true, true);
317 if (f
> 0) then addHelpEmptyLine();
318 addHelpCaptionLine('MOUSE');
319 for bind
in msbinds
do
321 if (Length(bind
.key
) = 0) then continue
;
322 if cmdlist
.get(bind
.cmdName
, cmd
) then
324 if (Length(cmd
.help
) > 0) then
327 //while (Length(s) < maxkeylen) do s += ' ';
328 //s := ' '+s+' -- '+cmd.help;
330 addHelpKey(bind
.key
, cmd
.help
);
335 //winHelp.appendChild(llb);
337 uiLayoutCtl(winHelp
);
338 winHelp
.escClose
:= true;
339 winHelp
.centerInScreen();
343 procedure winLayersClosed (me
: TUIControl
); begin showLayersWindow
:= false; end;
344 procedure winOutlinesClosed (me
: TUIControl
); begin showOutlineWindow
:= false; end;
346 procedure addCheckBox (parent
: TUIControl
; const text: AnsiString; pvar
: PBoolean; const aid
: AnsiString='');
350 cb
:= TUICheckBox
.Create();
355 parent
.appendChild(cb
);
358 procedure addButton (parent
: TUIControl
; const text: AnsiString; cb
: TUIControl
.TActionCB
);
362 but
:= TUIButton
.Create();
363 //but.flExpand := true;
366 parent
.appendChild(but
);
370 procedure actionFillWalls (cb
: TUIControl
);
372 TUICheckBox(cb
).checked
:= not TUICheckBox(cb
).checked
;
373 TUICheckBox(cb
.topLevel
['cbcontour']).enabled
:= not TUICheckBox(cb
).checked
;
376 procedure createLayersWindow ();
380 winLayers
:= TUITopWindow
.Create('layers');
381 winLayers
.flHoriz
:= false;
384 winLayers
.flHoriz
:= false;
385 winLayers
.escClose
:= true;
386 winLayers
.closeCB
:= winLayersClosed
;
388 box
:= TUIVBox
.Create();
389 addCheckBox(box
, '~background', @g_rlayer_back
);
390 addCheckBox(box
, '~steps', @g_rlayer_step
);
391 addCheckBox(box
, '~walls', @g_rlayer_wall
);
392 addCheckBox(box
, '~doors', @g_rlayer_door
);
393 addCheckBox(box
, 'acid~1', @g_rlayer_acid1
);
394 addCheckBox(box
, 'acid~2', @g_rlayer_acid2
);
395 addCheckBox(box
, 'wate~r', @g_rlayer_water
);
396 addCheckBox(box
, '~foreground', @g_rlayer_fore
);
397 winLayers
.appendChild(box
);
399 uiLayoutCtl(winLayers
);
403 procedure createOutlinesWindow ();
407 winOutlines
:= TUITopWindow
.Create('outlines');
408 winOutlines
.flHoriz
:= false;
409 winOutlines
.x0
:= 100;
410 winOutlines
.y0
:= 30;
411 winOutlines
.flHoriz
:= false;
412 winOutlines
.escClose
:= true;
413 winOutlines
.closeCB
:= winOutlinesClosed
;
415 box
:= TUIVBox
.Create();
416 box
.hasFrame
:= true;
417 box
.caption
:= 'layers';
418 addCheckBox(box
, '~background', @g_ol_rlayer_back
);
419 addCheckBox(box
, '~steps', @g_ol_rlayer_step
);
420 addCheckBox(box
, '~walls', @g_ol_rlayer_wall
);
421 addCheckBox(box
, '~doors', @g_ol_rlayer_door
);
422 addCheckBox(box
, 'acid~1', @g_ol_rlayer_acid1
);
423 addCheckBox(box
, 'acid~2', @g_ol_rlayer_acid2
);
424 addCheckBox(box
, 'wate~r', @g_ol_rlayer_water
);
425 addCheckBox(box
, '~foreground', @g_ol_rlayer_fore
);
426 winOutlines
.appendChild(box
);
428 box
:= TUIVBox
.Create();
429 box
.hasFrame
:= true;
430 box
.caption
:= 'options';
431 addCheckBox(box
, 'fi~ll walls', @g_ol_fill_walls
, 'cbfill');
432 addCheckBox(box
, 'con~tours', @g_ol_nice
, 'cbcontour');
433 winOutlines
.appendChild(box
);
435 winOutlines
.setActionCBFor('cbfill', actionFillWalls
);
437 uiLayoutCtl(winOutlines
);
441 procedure createOptionsWindow ();
446 winOptions
:= TUITopWindow
.Create('Holmes Options');
447 winOptions
.flHoriz
:= false;
448 winOptions
.flHoriz
:= false;
449 winOptions
.escClose
:= true;
451 box
:= TUIVBox
.Create();
452 box
.hasFrame
:= true;
453 box
.caption
:= 'visual';
454 addCheckBox(box
, 'map ~grid', @showGrid
);
455 addCheckBox(box
, 'cursor ~position on map', @showMapCurPos
);
456 addCheckBox(box
, '~monster info', @showMonsInfo
);
457 addCheckBox(box
, 'monster LO~S to player', @showMonsLOS2Plr
);
458 addCheckBox(box
, 'monster ~cells (SLOW!)', @showAllMonsCells
);
459 addCheckBox(box
, 'draw ~triggers (SLOW!)', @showTriggers
);
460 winOptions
.appendChild(box
);
462 box
:= TUIHBox
.Create();
463 box
.hasFrame
:= true;
464 box
.caption
:= 'windows';
465 box
.captionAlign
:= 0;
467 addButton(box
, '~layers', toggleLayersWindowCB
);
468 span
:= TUISpan
.Create();
469 span
.flExpand
:= true;
470 span
.flDefaultSize
:= TLaySize
.Create(4, 1);
471 box
.appendChild(span
);
472 addButton(box
, '~outline', toggleOutlineWindowCB
);
473 winOptions
.appendChild(box
);
475 uiLayoutCtl(winOptions
);
476 winOptions
.centerInScreen();
480 procedure toggleLayersWindow (arg
: Integer=-1);
482 if (arg
< 0) then showLayersWindow
:= not showLayersWindow
else showLayersWindow
:= (arg
> 0);
483 showLayersWindow
:= not showLayersWindow
; // hack for callback
484 toggleLayersWindowCB(nil);
487 procedure toggleOutlineWindow (arg
: Integer=-1);
489 if (arg
< 0) then showOutlineWindow
:= not showOutlineWindow
else showOutlineWindow
:= (arg
> 0);
490 showOutlineWindow
:= not showOutlineWindow
; // hack for callback
491 toggleOutlineWindowCB(nil);
494 procedure toggleHelpWindow (arg
: Integer=-1);
496 if (winHelp
= nil) then
498 if (arg
= 0) then exit
;
501 if (arg
< 0) then begin if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
); end
502 else if (arg
= 0) then begin if uiVisibleWindow(winHelp
) then uiRemoveWindow(winHelp
); end
503 else begin if (not uiVisibleWindow(winHelp
)) then uiAddWindow(winHelp
); end;
504 if (not uiVisibleWindow(winHelp
)) then FreeAndNil(winHelp
);
507 procedure toggleOptionsWindow (arg
: Integer=-1);
509 if (winOptions
= nil) then createOptionsWindow();
510 if (arg
< 0) then begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
); end
511 else if (arg
= 0) then begin if uiVisibleWindow(winOptions
) then uiRemoveWindow(winOptions
); end
512 else begin if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
); end
516 // ////////////////////////////////////////////////////////////////////////// //
518 vpSet
: Boolean = false;
521 laserSet
: Boolean = false;
522 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
523 monMarkedUID
: Integer = -1;
524 platMarkedGUID
: Integer = -1;
527 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
534 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
541 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
548 laserSet
:= laserSet
; // shut up, fpc!
552 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
553 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
556 {$IFDEF HOLMES_OLD_OUTLINES}
558 edgeBmp
: array of Byte = nil;
561 procedure drawOutlines ();
565 procedure clearEdgeBmp ();
567 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
568 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
571 procedure drawPanel (pan
: TPanel
);
573 sx
, len
, y0
, y1
: Integer;
575 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
576 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
577 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
578 if g_ol_nice
or g_ol_fill_walls
then
582 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
583 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
584 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
585 if (len
< 1) then exit
;
587 assert(sx
+len
<= gWinSizeX
+4);
590 if (y0
< 0) then y0
:= 0;
591 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
594 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
600 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
609 procedure flushLine ();
611 if (lsy
> 0) and (lsx
> 0) then
616 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
622 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
623 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
631 procedure startLine (y
: Integer);
637 procedure putPixel (x
: Integer);
639 if (x
< 1) then exit
;
640 if (lex
+1 <> x
) then flushLine();
641 if (lsx
< 0) then lsx
:= x
;
645 procedure drawEdges ();
651 glDisable(GL_TEXTURE_2D
);
654 glDisable(GL_LINE_SMOOTH
);
655 glDisable(GL_POLYGON_SMOOTH
);
656 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
659 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
665 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
666 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
667 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
678 procedure drawFilledWalls ();
684 glDisable(GL_TEXTURE_2D
);
687 glDisable(GL_LINE_SMOOTH
);
688 glDisable(GL_POLYGON_SMOOTH
);
689 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
692 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
696 if (a
[0] <> 0) then putPixel(x
);
703 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
711 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
712 for f
:= 0 to High(parr
) do
715 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
716 if ((pan
.PanelType
and ptype
) = 0) then continue
;
719 if g_ol_nice
then drawEdges();
720 if g_ol_fill_walls
then drawFilledWalls();
726 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
728 result
:= false; // don't stop
729 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
730 if ((pan
.PanelType
and xptag
) = 0) then exit
;
734 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
740 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
741 else panelTypeToTag(ptype
);
742 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
743 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
744 if g_ol_nice
then drawEdges();
745 if g_ol_fill_walls
then drawFilledWalls();
749 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
750 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
751 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
752 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
753 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
754 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
755 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
756 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
761 oliner
: TOutliner
= nil;
763 procedure drawOutlines ();
767 procedure clearOliner ();
769 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
770 if (oliner
= nil) then oliner
:= TOutliner
.Create(vpw
+2, vph
+2) else oliner
.setup(vpw
+2, vph
+2);
773 procedure drawOutline (ol
: TOutliner
; sx
, sy
: Integer);
774 procedure xline (x0
, x1
, y
: Integer);
778 if (g_dbg_scale
< 1.0) then
781 for x
:= x0
to x1
do glVertex2f(sx
+x
+0.375, sy
+y
+0.375);
787 glVertex2f(sx
+x0
+0, sy
+y
+0);
788 glVertex2f(sx
+x1
+1, sy
+y
+0);
789 glVertex2f(sx
+x1
+1, sy
+y
+1);
790 glVertex2f(sx
+x0
+0, sy
+y
+1);
796 sp
: TOutliner
.TSpanX
;
798 if (ol
= nil) then exit
;
800 glDisable(GL_POINT_SMOOTH
);
801 for y
:= 0 to ol
.height
-1 do
803 for sp
in ol
.eachSpanAtY(y
) do
805 if (g_dbg_scale
<= 1.0) then
808 glVertex2f(sx
+sp
.x0
+0.375, sy
+y
+0.375);
809 glVertex2f(sx
+sp
.x1
+0.375, sy
+y
+0.375);
815 glVertex2f(sx
+sp
.x0
+0, sy
+y
+0);
816 glVertex2f(sx
+sp
.x0
+1, sy
+y
+0);
817 glVertex2f(sx
+sp
.x0
+1, sy
+y
+1);
818 glVertex2f(sx
+sp
.x0
+0, sy
+y
+1);
820 glVertex2f(sx
+sp
.x1
+0, sy
+y
+0);
821 glVertex2f(sx
+sp
.x1
+1, sy
+y
+0);
822 glVertex2f(sx
+sp
.x1
+1, sy
+y
+1);
823 glVertex2f(sx
+sp
.x1
+0, sy
+y
+1);
827 for sp
in ol
.eachSpanEdgeAtY(y
, -1) do
829 xline(sp
.x0
, sp
.x1
, y
);
832 glVertex2f(sx+sp.x0+0, sy+y+0);
833 glVertex2f(sx+sp.x1+1, sy+y+0);
834 glVertex2f(sx+sp.x1+1, sy+y+1);
835 glVertex2f(sx+sp.x0+0, sy+y+1);
839 for sp
in ol
.eachSpanEdgeAtY(y
, +1) do
841 xline(sp
.x0
, sp
.x1
, y
);
844 glVertex2f(sx+sp.x0+0, sy+y+0);
845 glVertex2f(sx+sp.x1+1, sy+y+0);
846 glVertex2f(sx+sp.x1+1, sy+y+1);
847 glVertex2f(sx+sp.x0+0, sy+y+1);
854 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
862 if g_ol_nice
then clearOliner();
863 hlmContext
.color
:= TGxRGBA
.Create(r
, g
, b
);
864 for f
:= 0 to High(parr
) do
867 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
868 if ((pan
.PanelType
and ptype
) = 0) then continue
;
869 if (pan
.X
> vpx
+vpw
+41) or (pan
.Y
> vpy
+vph
+41) then continue
;
870 if (pan
.X
+pan
.Width
< vpx
-41) then continue
;
871 if (pan
.Y
+pan
.Height
< vpy
-41) then continue
;
874 oliner
.addRect(pan
.X
-(vpx
+1), pan
.Y
-(vpy
+1), pan
.Width
, pan
.Height
);
876 if g_ol_fill_walls
then
878 hlmContext
.fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
880 else if not g_ol_nice
then
882 hlmContext
.rect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
887 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
888 drawOutline(oliner
, vpx
+1, vpy
+1);
893 if (vpw
< 2) or (vph
< 2) then exit
;
894 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
895 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
896 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
897 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
898 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
899 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
900 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
901 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
906 procedure plrDebugDraw ();
907 procedure drawTileGrid ();
911 hlmContext
.color
:= TGxRGBA
.Create(96, 96, 96);
912 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
914 hlmContext
.line(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
);
917 hlmContext
.color
:= TGxRGBA
.Create(96, 96, 96);
918 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
920 hlmContext
.line(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
);
924 procedure drawAwakeCells ();
928 hlmContext
.color
:= TGxRGBA
.Create(128, 0, 128, 64);
929 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
931 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
933 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
935 hlmContext
.fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
);
941 procedure drawTraceBox ();
944 px
, py
, pw
, ph
: Integer;
949 if (Length(gPlayers
) < 1) then exit
;
951 if (plr
= nil) then exit
;
952 plr
.getMapBox(px
, py
, pw
, ph
);
953 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 200);
954 hlmContext
.rect(px
, py
, pw
, ph
);
955 pdx
:= pmsCurMapX
-(px
+pw
div 2);
956 pdy
:= pmsCurMapY
-(py
+ph
div 2);
957 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 200);
958 hlmContext
.line(px
+pw
div 2, py
+ph
div 2, px
+pw
div 2+pdx
, py
+ph
div 2+pdy
);
959 pan
:= mapGrid
.traceBox(ex
, ey
, px
, py
, pw
, ph
, pdx
, pdy
, GridTagObstacle
);
962 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 255, 180);
963 hlmContext
.rect(px
+pdx
, py
+pdy
, pw
, ph
);
967 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 180);
968 hlmContext
.rect(px
+pdx
, py
+pdy
, pw
, ph
);
970 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0, 180);
971 hlmContext
.rect(ex
, ey
, pw
, ph
);
974 procedure hilightCell (cx
, cy
: Integer);
976 hlmContext
.color
:= TGxRGBA
.Create(0, 128, 0, 64);
977 hlmContext
.fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
);
980 procedure hilightBodyCells (proxyId
: Integer);
983 pcellxy
: PGridCellCoord
;
985 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
986 it
:= monsGrid
.forEachBodyCell(proxyId
);
987 for pcellxy
in it
do hilightCell(pcellxy
^.x
, pcellxy
^.y
);
991 procedure hilightCell1 (cx
, cy
: Integer);
993 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
994 cx
:= cx
and (not (monsGrid
.tileSize
-1));
995 cy
:= cy
and (not (monsGrid
.tileSize
-1));
996 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 92);
997 hlmContext
.fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
);
1000 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
1002 result
:= false; // don't stop
1003 if (pan
= nil) then exit
; // cell completion, ignore
1004 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
1005 hlmContext
.color
:= TGxRGBA
.Create(0, 128, 128, 64);
1006 hlmContext
.fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
1009 procedure monsCollector (mon
: TMonster
);
1012 mx
, my
, mw
, mh
: Integer;
1014 mon
.getMapBox(mx
, my
, mw
, mh
);
1015 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0, 160);
1016 hlmContext
.rect(mx
, my
, mw
, mh
);
1017 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
1018 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
1020 //e_DrawPoint(8, ex, ey, 0, 255, 0);
1021 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0, 220);
1022 hlmContext
.fillRect(ex
-2, ey
-2, 7, 7);
1026 procedure drawMonsterInfo (mon
: TMonster
);
1028 mx
, my
, mw
, mh
: Integer;
1030 procedure drawMonsterTargetLine ();
1032 emx
, emy
, emw
, emh
: Integer;
1037 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
1039 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
1040 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1042 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
1044 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
1045 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1051 mon
.getMapBox(mx
, my
, mw
, mh
);
1052 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0);
1053 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2);
1054 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1056 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0);
1057 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, ex
, ey
);
1061 procedure drawLOS2Plr ();
1063 emx
, emy
, emw
, emh
: Integer;
1067 eplr
:= gPlayers
[0];
1068 if (eplr
= nil) then exit
;
1069 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1070 mon
.getMapBox(mx
, my
, mw
, mh
);
1071 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0);
1072 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2);
1073 {$IF DEFINED(D2F_DEBUG)}
1074 mapGrid
.dbgRayTraceTileHitCB
:= hilightCell1
;
1076 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1077 //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
1079 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 0);
1080 hlmContext
.line(mx
+mw
div 2, my
+mh
div 2, ex
, ey
);
1082 {$IF DEFINED(D2F_DEBUG)}
1083 mapGrid
.dbgRayTraceTileHitCB
:= nil;
1088 if (mon
= nil) then exit
;
1089 mon
.getMapBox(mx
, my
, mw
, mh
);
1092 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1093 hilightBodyCells(mon
.proxyId
);
1095 if showMonsInfo
then
1097 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1098 hlmContext
.font
:= 'msx6';
1099 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0);
1101 hlmContext
.darkenRect(mx
-4, my
-7*hlmContext
.charWidth(' ')-6, 110, 7*hlmContext
.charWidth(' ')+6, 128);
1106 hlmContext
.drawText(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
])); my
-= hlmContext
.charWidth(' ');
1108 hlmContext
.drawText(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)])); my
-= hlmContext
.charWidth(' ');
1110 hlmContext
.drawText(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
])); my
-= hlmContext
.charWidth(' ');
1112 hlmContext
.drawText(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
])); my
-= hlmContext
.charWidth(' ');
1114 hlmContext
.drawText(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
])); my
-= hlmContext
.charWidth(' ');
1116 hlmContext
.drawText(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
])); my
-= hlmContext
.charWidth(' ');
1117 hlmContext
.drawText(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
])); my
-= hlmContext
.charWidth(' ');
1120 drawMonsterTargetLine();
1121 if showMonsLOS2Plr
then drawLOS2Plr();
1123 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1124 property MonsterPain: Integer read FPain write FPain;
1125 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1129 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1131 result
:= false; // don't stop
1132 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1133 hilightBodyCells(mon
.proxyId
);
1136 procedure drawSelectedPlatformCells ();
1140 if not showGrid
then exit
;
1141 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1142 if (pan
= nil) then exit
;
1143 //mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
1144 hilightBodyCells(pan
.proxyId
);
1145 hlmContext
.color
:= TGxRGBA
.Create(0, 200, 0, 200);
1146 hlmContext
.rect(pan
.x
, pan
.y
, pan
.width
, pan
.height
);
1149 procedure drawTrigger (var trig
: TTrigger
);
1151 procedure drawPanelDest (pguid
: Integer);
1155 pan
:= g_Map_PanelByGUID(pguid
);
1156 if (pan
= nil) then exit
;
1157 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 220);
1158 hlmContext
.line(trig
.trigCenter
.x
, trig
.trigCenter
.y
, pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2);
1165 hlmContext
.font
:= 'msx6';
1166 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 96);
1167 hlmContext
.fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
);
1168 tts
:= trigType2Str(trig
.TriggerType
);
1169 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1170 hlmContext
.darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1171 hlmContext
.color
:= TGxRGBA
.Create(255, 127, 0);
1172 hlmContext
.drawText(tx
, trig
.y
-9, tts
);
1173 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1174 hlmContext
.darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1175 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0);
1176 hlmContext
.drawText(tx
, trig
.y
-19, trig
.mapId
);
1177 drawPanelDest(trig
.trigPanelGUID
);
1178 case trig
.TriggerType
of
1179 TRIGGER_NONE
: begin end;
1180 TRIGGER_EXIT
: begin end;
1181 TRIGGER_TELEPORT
: begin end;
1182 TRIGGER_OPENDOOR
: begin end;
1183 TRIGGER_CLOSEDOOR
: begin end;
1184 TRIGGER_DOOR
: begin end;
1185 TRIGGER_DOOR5
: begin end;
1186 TRIGGER_CLOSETRAP
: begin end;
1187 TRIGGER_TRAP
: begin end;
1188 TRIGGER_SECRET
: begin end;
1189 TRIGGER_LIFTUP
: begin end;
1190 TRIGGER_LIFTDOWN
: begin end;
1191 TRIGGER_LIFT
: begin end;
1192 TRIGGER_TEXTURE
: begin end;
1193 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1195 if (trig
.trigDataRec
.trigTWidth
> 0) and (trig
.trigDataRec
.trigTHeight
> 0) then
1197 hlmContext
.color
:= TGxRGBA
.Create(0, 255, 255, 42);
1198 hlmContext
.fillRect(
1199 trig
.trigDataRec
.trigTX
, trig
.trigDataRec
.trigTY
,
1200 trig
.trigDataRec
.trigTWidth
, trig
.trigDataRec
.trigTHeight
);
1201 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255, 220);
1203 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1204 trig
.trigDataRec
.trigTX
+trig
.trigDataRec
.trigTWidth
div 2,
1205 trig
.trigDataRec
.trigTY
+trig
.trigDataRec
.trigTHeight
div 2);
1208 TRIGGER_SOUND
: begin end;
1209 TRIGGER_SPAWNMONSTER
: begin end;
1210 TRIGGER_SPAWNITEM
: begin end;
1211 TRIGGER_MUSIC
: begin end;
1212 TRIGGER_PUSH
: begin end;
1213 TRIGGER_SCORE
: begin end;
1214 TRIGGER_MESSAGE
: begin end;
1215 TRIGGER_DAMAGE
: begin end;
1216 TRIGGER_HEALTH
: begin end;
1217 TRIGGER_SHOT
: begin end;
1218 TRIGGER_EFFECT
: begin end;
1219 TRIGGER_SCRIPT
: begin end;
1222 //trigPanelId: Integer;
1225 procedure drawTriggers ();
1229 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1232 procedure drawGibsBoxes ();
1235 px
, py
, pw
, ph
: Integer;
1238 for f
:= 0 to High(gGibs
) do
1243 gib
.getMapBox(px
, py
, pw
, ph
);
1244 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 255);
1245 hlmContext
.rect(px
, py
, pw
, ph
);
1253 it
: TMonsterGrid
.Iter
;
1254 mx
, my
, mw
, mh
: Integer;
1258 if (gPlayer1
= nil) then exit
;
1260 if (hlmContext
= nil) then hlmContext
:= TGxContext
.Create();
1262 gxSetContext(hlmContext
);
1264 //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
1265 //hlmContext.clip := TGxRect.Create(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1268 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
1269 glTranslatef(-vpx, -vpy, 0);
1271 hlmContext
.glSetScaleTrans(g_dbg_scale
, -vpx
, -vpy
);
1272 glEnable(GL_SCISSOR_TEST
);
1273 glScissor(0, gScreenHeight
-gPlayerScreenSize
.Y
-1, gPlayerScreenSize
.X
, gPlayerScreenSize
.Y
);
1275 if (showGrid
) then drawTileGrid();
1280 //g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
1281 it
:= monsGrid
.forEachAlongLine(laserX0
, laserY0
, laserX1
, laserY1
, -1, true);
1282 for mit
in it
do monsCollector(mit
^);
1286 if (monMarkedUID
<> -1) then
1288 mon
:= g_Monsters_ByUID(monMarkedUID
);
1289 if (mon
<> nil) then
1291 mon
.getMapBox(mx
, my
, mw
, mh
);
1292 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
1293 hlmContext
.color
:= TGxRGBA
.Create(255, 0, 0, 220);
1294 hlmContext
.rect(mx
, my
, mw
, mh
);
1295 drawMonsterInfo(mon
);
1299 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1300 if showTriggers
then drawTriggers();
1301 if showGrid
then drawSelectedPlatformCells();
1305 if showTraceBox
then drawTraceBox();
1310 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1312 {$IF DEFINED(D2F_DEBUG)}
1313 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1315 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1316 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1317 {$IF DEFINED(D2F_DEBUG)}
1318 mapGrid.dbgRayTraceTileHitCB := nil;
1321 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1322 if (pan <> nil) then writeln('hit!');
1329 if showMapCurPos
then
1331 gxSetContext(hlmContext
);
1332 hlmContext
.font
:= 'win8';
1333 hlmContext
.color
:= TGxRGBA
.Create(255, 255, 0);
1334 hlmContext
.drawText(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]));
1340 // ////////////////////////////////////////////////////////////////////////// //
1341 procedure onKeyEvent (var ev
: TFUIEvent
);
1342 {$IF DEFINED(D2F_DEBUG)}
1349 procedure dummyWallTrc (cx
, cy
: Integer);
1357 {$IF DEFINED(D2F_DEBUG)}
1358 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1359 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
1360 ((ev
.kstate
and TFUIEvent
.ModCtrl
) <> 0) then
1366 SDL_SCANCODE_UP
: dy
-= 120;
1367 SDL_SCANCODE_DOWN
: dy
+= 120;
1368 SDL_SCANCODE_LEFT
: dx
-= 120;
1369 SDL_SCANCODE_RIGHT
: dx
+= 120;
1371 {$IF DEFINED(D2F_DEBUG)}
1372 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1373 mapGrid
.dbgShowTraceLog
:= true;
1375 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1376 {$IF DEFINED(D2F_DEBUG)}
1377 //mapGrid.dbgRayTraceTileHitCB := nil;
1378 mapGrid
.dbgShowTraceLog
:= false;
1380 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1388 // ////////////////////////////////////////////////////////////////////////// //
1389 procedure g_Holmes_OnEvent (var ev
: TFUIEvent
);
1390 {$IF not DEFINED(HEADLESS)}
1392 doeat
: Boolean = false;
1395 {$IF not DEFINED(HEADLESS)}
1396 if g_Game_IsNet
then exit
;
1397 if not g_holmes_enabled
then exit
;
1398 if g_holmes_imfunctional
then exit
;
1400 holmesInitCommands();
1409 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1410 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1411 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1415 else if (ev
.mouse
) then
1424 uiDispatchEvent(ev
);
1425 if (not ev
.alive
) then exit
;
1429 if (gPlayer1
<> nil) and (vpSet
) then msbindExecute(ev
);
1434 if keybindExecute(ev
) then ev
.eat();
1435 if (ev
.alive
) then onKeyEvent(ev
);
1438 if (doeat
) then ev
.eat();
1443 // ////////////////////////////////////////////////////////////////////////// //
1444 procedure g_Holmes_Draw ();
1446 if g_Game_IsNet
then exit
;
1447 if not g_holmes_enabled
then exit
;
1448 if g_holmes_imfunctional
then exit
;
1450 {$IF not DEFINED(HEADLESS)}
1451 holmesInitCommands();
1454 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1455 glDisable(GL_STENCIL_TEST
);
1456 glDisable(GL_BLEND
);
1457 glDisable(GL_SCISSOR_TEST
);
1458 glDisable(GL_TEXTURE_2D
);
1460 if gGameOn
then plrDebugDraw();
1467 procedure g_Holmes_DrawUI ();
1469 if g_Game_IsNet
then exit
;
1470 if not g_holmes_enabled
then exit
;
1471 if g_holmes_imfunctional
then exit
;
1473 {$IF not DEFINED(HEADLESS)}
1474 gGfxDoClear
:= false;
1475 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1477 glMatrixMode(GL_MODELVIEW
);
1481 if assigned(postrenderFrameCB
) then postrenderFrameCB();
1489 // ////////////////////////////////////////////////////////////////////////// //
1490 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1491 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1492 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1494 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1495 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1496 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1497 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1499 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1500 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1502 procedure bcMonsterSpawn (s
: AnsiString);
1506 if not gGameOn
or g_Game_IsClient
then
1508 conwriteln('cannot spawn monster in this mode');
1511 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1512 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1513 monMarkedUID
:= mon
.UID
;
1516 procedure bcMonsterWakeup ();
1520 if (monMarkedUID
<> -1) then
1522 mon
:= g_Monsters_ByUID(monMarkedUID
);
1523 if (mon
<> nil) then mon
.WakeUp();
1527 procedure bcPlayerTeleport ();
1529 x
, y
, w
, h
: Integer;
1531 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1532 if (gPlayers
[0] <> nil) then
1534 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1535 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1539 procedure dbgToggleTraceBox (arg
: Integer=-1); begin if (arg
< 0) then showTraceBox
:= not showTraceBox
else showTraceBox
:= (arg
> 0); end;
1541 procedure dbgToggleHolmesPause (arg
: Integer=-1); begin if (arg
< 0) then g_Game_HolmesPause(not gPauseHolmes
) else g_Game_HolmesPause(arg
> 0); end;
1543 procedure cbAtcurSelectMonster ();
1544 function monsAtDump (mon
: TMonster
{; tag: Integer}): Boolean;
1546 result
:= true; // stop
1547 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1548 monMarkedUID
:= mon
.UID
;
1549 dumpPublishedProperties(mon
);
1553 x
, y
, w
, h
: Integer;
1555 it
: TMonsterGrid
.Iter
;
1558 if (Length(gPlayers
) > 0) then
1561 if (plr
<> nil) then
1563 plr
.getMapBox(x
, y
, w
, h
);
1564 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1566 dumpPublishedProperties(plr
);
1570 //e_WriteLog('===========================', MSG_NOTIFY);
1571 it
:= monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
);
1572 for mit
in it
do monsAtDump(mit
^);
1574 //e_WriteLog('---------------------------', MSG_NOTIFY);
1577 procedure cbAtcurDumpMonsters ();
1578 function monsAtDump (mon
: TMonster
{; tag: Integer}): Boolean;
1580 result
:= false; // don't stop
1581 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), TMsgType
.Notify
);
1585 it
: TMonsterGrid
.Iter
;
1587 it
:= monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
);
1588 if (it
.length
> 0) then
1590 e_WriteLog('===========================', TMsgType
.Notify
);
1591 for mit
in it
do monsAtDump(mit
^);
1592 e_WriteLog('---------------------------', TMsgType
.Notify
);
1597 procedure cbAtcurDumpWalls ();
1598 function wallToggle (pan
: TPanel
{; tag: Integer}): Boolean;
1600 result
:= false; // don't stop
1601 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1602 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
]);
1603 dumpPublishedProperties(pan
);
1606 hasTrigs
: Boolean = false;
1610 it
: TPanelGrid
.Iter
;
1612 platMarkedGUID
:= -1;
1613 it
:= mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, (GridTagWall
or GridTagDoor
));
1614 if (it
.length
> 0) then
1616 e_WriteLog('=== TOGGLE WALL ===', TMsgType
.Notify
);
1617 for mwit
in it
do wallToggle(mwit
^);
1618 e_WriteLog('--- toggle wall ---', TMsgType
.Notify
);
1621 if showTriggers
then
1623 for f
:= 0 to High(gTriggers
) do
1625 trig
:= @gTriggers
[f
];
1626 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1628 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1629 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1632 if hasTrigs
then writeln('--- triggers ---');
1636 procedure cbAtcurToggleWalls ();
1637 function wallToggle (pan
: TPanel
{; tag: Integer}): Boolean;
1639 result
:= false; // don't stop
1640 //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);
1641 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1645 it
: TPanelGrid
.Iter
;
1647 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1648 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1649 it
:= mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, (GridTagWall
or GridTagDoor
));
1650 for mwit
in it
do wallToggle(mwit
^);
1655 // ////////////////////////////////////////////////////////////////////////// //
1656 procedure holmesInitCommands ();
1658 if (cmdlist
<> nil) then exit
;
1659 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1660 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1661 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1662 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1664 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1665 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1666 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1667 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1668 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'wake up selected monster', 'monster control');
1670 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1672 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1673 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1675 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1677 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1678 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1679 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1681 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1682 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1683 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1684 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1686 cmdAdd('dbg_tracebox', dbgToggleTraceBox
, 'test traceBox()', 'player control');
1688 cmdAdd('hlm_pause', dbgToggleHolmesPause
, '"Holmes" pause mode', 'game control');
1692 procedure holmesInitBinds ();
1695 pr
: TTextParser
= nil;
1696 s
, kn
, v
: AnsiString;
1701 if not keybindsInited
then
1704 keybindAdd('F1', 'win_help');
1705 keybindAdd('M-F1', 'win_options');
1706 keybindAdd('C-O', 'win_outline');
1707 keybindAdd('C-L', 'win_layers');
1709 keybindAdd('M-M', 'mon_think_step');
1710 keybindAdd('M-I', 'mon_info');
1711 keybindAdd('M-L', 'mon_los_plr');
1712 keybindAdd('M-G', 'mon_cells');
1713 keybindAdd('M-A', 'mon_wakeup');
1715 keybindAdd('M-P', 'mplat_step');
1716 keybindAdd('M-O', 'mplat_toggle');
1718 keybindAdd('C-T', 'plr_teleport');
1719 keybindAdd('M-T', 'dbg_tracebox');
1721 keybindAdd('C-P', 'dbg_curpos');
1722 keybindAdd('C-G', 'dbg_grid');
1723 keybindAdd('C-X', 'dbg_triggers');
1725 keybindAdd('C-1', 'mon_spawn zombie');
1727 keybindAdd('C-S-P', 'hlm_pause');
1730 msbindAdd('LMB', 'atcur_select_monster');
1731 msbindAdd('M-LMB', 'atcur_dump_monsters');
1732 msbindAdd('RMB', 'atcur_dump_walls');
1733 msbindAdd('M-RMB', 'atcur_disable_walls');
1735 // load bindings from file
1737 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1738 pr
:= TFileTextParser
.Create(st
);
1739 conwriteln('parsing "holmes.rc"...');
1740 while (pr
.tokType
<> pr
.TTEOF
) do
1743 if (s
= 'stop') then break
1744 else if (s
= 'unbind_keys') then keybinds
:= nil
1745 else if (s
= 'unbind_mouse') then msbinds
:= nil
1746 else if (s
= 'bind') then
1748 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1749 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1750 else s
:= pr
.expectId();
1752 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1753 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1754 else v
:= pr
.expectId();
1756 kn
:= parseModKeys(s
, kmods
, mbuts
);
1757 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1767 except on e
: Exception
do // sorry
1768 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1770 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1780 fuiEventCB
:= g_Holmes_OnEvent
;
1781 //uiContext.font := 'win14';
1783 conRegVar('hlm_ui_scale', @fuiRenderScale
, 0.01, 5.0, 'Holmes UI scale', '', false);