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}
23 g_textures
, g_basic
, e_graphics
, g_phys
, g_grid
, g_player
, g_monsters
,
24 g_window
, g_map
, g_triggers
, g_items
, g_game
, g_panel
, g_console
,
32 // both for but and for bstate
45 kind
: Byte; // motion, press, release
47 dx
, dy
: Integer; // for wheel this is wheel motion, otherwise this is relative mouse motion
48 but
: Word; // current pressed/released button, or 0 for motion
49 bstate
: Word; // button state
50 kstate
: Word; // keyboard state (see THKeyEvent);
67 scan
: Word; // SDL_SCANCODE_XXX
68 sym
: Word; // SDLK_XXX
69 bstate
: Word; // button state
70 kstate
: Word; // keyboard state
75 procedure g_Holmes_VidModeChanged ();
76 procedure g_Holmes_WindowFocused ();
77 procedure g_Holmes_WindowBlured ();
79 procedure g_Holmes_Draw ();
80 procedure g_Holmes_DrawUI ();
82 function g_Holmes_MouseEvent (var ev
: THMouseEvent
): Boolean; // returns `true` if event was eaten
83 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean; // returns `true` if event was eaten
86 procedure g_Holmes_plrView (viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer);
87 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
90 operator
= (constref ev
: THKeyEvent
; const s
: AnsiString): Boolean;
91 operator
= (const s
: AnsiString; constref ev
: THKeyEvent
): Boolean;
93 operator
= (constref ev
: THMouseEvent
; const s
: AnsiString): Boolean;
94 operator
= (const s
: AnsiString; constref ev
: THMouseEvent
): Boolean;
98 g_holmes_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
99 g_holmes_ui_scale
: Single = 1.0;
106 SysUtils
, Classes
, GL
, SDL2
,
107 MAPDEF
, g_main
, g_options
,
108 utils
, hashtable
, xparser
;
112 //globalInited: Boolean = false;
115 msB
: Word = 0; // button state
116 kbS
: Word = 0; // keyboard modifiers state
117 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
118 showMonsInfo
: Boolean = false;
119 showMonsLOS2Plr
: Boolean = false;
120 showAllMonsCells
: Boolean = false;
121 showMapCurPos
: Boolean = false;
122 showLayersWindow
: Boolean = false;
123 showOutlineWindow
: Boolean = false;
124 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
127 // ////////////////////////////////////////////////////////////////////////// //
128 {$INCLUDE g_holmes.inc}
129 {$INCLUDE g_holmes_ui.inc}
132 // ////////////////////////////////////////////////////////////////////////// //
133 // any mods = 255: nothing was defined
134 function parseModKeys (const s
: AnsiString; out kmods
: Byte; out mbuts
: Byte): AnsiString;
141 //while (pos <= Length(s)) and (s[pos] <= ' ') do Inc(pos);
142 if (pos
< Length(s
)) and ((s
[pos
] = '+') or (s
[pos
] = '-') or (s
[pos
] = '*')) then Inc(pos
);
143 while (pos
< Length(s
)) do
145 if (Length(s
)-pos
>= 2) and (s
[pos
+1] = '-') then
148 'C', 'c': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModCtrl
; Inc(pos
, 2); continue
; end;
149 'M', 'm': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModAlt
; Inc(pos
, 2); continue
; end;
150 'S', 's': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModShift
; Inc(pos
, 2); continue
; end;
154 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
157 'L', 'l': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Left
; Inc(pos
, 4); continue
; end;
158 'R', 'r': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Right
; Inc(pos
, 4); continue
; end;
159 'M', 'm': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Middle
; Inc(pos
, 4); continue
; end;
166 while (epos
> pos
) and (s
[epos
-1] <= ' ') do Dec(epos
);
167 if (epos
> pos
) then result
:= Copy(s
, pos
, epos
-pos
) else result
:= '';
171 operator
= (constref ev
: THKeyEvent
; const s
: AnsiString): Boolean;
179 if (Length(s
) > 0) then
181 if (s
[1] = '+') then begin if (ev
.kind
<> ev
.Press
) then exit
; end
182 else if (s
[1] = '-') then begin if (ev
.kind
<> ev
.Release
) then exit
; end
183 else if (s
[1] = '*') then begin end
184 else if (ev
.kind
<> ev
.Press
) then exit
;
186 kname
:= parseModKeys(s
, kmods
, mbuts
);
187 if (kmods
= 255) then kmods
:= 0;
188 if (ev
.kstate
<> kmods
) then exit
;
189 if (mbuts
<> 255) and (ev
.bstate
<> mbuts
) then exit
;
190 for f
:= 1 to High(e_KeyNames
) do
192 if (CompareText(kname
, e_KeyNames
[f
]) = 0) then
194 result
:= (ev
.scan
= f
);
201 operator
= (const s
: AnsiString; constref ev
: THKeyEvent
): Boolean;
207 operator
= (constref ev
: THMouseEvent
; const s
: AnsiString): Boolean;
216 if (Length(s
) > 0) then
218 if (s
[1] = '+') then begin if (ev
.kind
<> ev
.Press
) then exit
; end
219 else if (s
[1] = '-') then begin if (ev
.kind
<> ev
.Release
) then exit
; end
220 else if (s
[1] = '*') then begin if (ev
.kind
<> ev
.Motion
) then exit
; end
221 else if (ev
.kind
<> ev
.Press
) then exit
;
224 kname
:= parseModKeys(s
, kmods
, mbuts
);
225 if (CompareText(kname
, 'LMB') = 0) then but
:= THMouseEvent
.Left
226 else if (CompareText(kname
, 'RMB') = 0) then but
:= THMouseEvent
.Right
227 else if (CompareText(kname
, 'MMB') = 0) then but
:= THMouseEvent
.Middle
228 else if (CompareText(kname
, 'None') = 0) then but
:= 0
231 //conwritefln('s=[%s]; kname=[%s]; kmods=%s; mbuts=%s; but=%s', [s, kname, kmods, mbuts, but]);
233 if (mbuts
= 255) then mbuts
:= 0;
234 if (kmods
= 255) then kmods
:= 0;
235 if (ev
.kstate
<> kmods
) then exit
;
237 if (ev
.kind
= ev
.Press
) then mbuts
:= mbuts
or but
238 else if (ev
.kind
= ev
.Release
) then mbuts
:= mbuts
and (not but
);
240 //conwritefln(' ev.bstate=%s; ev.but=%s; mbuts=%s', [ev.bstate, ev.but, mbuts]);
242 result
:= (ev
.bstate
= mbuts
) and (ev
.but
= but
);
246 operator
= (const s
: AnsiString; constref ev
: THMouseEvent
): Boolean;
252 // ////////////////////////////////////////////////////////////////////////// //
253 function typeKind2Str (t
: TTypeKind
): AnsiString;
256 tkUnknown
: result
:= 'Unknown';
257 tkInteger
: result
:= 'Integer';
258 tkChar
: result
:= 'Char';
259 tkEnumeration
: result
:= 'Enumeration';
260 tkFloat
: result
:= 'Float';
261 tkSet
: result
:= 'Set';
262 tkMethod
: result
:= 'Method';
263 tkSString
: result
:= 'SString';
264 tkLString
: result
:= 'LString';
265 tkAString
: result
:= 'AString';
266 tkWString
: result
:= 'WString';
267 tkVariant
: result
:= 'Variant';
268 tkArray
: result
:= 'Array';
269 tkRecord
: result
:= 'Record';
270 tkInterface
: result
:= 'Interface';
271 tkClass
: result
:= 'Class';
272 tkObject
: result
:= 'Object';
273 tkWChar
: result
:= 'WChar';
274 tkBool
: result
:= 'Bool';
275 tkInt64
: result
:= 'Int64';
276 tkQWord
: result
:= 'QWord';
277 tkDynArray
: result
:= 'DynArray';
278 tkInterfaceRaw
: result
:= 'InterfaceRaw';
279 tkProcVar
: result
:= 'ProcVar';
280 tkUString
: result
:= 'UString';
281 tkUChar
: result
:= 'UChar';
282 tkHelper
: result
:= 'Helper';
283 tkFile
: result
:= 'File';
284 tkClassRef
: result
:= 'ClassRef';
285 tkPointer
: result
:= 'Pointer';
286 else result
:= '<unknown>';
291 procedure dumpPublishedProperties (obj
: TObject
);
298 if (obj
= nil) then exit
;
299 e_LogWritefln('Object of type ''%s'':', [obj
.ClassName
]);
301 pt
:= GetTypeData(pi
);
302 e_LogWritefln('property count: %s', [pt
.PropCount
]);
303 GetMem(pp
, pt
^.PropCount
*sizeof(Pointer));
305 j
:= GetPropList(pi
, [tkInteger
, tkBool
, tkSString
, tkLString
, tkAString
, tkSet
, tkEnumeration
], pp
);
306 //e_LogWritefln('ordinal property count: %s', [j]);
309 if (typinfo
.PropType(obj
, pp
^[i
].name
) in [tkSString
, tkLString
, tkAString
]) then
311 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetStrProp(obj
, pp
^[i
])]);
313 else if (typinfo
.PropType(obj
, pp
^[i
].name
) = tkSet
) then
315 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)]);
317 else if (typinfo
.PropType(obj
, pp
^[i
].name
) = tkEnumeration
) then
319 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetEnumProp(obj
, pp
^[i
])]);
323 e_LogWritefln(' #%s: <%s>; type: %s; value: %s', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetOrdProp(obj
, pp
^[i
])]);
332 //FIXME: autogenerate
333 function trigType2Str (ttype
: Integer): AnsiString;
335 result
:= '<unknown>';
337 TRIGGER_NONE
: result
:= 'none';
338 TRIGGER_EXIT
: result
:= 'exit';
339 TRIGGER_TELEPORT
: result
:= 'teleport';
340 TRIGGER_OPENDOOR
: result
:= 'opendoor';
341 TRIGGER_CLOSEDOOR
: result
:= 'closedoor';
342 TRIGGER_DOOR
: result
:= 'door';
343 TRIGGER_DOOR5
: result
:= 'door5';
344 TRIGGER_CLOSETRAP
: result
:= 'closetrap';
345 TRIGGER_TRAP
: result
:= 'trap';
346 TRIGGER_PRESS
: result
:= 'press';
347 TRIGGER_SECRET
: result
:= 'secret';
348 TRIGGER_LIFTUP
: result
:= 'liftup';
349 TRIGGER_LIFTDOWN
: result
:= 'liftdown';
350 TRIGGER_LIFT
: result
:= 'lift';
351 TRIGGER_TEXTURE
: result
:= 'texture';
352 TRIGGER_ON
: result
:= 'on';
353 TRIGGER_OFF
: result
:= 'off';
354 TRIGGER_ONOFF
: result
:= 'onoff';
355 TRIGGER_SOUND
: result
:= 'sound';
356 TRIGGER_SPAWNMONSTER
: result
:= 'spawnmonster';
357 TRIGGER_SPAWNITEM
: result
:= 'spawnitem';
358 TRIGGER_MUSIC
: result
:= 'music';
359 TRIGGER_PUSH
: result
:= 'push';
360 TRIGGER_SCORE
: result
:= 'score';
361 TRIGGER_MESSAGE
: result
:= 'message';
362 TRIGGER_DAMAGE
: result
:= 'damage';
363 TRIGGER_HEALTH
: result
:= 'health';
364 TRIGGER_SHOT
: result
:= 'shot';
365 TRIGGER_EFFECT
: result
:= 'effect';
366 TRIGGER_SCRIPT
: result
:= 'script';
370 // ////////////////////////////////////////////////////////////////////////// //
371 {$INCLUDE g_holmes_cmd.inc}
372 procedure holmesInitCommands (); forward;
373 procedure holmesInitBinds (); forward;
376 // ////////////////////////////////////////////////////////////////////////// //
378 g_ol_nice
: Boolean = false;
379 g_ol_fill_walls
: Boolean = false;
380 g_ol_rlayer_back
: Boolean = false;
381 g_ol_rlayer_step
: Boolean = false;
382 g_ol_rlayer_wall
: Boolean = false;
383 g_ol_rlayer_door
: Boolean = false;
384 g_ol_rlayer_acid1
: Boolean = false;
385 g_ol_rlayer_acid2
: Boolean = false;
386 g_ol_rlayer_water
: Boolean = false;
387 g_ol_rlayer_fore
: Boolean = false;
390 // ////////////////////////////////////////////////////////////////////////// //
392 winHelp
: THTopWindow
= nil;
393 winOptions
: THTopWindow
= nil;
394 winLayers
: THTopWindow
= nil;
395 winOutlines
: THTopWindow
= nil;
398 procedure createHelpWindow (); forward;
399 procedure createOptionsWindow (); forward;
400 procedure createLayersWindow (); forward;
401 procedure createOutlinesWindow (); forward;
404 procedure toggleLayersWindowCB (me
: THControl
; checked
: Integer);
406 if showLayersWindow
then
408 if (winLayers
= nil) then createLayersWindow();
409 uiAddWindow(winLayers
);
413 uiRemoveWindow(winLayers
);
418 procedure toggleOutlineWindowCB (me
: THControl
; checked
: Integer);
420 if showOutlineWindow
then
422 if (winOutlines
= nil) then createOutlinesWindow();
423 uiAddWindow(winOutlines
);
427 uiRemoveWindow(winOutlines
);
432 procedure createHelpWindow ();
434 llb
: THCtlSimpleText
;
435 slist
: array of AnsiString = nil;
437 bind
: THolmesBinding
;
438 f
, maxkeylen
: Integer;
441 for cmd
in cmdlist
do cmd
.helpmark
:= false;
444 for bind
in keybinds
do
446 if (Length(bind
.key
) = 0) then continue
;
447 if cmdlist
.get(bind
.cmdName
, cmd
) then
449 if (Length(cmd
.help
) > 0) then
451 cmd
.helpmark
:= true;
452 if (maxkeylen
< Length(bind
.key
)) then maxkeylen
:= Length(bind
.key
);
457 for cmd
in cmdlist
do
459 if not cmd
.helpmark
then continue
;
460 if (Length(cmd
.help
) = 0) then continue
;
462 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
463 if (f
= Length(slist
)) then
465 SetLength(slist
, Length(slist
)+1);
466 slist
[High(slist
)] := cmd
.section
;
470 llb
:= THCtlSimpleText
.Create(0, 0);
471 for f
:= 0 to High(slist
) do
473 if (f
> 0) then llb
.appendItem('');
474 llb
.appendItem(slist
[f
], true, true);
475 for cmd
in cmdlist
do
477 if not cmd
.helpmark
then continue
;
478 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
479 for bind
in keybinds
do
481 if (Length(bind
.key
) = 0) then continue
;
482 if (cmd
.name
= bind
.cmdName
) then
485 while (Length(s
) < maxkeylen
) do s
+= ' ';
486 s
:= ' '+s
+' -- '+cmd
.help
;
494 for bind
in msbinds
do
496 if (Length(bind
.key
) = 0) then continue
;
497 if cmdlist
.get(bind
.cmdName
, cmd
) then
499 if (Length(cmd
.help
) > 0) then
501 cmd
.helpmark
:= true;
502 if (maxkeylen
< Length(bind
.key
)) then maxkeylen
:= Length(bind
.key
);
508 llb
.appendItem('mouse', true, true);
509 for bind
in msbinds
do
511 if (Length(bind
.key
) = 0) then continue
;
512 if cmdlist
.get(bind
.cmdName
, cmd
) then
514 if (Length(cmd
.help
) > 0) then
517 while (Length(s
) < maxkeylen
) do s
+= ' ';
518 s
:= ' '+s
+' -- '+cmd
.help
;
524 winHelp
:= THTopWindow
.Create('Holmes Help', 10, 10);
525 winHelp
.escClose
:= true;
526 winHelp
.appendChild(llb
);
527 winHelp
.centerInScreen();
531 procedure winLayersClosed (me
: THControl
; dummy
: Integer); begin showLayersWindow
:= false; end;
532 procedure winOutlinesClosed (me
: THControl
; dummy
: Integer); begin showOutlineWindow
:= false; end;
534 procedure createLayersWindow ();
538 llb
:= THCtlCBListBox
.Create(0, 0);
539 llb
.appendItem('background', @g_rlayer_back
);
540 llb
.appendItem('steps', @g_rlayer_step
);
541 llb
.appendItem('walls', @g_rlayer_wall
);
542 llb
.appendItem('doors', @g_rlayer_door
);
543 llb
.appendItem('acid1', @g_rlayer_acid1
);
544 llb
.appendItem('acid2', @g_rlayer_acid2
);
545 llb
.appendItem('water', @g_rlayer_water
);
546 llb
.appendItem('foreground', @g_rlayer_fore
);
547 winLayers
:= THTopWindow
.Create('layers', 10, 10);
548 winLayers
.escClose
:= true;
549 winLayers
.appendChild(llb
);
550 winLayers
.closeCB
:= winLayersClosed
;
554 procedure createOutlinesWindow ();
558 llb
:= THCtlCBListBox
.Create(0, 0);
559 llb
.appendItem('background', @g_ol_rlayer_back
);
560 llb
.appendItem('steps', @g_ol_rlayer_step
);
561 llb
.appendItem('walls', @g_ol_rlayer_wall
);
562 llb
.appendItem('doors', @g_ol_rlayer_door
);
563 llb
.appendItem('acid1', @g_ol_rlayer_acid1
);
564 llb
.appendItem('acid2', @g_ol_rlayer_acid2
);
565 llb
.appendItem('water', @g_ol_rlayer_water
);
566 llb
.appendItem('foreground', @g_ol_rlayer_fore
);
567 llb
.appendItem('OPTIONS', nil);
568 llb
.appendItem('fill walls', @g_ol_fill_walls
);
569 llb
.appendItem('contours', @g_ol_nice
);
570 winOutlines
:= THTopWindow
.Create('outlines', 100, 10);
571 winOutlines
.escClose
:= true;
572 winOutlines
.appendChild(llb
);
573 winOutlines
.closeCB
:= winOutlinesClosed
;
577 procedure createOptionsWindow ();
581 llb
:= THCtlCBListBox
.Create(0, 0);
582 llb
.appendItem('map grid', @showGrid
);
583 llb
.appendItem('cursor position on map', @showMapCurPos
);
584 llb
.appendItem('monster info', @showMonsInfo
);
585 llb
.appendItem('monster LOS to player', @showMonsLOS2Plr
);
586 llb
.appendItem('monster cells (SLOW!)', @showAllMonsCells
);
587 llb
.appendItem('draw triggers (SLOW!)', @showTriggers
);
588 llb
.appendItem('WINDOWS', nil);
589 llb
.appendItem('layers window', @showLayersWindow
, toggleLayersWindowCB
);
590 llb
.appendItem('outline window', @showOutlineWindow
, toggleOutlineWindowCB
);
591 winOptions
:= THTopWindow
.Create('Holmes Options', 100, 100);
592 winOptions
.escClose
:= true;
593 winOptions
.appendChild(llb
);
594 winOptions
.centerInScreen();
598 procedure toggleLayersWindow (arg
: Integer=-1);
600 showLayersWindow
:= not showLayersWindow
;
601 toggleLayersWindowCB(nil, 0);
604 procedure toggleOutlineWindow (arg
: Integer=-1);
606 showOutlineWindow
:= not showOutlineWindow
;
607 toggleOutlineWindowCB(nil, 0);
610 procedure toggleHelpWindow (arg
: Integer=-1);
612 if (winHelp
= nil) then createHelpWindow();
613 if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
);
616 procedure toggleOptionsWindow (arg
: Integer=-1);
618 if (winOptions
= nil) then createOptionsWindow();
619 if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
);
623 // ////////////////////////////////////////////////////////////////////////// //
624 procedure g_Holmes_VidModeChanged ();
626 e_WriteLog(Format('Holmes: videomode changed: %dx%d', [gScreenWidth
, gScreenHeight
]), MSG_NOTIFY
);
627 // texture space is possibly lost here, idc
633 //createCursorTexture();
636 procedure g_Holmes_WindowFocused ();
642 procedure g_Holmes_WindowBlured ();
647 // ////////////////////////////////////////////////////////////////////////// //
649 vpSet
: Boolean = false;
652 laserSet
: Boolean = false;
653 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
654 monMarkedUID
: Integer = -1;
655 platMarkedGUID
: Integer = -1;
658 procedure g_Holmes_plrView (viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer);
667 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
674 laserSet
:= laserSet
; // shut up, fpc!
678 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
679 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
682 procedure plrDebugMouse (var ev
: THMouseEvent
);
684 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
685 if (gPlayer1
= nil) or not vpSet
then exit
;
686 //if (ev.kind <> THMouseEvent.Press) then exit;
687 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
693 edgeBmp
: array of Byte = nil;
696 procedure drawOutlines ();
700 procedure clearEdgeBmp ();
702 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
703 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
706 procedure drawPanel (pan
: TPanel
);
708 sx
, len
, y0
, y1
: Integer;
710 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
711 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
712 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
713 if g_ol_nice
or g_ol_fill_walls
then
717 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
718 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
719 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
720 if (len
< 1) then exit
;
722 assert(sx
+len
<= gWinSizeX
+4);
725 if (y0
< 0) then y0
:= 0;
726 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
729 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
735 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
744 procedure flushLine ();
746 if (lsy
> 0) and (lsx
> 0) then
751 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
757 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
758 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
766 procedure startLine (y
: Integer);
772 procedure putPixel (x
: Integer);
774 if (x
< 1) then exit
;
775 if (lex
+1 <> x
) then flushLine();
776 if (lsx
< 0) then lsx
:= x
;
780 procedure drawEdges ();
786 glDisable(GL_TEXTURE_2D
);
789 glDisable(GL_LINE_SMOOTH
);
790 glDisable(GL_POLYGON_SMOOTH
);
791 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
794 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
800 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
801 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
802 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
813 procedure drawFilledWalls ();
819 glDisable(GL_TEXTURE_2D
);
822 glDisable(GL_LINE_SMOOTH
);
823 glDisable(GL_POLYGON_SMOOTH
);
824 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
827 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
831 if (a
[0] <> 0) then putPixel(x
);
838 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
846 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
847 for f
:= 0 to High(parr
) do
850 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
851 if ((pan
.PanelType
and ptype
) = 0) then continue
;
854 if g_ol_nice
then drawEdges();
855 if g_ol_fill_walls
then drawFilledWalls();
861 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
863 result
:= false; // don't stop
864 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
865 if ((pan
.PanelType
and xptag
) = 0) then exit
;
869 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
875 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
876 else panelTypeToTag(ptype
);
877 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
878 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
879 if g_ol_nice
then drawEdges();
880 if g_ol_fill_walls
then drawFilledWalls();
884 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
885 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
886 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
887 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
888 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
889 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
890 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
891 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
895 procedure plrDebugDraw ();
896 procedure drawTileGrid ();
900 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
902 drawLine(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, 96, 96, 96, 255);
905 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
907 drawLine(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
, 96, 96, 96, 255);
911 procedure hilightCell (cx
, cy
: Integer);
913 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 0, 128, 0, 64);
916 procedure hilightCell1 (cx
, cy
: Integer);
918 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
919 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 255, 255, 0, 92);
922 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
924 result
:= false; // don't stop
925 if (pan
= nil) then exit
; // cell completion, ignore
926 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
927 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, 0, 128, 128, 64);
930 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
933 mx
, my
, mw
, mh
: Integer;
936 mon
.getMapBox(mx
, my
, mw
, mh
);
937 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
938 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
940 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
944 procedure drawMonsterInfo (mon
: TMonster
);
946 mx
, my
, mw
, mh
: Integer;
948 procedure drawMonsterTargetLine ();
950 emx
, emy
, emw
, emh
: Integer;
955 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
957 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
958 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
960 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
962 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
963 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
969 mon
.getMapBox(mx
, my
, mw
, mh
);
970 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
971 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
973 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
977 procedure drawLOS2Plr ();
979 emx
, emy
, emw
, emh
: Integer;
984 if (eplr
= nil) then exit
;
985 eplr
.getMapBox(emx
, emy
, emw
, emh
);
986 mon
.getMapBox(mx
, my
, mw
, mh
);
987 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
988 {$IF DEFINED(D2F_DEBUG)}
989 //mapGrid.dbgRayTraceTileHitCB := hilightCell1;
991 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
992 //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
994 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
996 {$IF DEFINED(D2F_DEBUG)}
997 //mapGrid.dbgRayTraceTileHitCB := nil;
1002 if (mon
= nil) then exit
;
1003 mon
.getMapBox(mx
, my
, mw
, mh
);
1006 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1008 if showMonsInfo
then
1010 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1011 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
1016 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), 255, 127, 0); my
-= 8;
1018 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), 255, 127, 0); my
-= 8;
1020 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), 255, 127, 0); my
-= 8;
1022 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), 255, 127, 0); my
-= 8;
1024 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), 255, 127, 0); my
-= 8;
1026 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), 255, 127, 0); my
-= 8;
1027 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), 255, 127, 0); my
-= 8;
1030 drawMonsterTargetLine();
1031 if showMonsLOS2Plr
then drawLOS2Plr();
1033 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1034 property MonsterPain: Integer read FPain write FPain;
1035 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1039 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1041 result
:= false; // don't stop
1042 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1045 procedure drawSelectedPlatformCells ();
1049 if not showGrid
then exit
;
1050 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1051 if (pan
= nil) then exit
;
1052 mapGrid
.forEachBodyCell(pan
.proxyId
, hilightCell
);
1053 drawRect(pan
.x
, pan
.y
, pan
.width
, pan
.height
, 0, 200, 0, 200);
1056 procedure drawTrigger (var trig
: TTrigger
);
1058 procedure drawPanelDest (pguid
: Integer);
1062 pan
:= g_Map_PanelByGUID(pguid
);
1063 if (pan
= nil) then exit
;
1065 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1066 pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2,
1074 fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
, 255, 0, 255, 96);
1075 tts
:= trigType2Str(trig
.TriggerType
);
1076 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1077 darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1078 drawText6(tx
, trig
.y
-9, tts
, 255, 127, 0);
1079 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1080 darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1081 drawText6(tx
, trig
.y
-19, trig
.mapId
, 255, 255, 0);
1082 drawPanelDest(trig
.trigPanelGUID
);
1083 case trig
.TriggerType
of
1084 TRIGGER_NONE
: begin end;
1085 TRIGGER_EXIT
: begin end;
1086 TRIGGER_TELEPORT
: begin end;
1087 TRIGGER_OPENDOOR
: begin end;
1088 TRIGGER_CLOSEDOOR
: begin end;
1089 TRIGGER_DOOR
: begin end;
1090 TRIGGER_DOOR5
: begin end;
1091 TRIGGER_CLOSETRAP
: begin end;
1092 TRIGGER_TRAP
: begin end;
1093 TRIGGER_SECRET
: begin end;
1094 TRIGGER_LIFTUP
: begin end;
1095 TRIGGER_LIFTDOWN
: begin end;
1096 TRIGGER_LIFT
: begin end;
1097 TRIGGER_TEXTURE
: begin end;
1098 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1100 if (trig
.trigData
.trigTWidth
> 0) and (trig
.trigData
.trigTHeight
> 0) then
1103 trig
.trigData
.trigTX
, trig
.trigData
.trigTY
,
1104 trig
.trigData
.trigTWidth
, trig
.trigData
.trigTHeight
,
1107 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1108 trig
.trigData
.trigTX
+trig
.trigData
.trigTWidth
div 2,
1109 trig
.trigData
.trigTY
+trig
.trigData
.trigTHeight
div 2,
1113 TRIGGER_SOUND
: begin end;
1114 TRIGGER_SPAWNMONSTER
: begin end;
1115 TRIGGER_SPAWNITEM
: begin end;
1116 TRIGGER_MUSIC
: begin end;
1117 TRIGGER_PUSH
: begin end;
1118 TRIGGER_SCORE
: begin end;
1119 TRIGGER_MESSAGE
: begin end;
1120 TRIGGER_DAMAGE
: begin end;
1121 TRIGGER_HEALTH
: begin end;
1122 TRIGGER_SHOT
: begin end;
1123 TRIGGER_EFFECT
: begin end;
1124 TRIGGER_SCRIPT
: begin end;
1127 //trigPanelId: Integer;
1130 procedure drawTriggers ();
1134 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1139 mx
, my
, mw
, mh
: Integer;
1141 if (gPlayer1
= nil) then exit
;
1143 glEnable(GL_SCISSOR_TEST
);
1144 glScissor(0, gWinSizeY
-gPlayerScreenSize
.Y
-1, vpw
, vph
);
1147 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
1148 glTranslatef(-vpx
, -vpy
, 0);
1150 if (showGrid
) then drawTileGrid();
1153 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
1155 if (monMarkedUID
<> -1) then
1157 mon
:= g_Monsters_ByUID(monMarkedUID
);
1158 if (mon
<> nil) then
1160 mon
.getMapBox(mx
, my
, mw
, mh
);
1161 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
1162 drawMonsterInfo(mon
);
1166 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1167 if showTriggers
then drawTriggers();
1168 if showGrid
then drawSelectedPlatformCells();
1172 glDisable(GL_SCISSOR_TEST
);
1174 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), 255, 255, 0);
1178 // ////////////////////////////////////////////////////////////////////////// //
1179 function g_Holmes_MouseEvent (var ev
: THMouseEvent
): Boolean;
1183 holmesInitCommands();
1186 msX
:= trunc(ev
.x
/g_holmes_ui_scale
);
1187 msY
:= trunc(ev
.y
/g_holmes_ui_scale
);
1192 he
.x
:= trunc(he
.x
/g_holmes_ui_scale
);
1193 he
.y
:= trunc(he
.y
/g_holmes_ui_scale
);
1194 if not uiMouseEvent(he
) then plrDebugMouse(he
);
1198 // ////////////////////////////////////////////////////////////////////////// //
1199 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean;
1200 {$IF DEFINED(D2F_DEBUG)}
1207 procedure dummyWallTrc (cx
, cy
: Integer);
1212 holmesInitCommands();
1218 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1219 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1220 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1223 if uiKeyEvent(ev
) then begin result
:= true; exit
; end;
1224 if keybindExecute(ev
) then begin result
:= true; exit
; end;
1226 if (ev
.kind
= THKeyEvent
.Press
) then
1228 {$IF DEFINED(D2F_DEBUG)}
1229 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1230 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
1231 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
1237 SDL_SCANCODE_UP
: dy
-= 120;
1238 SDL_SCANCODE_DOWN
: dy
+= 120;
1239 SDL_SCANCODE_LEFT
: dx
-= 120;
1240 SDL_SCANCODE_RIGHT
: dx
+= 120;
1242 {$IF DEFINED(D2F_DEBUG)}
1243 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1244 mapGrid
.dbgShowTraceLog
:= true;
1246 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1247 {$IF DEFINED(D2F_DEBUG)}
1248 //mapGrid.dbgRayTraceTileHitCB := nil;
1249 mapGrid
.dbgShowTraceLog
:= false;
1251 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1259 // ////////////////////////////////////////////////////////////////////////// //
1260 procedure g_Holmes_Draw ();
1262 {$IF not DEFINED(HEADLESS)}
1263 holmesInitCommands();
1266 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1267 glDisable(GL_STENCIL_TEST
);
1268 glDisable(GL_BLEND
);
1269 glDisable(GL_SCISSOR_TEST
);
1270 glDisable(GL_TEXTURE_2D
);
1282 procedure g_Holmes_DrawUI ();
1284 {$IF not DEFINED(HEADLESS)}
1286 glScalef(g_holmes_ui_scale
, g_holmes_ui_scale
, 1.0);
1294 // ////////////////////////////////////////////////////////////////////////// //
1295 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1296 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1297 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1299 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1300 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1301 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1302 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1304 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1305 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1307 procedure bcMonsterWakeup ();
1311 if (monMarkedUID
<> -1) then
1313 mon
:= g_Monsters_ByUID(monMarkedUID
);
1314 if (mon
<> nil) then mon
.WakeUp();
1318 procedure bcPlayerTeleport ();
1320 x
, y
, w
, h
: Integer;
1322 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1323 if (gPlayers
[0] <> nil) then
1325 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1326 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1330 procedure cbAtcurSelectMonster ();
1331 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1333 result
:= true; // stop
1334 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1335 monMarkedUID
:= mon
.UID
;
1336 dumpPublishedProperties(mon
);
1340 x
, y
, w
, h
: Integer;
1343 if (Length(gPlayers
) > 0) then
1346 if (plr
<> nil) then
1348 plr
.getMapBox(x
, y
, w
, h
);
1349 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1351 dumpPublishedProperties(plr
);
1355 //e_WriteLog('===========================', MSG_NOTIFY);
1356 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1357 //e_WriteLog('---------------------------', MSG_NOTIFY);
1360 procedure cbAtcurDumpMonsters ();
1361 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1363 result
:= false; // don't stop
1364 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1367 e_WriteLog('===========================', MSG_NOTIFY
);
1368 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1369 e_WriteLog('---------------------------', MSG_NOTIFY
);
1372 procedure cbAtcurDumpWalls ();
1373 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1375 result
:= false; // don't stop
1376 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1377 e_LogWritefln('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
]);
1378 dumpPublishedProperties(pan
);
1381 hasTrigs
: Boolean = false;
1385 platMarkedGUID
:= -1;
1386 e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY
);
1387 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1388 e_WriteLog('--- toggle wall ---', MSG_NOTIFY
);
1389 if showTriggers
then
1391 for f
:= 0 to High(gTriggers
) do
1393 trig
:= @gTriggers
[f
];
1394 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1396 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1397 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1400 if hasTrigs
then writeln('--- triggers ---');
1404 procedure cbAtcurToggleWalls ();
1405 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1407 result
:= false; // don't stop
1408 //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);
1409 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1412 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1413 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1414 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1418 // ////////////////////////////////////////////////////////////////////////// //
1419 procedure holmesInitCommands ();
1421 if (cmdlist
<> nil) then exit
;
1422 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1423 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1424 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1425 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1427 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1428 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1429 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1430 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1431 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1433 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1434 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1436 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1438 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1439 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1440 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1442 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1443 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1444 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1445 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1449 procedure holmesInitBinds ();
1452 pr
: TTextParser
= nil;
1453 s
, kn
, v
: AnsiString;
1458 if not keybindsInited
then
1461 keybindAdd('F1', 'win_help');
1462 keybindAdd('M-F1', 'win_options');
1463 keybindAdd('C-O', 'win_outline');
1464 keybindAdd('C-L', 'win_layers');
1466 keybindAdd('M-M', 'mon_think_step');
1467 keybindAdd('M-I', 'mon_info');
1468 keybindAdd('M-L', 'mon_los_plr');
1469 keybindAdd('M-G', 'mon_cells');
1470 keybindAdd('M-A', 'mon_wakeup');
1472 keybindAdd('M-P', 'mplat_step');
1473 keybindAdd('M-O', 'mplat_toggle');
1475 keybindAdd('C-T', 'plr_teleport');
1477 keybindAdd('C-P', 'dbg_curpos');
1478 keybindAdd('C-G', 'dbg_grid');
1479 keybindAdd('C-X', 'dbg_triggers');
1482 msbindAdd('LMB', 'atcur_select_monster');
1483 msbindAdd('M-LMB', 'atcur_dump_monsters');
1484 msbindAdd('RMB', 'atcur_dump_walls');
1485 msbindAdd('M-RMB', 'atcur_disable_walls');
1487 // load bindings from file
1489 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1490 pr
:= TFileTextParser
.Create(st
);
1491 conwriteln('parsing "holmes.rc"...');
1492 while (pr
.tokType
<> pr
.TTEOF
) do
1495 if (s
= 'stop') then break
1496 else if (s
= 'unbind_keys') then keybinds
:= nil
1497 else if (s
= 'unbind_mouse') then msbinds
:= nil
1498 else if (s
= 'bind') then
1500 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1501 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1502 else s
:= pr
.expectId();
1504 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1505 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1506 else v
:= pr
.expectId();
1508 kn
:= parseModKeys(s
, kmods
, mbuts
);
1509 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1519 except on e
: Exception
do // sorry
1520 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1522 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1528 conRegVar('hlm_ui_scale', @g_holmes_ui_scale
, 0.01, 5.0, 'Holmes UI scale', '', false);