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
,
33 // both for but and for bstate
46 kind
: Byte; // motion, press, release
48 dx
, dy
: Integer; // for wheel this is wheel motion, otherwise this is relative mouse motion
49 but
: Word; // current pressed/released button, or 0 for motion
50 bstate
: Word; // button state
51 kstate
: Word; // keyboard state (see THKeyEvent);
68 scan
: Word; // SDL_SCANCODE_XXX
69 sym
: Word; // SDLK_XXX
70 bstate
: Word; // button state
71 kstate
: Word; // keyboard state
76 procedure g_Holmes_VidModeChanged ();
77 procedure g_Holmes_WindowFocused ();
78 procedure g_Holmes_WindowBlured ();
80 procedure g_Holmes_Draw ();
81 procedure g_Holmes_DrawUI ();
83 function g_Holmes_MouseEvent (var ev
: THMouseEvent
): Boolean; // returns `true` if event was eaten
84 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean; // returns `true` if event was eaten
87 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
88 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
89 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
92 operator
= (constref ev
: THKeyEvent
; const s
: AnsiString): Boolean;
93 operator
= (const s
: AnsiString; constref ev
: THKeyEvent
): Boolean;
95 operator
= (constref ev
: THMouseEvent
; const s
: AnsiString): Boolean;
96 operator
= (const s
: AnsiString; constref ev
: THMouseEvent
): Boolean;
100 g_holmes_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
101 g_holmes_ui_scale
: Single = 1.0;
107 {rttiobj,} typinfo
, e_texture
,
108 SysUtils
, Classes
, GL
, SDL2
,
109 MAPDEF
, g_main
, g_options
,
110 utils
, hashtable
, xparser
;
114 //globalInited: Boolean = false;
117 msB
: Word = 0; // button state
118 kbS
: Word = 0; // keyboard modifiers state
119 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
120 showMonsInfo
: Boolean = false;
121 showMonsLOS2Plr
: Boolean = false;
122 showAllMonsCells
: Boolean = false;
123 showMapCurPos
: Boolean = false;
124 showLayersWindow
: Boolean = false;
125 showOutlineWindow
: Boolean = false;
126 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
127 showTraceBox
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
130 // ////////////////////////////////////////////////////////////////////////// //
131 {$INCLUDE g_holmes.inc}
132 {$INCLUDE g_holmes_ui.inc}
135 // ////////////////////////////////////////////////////////////////////////// //
136 // any mods = 255: nothing was defined
137 function parseModKeys (const s
: AnsiString; out kmods
: Byte; out mbuts
: Byte): AnsiString;
144 //while (pos <= Length(s)) and (s[pos] <= ' ') do Inc(pos);
145 if (pos
< Length(s
)) and ((s
[pos
] = '+') or (s
[pos
] = '-') or (s
[pos
] = '*')) then Inc(pos
);
146 while (pos
< Length(s
)) do
148 if (Length(s
)-pos
>= 2) and (s
[pos
+1] = '-') then
151 'C', 'c': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModCtrl
; Inc(pos
, 2); continue
; end;
152 'M', 'm': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModAlt
; Inc(pos
, 2); continue
; end;
153 'S', 's': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModShift
; Inc(pos
, 2); continue
; end;
157 if (Length(s
)-pos
>= 4) and ((s
[pos
+1] = 'M') or (s
[pos
+1] = 'm')) and ((s
[pos
+2] = 'B') or (s
[pos
+1] = 'b')) and (s
[pos
+3] = '-') then
160 'L', 'l': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Left
; Inc(pos
, 4); continue
; end;
161 'R', 'r': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Right
; Inc(pos
, 4); continue
; end;
162 'M', 'm': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Middle
; Inc(pos
, 4); continue
; end;
169 while (epos
> pos
) and (s
[epos
-1] <= ' ') do Dec(epos
);
170 if (epos
> pos
) then result
:= Copy(s
, pos
, epos
-pos
) else result
:= '';
174 operator
= (constref ev
: THKeyEvent
; const s
: AnsiString): Boolean;
182 if (Length(s
) > 0) then
184 if (s
[1] = '+') then begin if (ev
.kind
<> ev
.Press
) then exit
; end
185 else if (s
[1] = '-') then begin if (ev
.kind
<> ev
.Release
) then exit
; end
186 else if (s
[1] = '*') then begin end
187 else if (ev
.kind
<> ev
.Press
) then exit
;
189 kname
:= parseModKeys(s
, kmods
, mbuts
);
190 if (kmods
= 255) then kmods
:= 0;
191 if (ev
.kstate
<> kmods
) then exit
;
192 if (mbuts
<> 255) and (ev
.bstate
<> mbuts
) then exit
;
193 for f
:= 1 to High(e_KeyNames
) do
195 if (CompareText(kname
, e_KeyNames
[f
]) = 0) then
197 result
:= (ev
.scan
= f
);
204 operator
= (const s
: AnsiString; constref ev
: THKeyEvent
): Boolean;
210 operator
= (constref ev
: THMouseEvent
; const s
: AnsiString): Boolean;
219 if (Length(s
) > 0) then
221 if (s
[1] = '+') then begin if (ev
.kind
<> ev
.Press
) then exit
; end
222 else if (s
[1] = '-') then begin if (ev
.kind
<> ev
.Release
) then exit
; end
223 else if (s
[1] = '*') then begin if (ev
.kind
<> ev
.Motion
) then exit
; end
224 else if (ev
.kind
<> ev
.Press
) then exit
;
227 kname
:= parseModKeys(s
, kmods
, mbuts
);
228 if (CompareText(kname
, 'LMB') = 0) then but
:= THMouseEvent
.Left
229 else if (CompareText(kname
, 'RMB') = 0) then but
:= THMouseEvent
.Right
230 else if (CompareText(kname
, 'MMB') = 0) then but
:= THMouseEvent
.Middle
231 else if (CompareText(kname
, 'None') = 0) then but
:= 0
234 //conwritefln('s=[%s]; kname=[%s]; kmods=%s; mbuts=%s; but=%s', [s, kname, kmods, mbuts, but]);
236 if (mbuts
= 255) then mbuts
:= 0;
237 if (kmods
= 255) then kmods
:= 0;
238 if (ev
.kstate
<> kmods
) then exit
;
240 if (ev
.kind
= ev
.Press
) then mbuts
:= mbuts
or but
241 else if (ev
.kind
= ev
.Release
) then mbuts
:= mbuts
and (not but
);
243 //conwritefln(' ev.bstate=%s; ev.but=%s; mbuts=%s', [ev.bstate, ev.but, mbuts]);
245 result
:= (ev
.bstate
= mbuts
) and (ev
.but
= but
);
249 operator
= (const s
: AnsiString; constref ev
: THMouseEvent
): Boolean;
255 // ////////////////////////////////////////////////////////////////////////// //
256 function typeKind2Str (t
: TTypeKind
): AnsiString;
259 tkUnknown
: result
:= 'Unknown';
260 tkInteger
: result
:= 'Integer';
261 tkChar
: result
:= 'Char';
262 tkEnumeration
: result
:= 'Enumeration';
263 tkFloat
: result
:= 'Float';
264 tkSet
: result
:= 'Set';
265 tkMethod
: result
:= 'Method';
266 tkSString
: result
:= 'SString';
267 tkLString
: result
:= 'LString';
268 tkAString
: result
:= 'AString';
269 tkWString
: result
:= 'WString';
270 tkVariant
: result
:= 'Variant';
271 tkArray
: result
:= 'Array';
272 tkRecord
: result
:= 'Record';
273 tkInterface
: result
:= 'Interface';
274 tkClass
: result
:= 'Class';
275 tkObject
: result
:= 'Object';
276 tkWChar
: result
:= 'WChar';
277 tkBool
: result
:= 'Bool';
278 tkInt64
: result
:= 'Int64';
279 tkQWord
: result
:= 'QWord';
280 tkDynArray
: result
:= 'DynArray';
281 tkInterfaceRaw
: result
:= 'InterfaceRaw';
282 tkProcVar
: result
:= 'ProcVar';
283 tkUString
: result
:= 'UString';
284 tkUChar
: result
:= 'UChar';
285 tkHelper
: result
:= 'Helper';
286 tkFile
: result
:= 'File';
287 tkClassRef
: result
:= 'ClassRef';
288 tkPointer
: result
:= 'Pointer';
289 else result
:= '<unknown>';
294 procedure dumpPublishedProperties (obj
: TObject
);
301 if (obj
= nil) then exit
;
302 e_LogWritefln('Object of type ''%s'':', [obj
.ClassName
]);
304 pt
:= GetTypeData(pi
);
305 e_LogWritefln('property count: %s', [pt
.PropCount
]);
306 GetMem(pp
, pt
^.PropCount
*sizeof(Pointer));
308 j
:= GetPropList(pi
, [tkInteger
, tkBool
, tkSString
, tkLString
, tkAString
, tkSet
, tkEnumeration
], pp
);
309 //e_LogWritefln('ordinal property count: %s', [j]);
312 if (typinfo
.PropType(obj
, pp
^[i
].name
) in [tkSString
, tkLString
, tkAString
]) then
314 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetStrProp(obj
, pp
^[i
])]);
316 else if (typinfo
.PropType(obj
, pp
^[i
].name
) = tkSet
) then
318 e_LogWritefln(' #%s: <%s>; type: %s; value: %s', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetSetProp(obj
, pp
^[i
], true)]);
320 else if (typinfo
.PropType(obj
, pp
^[i
].name
) = tkEnumeration
) then
322 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetEnumProp(obj
, pp
^[i
])]);
326 e_LogWritefln(' #%s: <%s>; type: %s; value: %s', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetOrdProp(obj
, pp
^[i
])]);
335 //FIXME: autogenerate
336 function trigType2Str (ttype
: Integer): AnsiString;
338 result
:= '<unknown>';
340 TRIGGER_NONE
: result
:= 'none';
341 TRIGGER_EXIT
: result
:= 'exit';
342 TRIGGER_TELEPORT
: result
:= 'teleport';
343 TRIGGER_OPENDOOR
: result
:= 'opendoor';
344 TRIGGER_CLOSEDOOR
: result
:= 'closedoor';
345 TRIGGER_DOOR
: result
:= 'door';
346 TRIGGER_DOOR5
: result
:= 'door5';
347 TRIGGER_CLOSETRAP
: result
:= 'closetrap';
348 TRIGGER_TRAP
: result
:= 'trap';
349 TRIGGER_PRESS
: result
:= 'press';
350 TRIGGER_SECRET
: result
:= 'secret';
351 TRIGGER_LIFTUP
: result
:= 'liftup';
352 TRIGGER_LIFTDOWN
: result
:= 'liftdown';
353 TRIGGER_LIFT
: result
:= 'lift';
354 TRIGGER_TEXTURE
: result
:= 'texture';
355 TRIGGER_ON
: result
:= 'on';
356 TRIGGER_OFF
: result
:= 'off';
357 TRIGGER_ONOFF
: result
:= 'onoff';
358 TRIGGER_SOUND
: result
:= 'sound';
359 TRIGGER_SPAWNMONSTER
: result
:= 'spawnmonster';
360 TRIGGER_SPAWNITEM
: result
:= 'spawnitem';
361 TRIGGER_MUSIC
: result
:= 'music';
362 TRIGGER_PUSH
: result
:= 'push';
363 TRIGGER_SCORE
: result
:= 'score';
364 TRIGGER_MESSAGE
: result
:= 'message';
365 TRIGGER_DAMAGE
: result
:= 'damage';
366 TRIGGER_HEALTH
: result
:= 'health';
367 TRIGGER_SHOT
: result
:= 'shot';
368 TRIGGER_EFFECT
: result
:= 'effect';
369 TRIGGER_SCRIPT
: result
:= 'script';
373 // ////////////////////////////////////////////////////////////////////////// //
374 {$INCLUDE g_holmes_cmd.inc}
375 procedure holmesInitCommands (); forward;
376 procedure holmesInitBinds (); forward;
379 // ////////////////////////////////////////////////////////////////////////// //
381 g_ol_nice
: Boolean = false;
382 g_ol_fill_walls
: Boolean = false;
383 g_ol_rlayer_back
: Boolean = false;
384 g_ol_rlayer_step
: Boolean = false;
385 g_ol_rlayer_wall
: Boolean = false;
386 g_ol_rlayer_door
: Boolean = false;
387 g_ol_rlayer_acid1
: Boolean = false;
388 g_ol_rlayer_acid2
: Boolean = false;
389 g_ol_rlayer_water
: Boolean = false;
390 g_ol_rlayer_fore
: Boolean = false;
393 // ////////////////////////////////////////////////////////////////////////// //
395 winHelp
: THTopWindow
= nil;
396 winOptions
: THTopWindow
= nil;
397 winLayers
: THTopWindow
= nil;
398 winOutlines
: THTopWindow
= nil;
401 procedure createHelpWindow (); forward;
402 procedure createOptionsWindow (); forward;
403 procedure createLayersWindow (); forward;
404 procedure createOutlinesWindow (); forward;
407 procedure toggleLayersWindowCB (me
: THControl
; checked
: Integer);
409 if showLayersWindow
then
411 if (winLayers
= nil) then createLayersWindow();
412 uiAddWindow(winLayers
);
416 uiRemoveWindow(winLayers
);
421 procedure toggleOutlineWindowCB (me
: THControl
; checked
: Integer);
423 if showOutlineWindow
then
425 if (winOutlines
= nil) then createOutlinesWindow();
426 uiAddWindow(winOutlines
);
430 uiRemoveWindow(winOutlines
);
435 procedure createHelpWindow ();
437 llb
: THCtlSimpleText
;
438 slist
: array of AnsiString = nil;
440 bind
: THolmesBinding
;
441 f
, maxkeylen
: Integer;
444 for cmd
in cmdlist
do cmd
.helpmark
:= false;
447 for bind
in keybinds
do
449 if (Length(bind
.key
) = 0) then continue
;
450 if cmdlist
.get(bind
.cmdName
, cmd
) then
452 if (Length(cmd
.help
) > 0) then
454 cmd
.helpmark
:= true;
455 if (maxkeylen
< Length(bind
.key
)) then maxkeylen
:= Length(bind
.key
);
460 for cmd
in cmdlist
do
462 if not cmd
.helpmark
then continue
;
463 if (Length(cmd
.help
) = 0) then continue
;
465 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
466 if (f
= Length(slist
)) then
468 SetLength(slist
, Length(slist
)+1);
469 slist
[High(slist
)] := cmd
.section
;
473 llb
:= THCtlSimpleText
.Create(0, 0);
474 for f
:= 0 to High(slist
) do
476 if (f
> 0) then llb
.appendItem('');
477 llb
.appendItem(slist
[f
], true, true);
478 for cmd
in cmdlist
do
480 if not cmd
.helpmark
then continue
;
481 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
482 for bind
in keybinds
do
484 if (Length(bind
.key
) = 0) then continue
;
485 if (cmd
.name
= bind
.cmdName
) then
488 while (Length(s
) < maxkeylen
) do s
+= ' ';
489 s
:= ' '+s
+' -- '+cmd
.help
;
497 for bind
in msbinds
do
499 if (Length(bind
.key
) = 0) then continue
;
500 if cmdlist
.get(bind
.cmdName
, cmd
) then
502 if (Length(cmd
.help
) > 0) then
504 cmd
.helpmark
:= true;
505 if (maxkeylen
< Length(bind
.key
)) then maxkeylen
:= Length(bind
.key
);
511 llb
.appendItem('mouse', true, true);
512 for bind
in msbinds
do
514 if (Length(bind
.key
) = 0) then continue
;
515 if cmdlist
.get(bind
.cmdName
, cmd
) then
517 if (Length(cmd
.help
) > 0) then
520 while (Length(s
) < maxkeylen
) do s
+= ' ';
521 s
:= ' '+s
+' -- '+cmd
.help
;
527 winHelp
:= THTopWindow
.Create('Holmes Help', 10, 10);
528 winHelp
.escClose
:= true;
529 winHelp
.appendChild(llb
);
530 winHelp
.centerInScreen();
534 procedure winLayersClosed (me
: THControl
; dummy
: Integer); begin showLayersWindow
:= false; end;
535 procedure winOutlinesClosed (me
: THControl
; dummy
: Integer); begin showOutlineWindow
:= false; end;
537 procedure createLayersWindow ();
541 llb
:= THCtlCBListBox
.Create(0, 0);
542 llb
.appendItem('background', @g_rlayer_back
);
543 llb
.appendItem('steps', @g_rlayer_step
);
544 llb
.appendItem('walls', @g_rlayer_wall
);
545 llb
.appendItem('doors', @g_rlayer_door
);
546 llb
.appendItem('acid1', @g_rlayer_acid1
);
547 llb
.appendItem('acid2', @g_rlayer_acid2
);
548 llb
.appendItem('water', @g_rlayer_water
);
549 llb
.appendItem('foreground', @g_rlayer_fore
);
550 winLayers
:= THTopWindow
.Create('layers', 10, 10);
551 winLayers
.escClose
:= true;
552 winLayers
.appendChild(llb
);
553 winLayers
.closeCB
:= winLayersClosed
;
557 procedure createOutlinesWindow ();
561 llb
:= THCtlCBListBox
.Create(0, 0);
562 llb
.appendItem('background', @g_ol_rlayer_back
);
563 llb
.appendItem('steps', @g_ol_rlayer_step
);
564 llb
.appendItem('walls', @g_ol_rlayer_wall
);
565 llb
.appendItem('doors', @g_ol_rlayer_door
);
566 llb
.appendItem('acid1', @g_ol_rlayer_acid1
);
567 llb
.appendItem('acid2', @g_ol_rlayer_acid2
);
568 llb
.appendItem('water', @g_ol_rlayer_water
);
569 llb
.appendItem('foreground', @g_ol_rlayer_fore
);
570 llb
.appendItem('OPTIONS', nil);
571 llb
.appendItem('fill walls', @g_ol_fill_walls
);
572 llb
.appendItem('contours', @g_ol_nice
);
573 winOutlines
:= THTopWindow
.Create('outlines', 100, 10);
574 winOutlines
.escClose
:= true;
575 winOutlines
.appendChild(llb
);
576 winOutlines
.closeCB
:= winOutlinesClosed
;
580 procedure createOptionsWindow ();
584 llb
:= THCtlCBListBox
.Create(0, 0);
585 llb
.appendItem('map grid', @showGrid
);
586 llb
.appendItem('cursor position on map', @showMapCurPos
);
587 llb
.appendItem('monster info', @showMonsInfo
);
588 llb
.appendItem('monster LOS to player', @showMonsLOS2Plr
);
589 llb
.appendItem('monster cells (SLOW!)', @showAllMonsCells
);
590 llb
.appendItem('draw triggers (SLOW!)', @showTriggers
);
591 llb
.appendItem('WINDOWS', nil);
592 llb
.appendItem('layers window', @showLayersWindow
, toggleLayersWindowCB
);
593 llb
.appendItem('outline window', @showOutlineWindow
, toggleOutlineWindowCB
);
594 winOptions
:= THTopWindow
.Create('Holmes Options', 100, 100);
595 winOptions
.escClose
:= true;
596 winOptions
.appendChild(llb
);
597 winOptions
.centerInScreen();
601 procedure toggleLayersWindow (arg
: Integer=-1);
603 showLayersWindow
:= not showLayersWindow
;
604 toggleLayersWindowCB(nil, 0);
607 procedure toggleOutlineWindow (arg
: Integer=-1);
609 showOutlineWindow
:= not showOutlineWindow
;
610 toggleOutlineWindowCB(nil, 0);
613 procedure toggleHelpWindow (arg
: Integer=-1);
615 if (winHelp
= nil) then createHelpWindow();
616 if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
);
619 procedure toggleOptionsWindow (arg
: Integer=-1);
621 if (winOptions
= nil) then createOptionsWindow();
622 if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
);
626 // ////////////////////////////////////////////////////////////////////////// //
627 procedure g_Holmes_VidModeChanged ();
629 e_WriteLog(Format('Holmes: videomode changed: %dx%d', [gScreenWidth
, gScreenHeight
]), MSG_NOTIFY
);
630 // texture space is possibly lost here, idc
636 //createCursorTexture();
639 procedure g_Holmes_WindowFocused ();
645 procedure g_Holmes_WindowBlured ();
650 // ////////////////////////////////////////////////////////////////////////// //
652 vpSet
: Boolean = false;
655 laserSet
: Boolean = false;
656 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
657 monMarkedUID
: Integer = -1;
658 platMarkedGUID
: Integer = -1;
661 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
668 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
675 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
682 laserSet
:= laserSet
; // shut up, fpc!
686 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
687 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
690 procedure plrDebugMouse (var ev
: THMouseEvent
);
692 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
693 if (gPlayer1
= nil) or not vpSet
then exit
;
694 //if (ev.kind <> THMouseEvent.Press) then exit;
695 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
701 edgeBmp
: array of Byte = nil;
704 procedure drawOutlines ();
708 procedure clearEdgeBmp ();
710 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
711 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
714 procedure drawPanel (pan
: TPanel
);
716 sx
, len
, y0
, y1
: Integer;
718 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
719 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
720 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
721 if g_ol_nice
or g_ol_fill_walls
then
725 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
726 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
727 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
728 if (len
< 1) then exit
;
730 assert(sx
+len
<= gWinSizeX
+4);
733 if (y0
< 0) then y0
:= 0;
734 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
737 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
743 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
752 procedure flushLine ();
754 if (lsy
> 0) and (lsx
> 0) then
759 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
765 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
766 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
774 procedure startLine (y
: Integer);
780 procedure putPixel (x
: Integer);
782 if (x
< 1) then exit
;
783 if (lex
+1 <> x
) then flushLine();
784 if (lsx
< 0) then lsx
:= x
;
788 procedure drawEdges ();
794 glDisable(GL_TEXTURE_2D
);
797 glDisable(GL_LINE_SMOOTH
);
798 glDisable(GL_POLYGON_SMOOTH
);
799 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
802 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
808 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
809 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
810 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
821 procedure drawFilledWalls ();
827 glDisable(GL_TEXTURE_2D
);
830 glDisable(GL_LINE_SMOOTH
);
831 glDisable(GL_POLYGON_SMOOTH
);
832 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
835 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
839 if (a
[0] <> 0) then putPixel(x
);
846 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
854 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
855 for f
:= 0 to High(parr
) do
858 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
859 if ((pan
.PanelType
and ptype
) = 0) then continue
;
862 if g_ol_nice
then drawEdges();
863 if g_ol_fill_walls
then drawFilledWalls();
869 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
871 result
:= false; // don't stop
872 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
873 if ((pan
.PanelType
and xptag
) = 0) then exit
;
877 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
883 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
884 else panelTypeToTag(ptype
);
885 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
886 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
887 if g_ol_nice
then drawEdges();
888 if g_ol_fill_walls
then drawFilledWalls();
892 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
893 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
894 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
895 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
896 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
897 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
898 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
899 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
903 procedure plrDebugDraw ();
904 procedure drawTileGrid ();
908 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
910 drawLine(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, 96, 96, 96, 255);
913 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
915 drawLine(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
, 96, 96, 96, 255);
919 procedure drawAwakeCells ();
923 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
925 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
927 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
929 fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
, 128, 0, 128, 64);
935 procedure drawTraceBox ();
938 px
, py
, pw
, ph
: Integer;
943 if (Length(gPlayers
) < 1) then exit
;
945 if (plr
= nil) then exit
;
946 plr
.getMapBox(px
, py
, pw
, ph
);
947 drawRect(px
, py
, pw
, ph
, 255, 0, 255, 200);
948 pdx
:= pmsCurMapX
-(px
+pw
div 2);
949 pdy
:= pmsCurMapY
-(py
+ph
div 2);
950 drawLine(px
+pw
div 2, py
+ph
div 2, px
+pw
div 2+pdx
, py
+ph
div 2+pdy
, 255, 0, 255, 200);
951 pan
:= mapGrid
.traceBox(ex
, ey
, px
, py
, pw
, ph
, pdx
, pdy
, nil, GridTagObstacle
);
954 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, 255, 255, 255, 180);
958 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, 255, 255, 0, 180);
960 drawRect(ex
, ey
, pw
, ph
, 255, 127, 0, 180);
963 procedure hilightCell (cx
, cy
: Integer);
965 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 0, 128, 0, 64);
968 procedure hilightCell1 (cx
, cy
: Integer);
970 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
971 cx
:= cx
and (not (monsGrid
.tileSize
-1));
972 cy
:= cy
and (not (monsGrid
.tileSize
-1));
973 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 255, 255, 0, 92);
976 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
978 result
:= false; // don't stop
979 if (pan
= nil) then exit
; // cell completion, ignore
980 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
981 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, 0, 128, 128, 64);
984 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
987 mx
, my
, mw
, mh
: Integer;
990 mon
.getMapBox(mx
, my
, mw
, mh
);
991 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
992 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
994 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
998 procedure drawMonsterInfo (mon
: TMonster
);
1000 mx
, my
, mw
, mh
: Integer;
1002 procedure drawMonsterTargetLine ();
1004 emx
, emy
, emw
, emh
: Integer;
1009 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
1011 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
1012 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1014 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
1016 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
1017 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1023 mon
.getMapBox(mx
, my
, mw
, mh
);
1024 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
1025 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1027 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
1031 procedure drawLOS2Plr ();
1033 emx
, emy
, emw
, emh
: Integer;
1037 eplr
:= gPlayers
[0];
1038 if (eplr
= nil) then exit
;
1039 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1040 mon
.getMapBox(mx
, my
, mw
, mh
);
1041 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
1042 {$IF DEFINED(D2F_DEBUG)}
1043 mapGrid
.dbgRayTraceTileHitCB
:= hilightCell1
;
1045 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1046 //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
1048 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
1050 {$IF DEFINED(D2F_DEBUG)}
1051 mapGrid
.dbgRayTraceTileHitCB
:= nil;
1056 if (mon
= nil) then exit
;
1057 mon
.getMapBox(mx
, my
, mw
, mh
);
1060 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1062 if showMonsInfo
then
1064 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1065 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
1070 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), 255, 127, 0); my
-= 8;
1072 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), 255, 127, 0); my
-= 8;
1074 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), 255, 127, 0); my
-= 8;
1076 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), 255, 127, 0); my
-= 8;
1078 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), 255, 127, 0); my
-= 8;
1080 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), 255, 127, 0); my
-= 8;
1081 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), 255, 127, 0); my
-= 8;
1084 drawMonsterTargetLine();
1085 if showMonsLOS2Plr
then drawLOS2Plr();
1087 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1088 property MonsterPain: Integer read FPain write FPain;
1089 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1093 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1095 result
:= false; // don't stop
1096 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1099 procedure drawSelectedPlatformCells ();
1103 if not showGrid
then exit
;
1104 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1105 if (pan
= nil) then exit
;
1106 mapGrid
.forEachBodyCell(pan
.proxyId
, hilightCell
);
1107 drawRect(pan
.x
, pan
.y
, pan
.width
, pan
.height
, 0, 200, 0, 200);
1110 procedure drawTrigger (var trig
: TTrigger
);
1112 procedure drawPanelDest (pguid
: Integer);
1116 pan
:= g_Map_PanelByGUID(pguid
);
1117 if (pan
= nil) then exit
;
1119 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1120 pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2,
1128 fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
, 255, 0, 255, 96);
1129 tts
:= trigType2Str(trig
.TriggerType
);
1130 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1131 darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1132 drawText6(tx
, trig
.y
-9, tts
, 255, 127, 0);
1133 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1134 darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1135 drawText6(tx
, trig
.y
-19, trig
.mapId
, 255, 255, 0);
1136 drawPanelDest(trig
.trigPanelGUID
);
1137 case trig
.TriggerType
of
1138 TRIGGER_NONE
: begin end;
1139 TRIGGER_EXIT
: begin end;
1140 TRIGGER_TELEPORT
: begin end;
1141 TRIGGER_OPENDOOR
: begin end;
1142 TRIGGER_CLOSEDOOR
: begin end;
1143 TRIGGER_DOOR
: begin end;
1144 TRIGGER_DOOR5
: begin end;
1145 TRIGGER_CLOSETRAP
: begin end;
1146 TRIGGER_TRAP
: begin end;
1147 TRIGGER_SECRET
: begin end;
1148 TRIGGER_LIFTUP
: begin end;
1149 TRIGGER_LIFTDOWN
: begin end;
1150 TRIGGER_LIFT
: begin end;
1151 TRIGGER_TEXTURE
: begin end;
1152 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1154 if (trig
.trigDataRec
.trigTWidth
> 0) and (trig
.trigDataRec
.trigTHeight
> 0) then
1157 trig
.trigDataRec
.trigTX
, trig
.trigDataRec
.trigTY
,
1158 trig
.trigDataRec
.trigTWidth
, trig
.trigDataRec
.trigTHeight
,
1161 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1162 trig
.trigDataRec
.trigTX
+trig
.trigDataRec
.trigTWidth
div 2,
1163 trig
.trigDataRec
.trigTY
+trig
.trigDataRec
.trigTHeight
div 2,
1167 TRIGGER_SOUND
: begin end;
1168 TRIGGER_SPAWNMONSTER
: begin end;
1169 TRIGGER_SPAWNITEM
: begin end;
1170 TRIGGER_MUSIC
: begin end;
1171 TRIGGER_PUSH
: begin end;
1172 TRIGGER_SCORE
: begin end;
1173 TRIGGER_MESSAGE
: begin end;
1174 TRIGGER_DAMAGE
: begin end;
1175 TRIGGER_HEALTH
: begin end;
1176 TRIGGER_SHOT
: begin end;
1177 TRIGGER_EFFECT
: begin end;
1178 TRIGGER_SCRIPT
: begin end;
1181 //trigPanelId: Integer;
1184 procedure drawTriggers ();
1188 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1191 procedure drawGibsBoxes ();
1194 px
, py
, pw
, ph
: Integer;
1197 for f
:= 0 to High(gGibs
) do
1202 gib
.getMapBox(px
, py
, pw
, ph
);
1203 drawRect(px
, py
, pw
, ph
, 255, 0, 255);
1210 mx
, my
, mw
, mh
: Integer;
1214 if (gPlayer1
= nil) then exit
;
1216 glEnable(GL_SCISSOR_TEST
);
1217 glScissor(0, gWinSizeY
-gPlayerScreenSize
.Y
-1, vpw
, vph
);
1220 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
1221 glTranslatef(-vpx
, -vpy
, 0);
1223 if (showGrid
) then drawTileGrid();
1226 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
1228 if (monMarkedUID
<> -1) then
1230 mon
:= g_Monsters_ByUID(monMarkedUID
);
1231 if (mon
<> nil) then
1233 mon
.getMapBox(mx
, my
, mw
, mh
);
1234 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
1235 drawMonsterInfo(mon
);
1239 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1240 if showTriggers
then drawTriggers();
1241 if showGrid
then drawSelectedPlatformCells();
1245 if showTraceBox
then drawTraceBox();
1250 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1252 {$IF DEFINED(D2F_DEBUG)}
1253 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1255 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1256 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1257 {$IF DEFINED(D2F_DEBUG)}
1258 mapGrid.dbgRayTraceTileHitCB := nil;
1261 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1262 if (pan <> nil) then writeln('hit!');
1267 glDisable(GL_SCISSOR_TEST
);
1269 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), 255, 255, 0);
1273 // ////////////////////////////////////////////////////////////////////////// //
1274 function g_Holmes_MouseEvent (var ev
: THMouseEvent
): Boolean;
1278 holmesInitCommands();
1281 msX
:= trunc(ev
.x
/g_holmes_ui_scale
);
1282 msY
:= trunc(ev
.y
/g_holmes_ui_scale
);
1287 he
.x
:= trunc(he
.x
/g_holmes_ui_scale
);
1288 he
.y
:= trunc(he
.y
/g_holmes_ui_scale
);
1289 if not uiMouseEvent(he
) then plrDebugMouse(he
);
1293 // ////////////////////////////////////////////////////////////////////////// //
1294 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean;
1295 {$IF DEFINED(D2F_DEBUG)}
1302 procedure dummyWallTrc (cx
, cy
: Integer);
1307 holmesInitCommands();
1313 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1314 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1315 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1318 if uiKeyEvent(ev
) then begin result
:= true; exit
; end;
1319 if keybindExecute(ev
) then begin result
:= true; exit
; end;
1321 if (ev
.kind
= THKeyEvent
.Press
) then
1323 {$IF DEFINED(D2F_DEBUG)}
1324 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1325 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
1326 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
1332 SDL_SCANCODE_UP
: dy
-= 120;
1333 SDL_SCANCODE_DOWN
: dy
+= 120;
1334 SDL_SCANCODE_LEFT
: dx
-= 120;
1335 SDL_SCANCODE_RIGHT
: dx
+= 120;
1337 {$IF DEFINED(D2F_DEBUG)}
1338 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1339 mapGrid
.dbgShowTraceLog
:= true;
1341 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1342 {$IF DEFINED(D2F_DEBUG)}
1343 //mapGrid.dbgRayTraceTileHitCB := nil;
1344 mapGrid
.dbgShowTraceLog
:= false;
1346 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1354 // ////////////////////////////////////////////////////////////////////////// //
1355 procedure g_Holmes_Draw ();
1357 {$IF not DEFINED(HEADLESS)}
1358 holmesInitCommands();
1361 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1362 glDisable(GL_STENCIL_TEST
);
1363 glDisable(GL_BLEND
);
1364 glDisable(GL_SCISSOR_TEST
);
1365 glDisable(GL_TEXTURE_2D
);
1377 procedure g_Holmes_DrawUI ();
1379 {$IF not DEFINED(HEADLESS)}
1381 glScalef(g_holmes_ui_scale
, g_holmes_ui_scale
, 1.0);
1389 // ////////////////////////////////////////////////////////////////////////// //
1390 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1391 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1392 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1394 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1395 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1396 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1397 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1399 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1400 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1402 procedure bcMonsterSpawn (s
: AnsiString);
1406 if not gGameOn
or g_Game_IsClient
then
1408 conwriteln('cannot spawn monster in this mode');
1411 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1412 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1413 monMarkedUID
:= mon
.UID
;
1416 procedure bcMonsterWakeup ();
1420 if (monMarkedUID
<> -1) then
1422 mon
:= g_Monsters_ByUID(monMarkedUID
);
1423 if (mon
<> nil) then mon
.WakeUp();
1427 procedure bcPlayerTeleport ();
1429 x
, y
, w
, h
: Integer;
1431 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1432 if (gPlayers
[0] <> nil) then
1434 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1435 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1439 procedure dbgToggleTraceBox (arg
: Integer=-1); begin if (arg
< 0) then showTraceBox
:= not showTraceBox
else showTraceBox
:= (arg
> 0); end;
1441 procedure cbAtcurSelectMonster ();
1442 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1444 result
:= true; // stop
1445 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1446 monMarkedUID
:= mon
.UID
;
1447 dumpPublishedProperties(mon
);
1451 x
, y
, w
, h
: Integer;
1454 if (Length(gPlayers
) > 0) then
1457 if (plr
<> nil) then
1459 plr
.getMapBox(x
, y
, w
, h
);
1460 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1462 dumpPublishedProperties(plr
);
1466 //e_WriteLog('===========================', MSG_NOTIFY);
1467 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1468 //e_WriteLog('---------------------------', MSG_NOTIFY);
1471 procedure cbAtcurDumpMonsters ();
1472 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1474 result
:= false; // don't stop
1475 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1478 e_WriteLog('===========================', MSG_NOTIFY
);
1479 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1480 e_WriteLog('---------------------------', MSG_NOTIFY
);
1483 procedure cbAtcurDumpWalls ();
1484 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1486 result
:= false; // don't stop
1487 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1488 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
]);
1489 dumpPublishedProperties(pan
);
1492 hasTrigs
: Boolean = false;
1496 platMarkedGUID
:= -1;
1497 e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY
);
1498 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1499 e_WriteLog('--- toggle wall ---', MSG_NOTIFY
);
1500 if showTriggers
then
1502 for f
:= 0 to High(gTriggers
) do
1504 trig
:= @gTriggers
[f
];
1505 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1507 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1508 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1511 if hasTrigs
then writeln('--- triggers ---');
1515 procedure cbAtcurToggleWalls ();
1516 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1518 result
:= false; // don't stop
1519 //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);
1520 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1523 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1524 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1525 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1529 // ////////////////////////////////////////////////////////////////////////// //
1530 procedure holmesInitCommands ();
1532 if (cmdlist
<> nil) then exit
;
1533 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1534 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1535 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1536 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1538 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1539 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1540 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1541 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1542 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'wake up selected monster', 'monster control');
1544 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1546 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1547 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1549 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1551 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1552 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1553 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1555 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1556 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1557 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1558 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1560 cmdAdd('dbg_tracebox', dbgToggleTraceBox
, 'test traceBox()', 'player control');
1564 procedure holmesInitBinds ();
1567 pr
: TTextParser
= nil;
1568 s
, kn
, v
: AnsiString;
1573 if not keybindsInited
then
1576 keybindAdd('F1', 'win_help');
1577 keybindAdd('M-F1', 'win_options');
1578 keybindAdd('C-O', 'win_outline');
1579 keybindAdd('C-L', 'win_layers');
1581 keybindAdd('M-M', 'mon_think_step');
1582 keybindAdd('M-I', 'mon_info');
1583 keybindAdd('M-L', 'mon_los_plr');
1584 keybindAdd('M-G', 'mon_cells');
1585 keybindAdd('M-A', 'mon_wakeup');
1587 keybindAdd('M-P', 'mplat_step');
1588 keybindAdd('M-O', 'mplat_toggle');
1590 keybindAdd('C-T', 'plr_teleport');
1591 keybindAdd('M-T', 'dbg_tracebox');
1593 keybindAdd('C-P', 'dbg_curpos');
1594 keybindAdd('C-G', 'dbg_grid');
1595 keybindAdd('C-X', 'dbg_triggers');
1597 keybindAdd('C-1', 'mon_spawn zombie');
1600 msbindAdd('LMB', 'atcur_select_monster');
1601 msbindAdd('M-LMB', 'atcur_dump_monsters');
1602 msbindAdd('RMB', 'atcur_dump_walls');
1603 msbindAdd('M-RMB', 'atcur_disable_walls');
1605 // load bindings from file
1607 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1608 pr
:= TFileTextParser
.Create(st
);
1609 conwriteln('parsing "holmes.rc"...');
1610 while (pr
.tokType
<> pr
.TTEOF
) do
1613 if (s
= 'stop') then break
1614 else if (s
= 'unbind_keys') then keybinds
:= nil
1615 else if (s
= 'unbind_mouse') then msbinds
:= nil
1616 else if (s
= 'bind') then
1618 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1619 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1620 else s
:= pr
.expectId();
1622 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1623 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1624 else v
:= pr
.expectId();
1626 kn
:= parseModKeys(s
, kmods
, mbuts
);
1627 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1637 except on e
: Exception
do // sorry
1638 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1640 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1646 conRegVar('hlm_ui_scale', @g_holmes_ui_scale
, 0.01, 5.0, 'Holmes UI scale', '', false);