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};
105 SysUtils
, Classes
, GL
, SDL2
,
106 MAPDEF
, g_main
, g_options
,
107 utils
, hashtable
, xparser
;
111 //globalInited: Boolean = false;
114 msB
: Word = 0; // button state
115 kbS
: Word = 0; // keyboard modifiers state
116 showGrid
: Boolean = false;
117 showMonsInfo
: Boolean = false;
118 showMonsLOS2Plr
: Boolean = false;
119 showAllMonsCells
: Boolean = false;
120 showMapCurPos
: Boolean = false;
121 showLayersWindow
: Boolean = false;
122 showOutlineWindow
: Boolean = false;
123 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
125 // ////////////////////////////////////////////////////////////////////////// //
126 {$INCLUDE g_holmes.inc}
127 {$INCLUDE g_holmes_ui.inc}
130 // ////////////////////////////////////////////////////////////////////////// //
131 // any mods = 255: nothing was defined
132 function parseModKeys (const s
: AnsiString; out kmods
: Byte; out mbuts
: Byte): AnsiString;
139 //while (pos <= Length(s)) and (s[pos] <= ' ') do Inc(pos);
140 if (pos
< Length(s
)) and ((s
[pos
] = '+') or (s
[pos
] = '-') or (s
[pos
] = '*')) then Inc(pos
);
141 while (pos
< Length(s
)) do
143 if (Length(s
)-pos
>= 2) and (s
[pos
+1] = '-') then
146 'C', 'c': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModCtrl
; Inc(pos
, 2); continue
; end;
147 'M', 'm': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModAlt
; Inc(pos
, 2); continue
; end;
148 'S', 's': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModShift
; Inc(pos
, 2); continue
; end;
152 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
155 'L', 'l': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Left
; Inc(pos
, 4); continue
; end;
156 'R', 'r': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Right
; Inc(pos
, 4); continue
; end;
157 'M', 'm': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Middle
; Inc(pos
, 4); continue
; end;
164 while (epos
> pos
) and (s
[epos
-1] <= ' ') do Dec(epos
);
165 if (epos
> pos
) then result
:= Copy(s
, pos
, epos
-pos
) else result
:= '';
169 operator
= (constref ev
: THKeyEvent
; const s
: AnsiString): Boolean;
177 if (Length(s
) > 0) then
179 if (s
[1] = '+') then begin if (ev
.kind
<> ev
.Press
) then exit
; end
180 else if (s
[1] = '-') then begin if (ev
.kind
<> ev
.Release
) then exit
; end
181 else if (s
[1] = '*') then begin end
182 else if (ev
.kind
<> ev
.Press
) then exit
;
184 kname
:= parseModKeys(s
, kmods
, mbuts
);
185 if (kmods
= 255) then kmods
:= 0;
186 if (ev
.kstate
<> kmods
) then exit
;
187 if (mbuts
<> 255) and (ev
.bstate
<> mbuts
) then exit
;
188 for f
:= 1 to High(e_KeyNames
) do
190 if (CompareText(kname
, e_KeyNames
[f
]) = 0) then
192 result
:= (ev
.scan
= f
);
199 operator
= (const s
: AnsiString; constref ev
: THKeyEvent
): Boolean;
205 operator
= (constref ev
: THMouseEvent
; const s
: AnsiString): Boolean;
214 if (Length(s
) > 0) then
216 if (s
[1] = '+') then begin if (ev
.kind
<> ev
.Press
) then exit
; end
217 else if (s
[1] = '-') then begin if (ev
.kind
<> ev
.Release
) then exit
; end
218 else if (s
[1] = '*') then begin if (ev
.kind
<> ev
.Motion
) then exit
; end
219 else if (ev
.kind
<> ev
.Press
) then exit
;
222 kname
:= parseModKeys(s
, kmods
, mbuts
);
223 if (CompareText(kname
, 'LMB') = 0) then but
:= THMouseEvent
.Left
224 else if (CompareText(kname
, 'RMB') = 0) then but
:= THMouseEvent
.Right
225 else if (CompareText(kname
, 'MMB') = 0) then but
:= THMouseEvent
.Middle
226 else if (CompareText(kname
, 'None') = 0) then but
:= 0
229 //conwritefln('s=[%s]; kname=[%s]; kmods=%s; mbuts=%s; but=%s', [s, kname, kmods, mbuts, but]);
231 if (mbuts
= 255) then mbuts
:= 0;
232 if (kmods
= 255) then kmods
:= 0;
233 if (ev
.kstate
<> kmods
) then exit
;
235 if (ev
.kind
= ev
.Press
) then mbuts
:= mbuts
or but
236 else if (ev
.kind
= ev
.Release
) then mbuts
:= mbuts
and (not but
);
238 //conwritefln(' ev.bstate=%s; ev.but=%s; mbuts=%s', [ev.bstate, ev.but, mbuts]);
240 result
:= (ev
.bstate
= mbuts
) and (ev
.but
= but
);
244 operator
= (const s
: AnsiString; constref ev
: THMouseEvent
): Boolean;
250 // ////////////////////////////////////////////////////////////////////////// //
251 function typeKind2Str (t
: TTypeKind
): AnsiString;
254 tkUnknown
: result
:= 'Unknown';
255 tkInteger
: result
:= 'Integer';
256 tkChar
: result
:= 'Char';
257 tkEnumeration
: result
:= 'Enumeration';
258 tkFloat
: result
:= 'Float';
259 tkSet
: result
:= 'Set';
260 tkMethod
: result
:= 'Method';
261 tkSString
: result
:= 'SString';
262 tkLString
: result
:= 'LString';
263 tkAString
: result
:= 'AString';
264 tkWString
: result
:= 'WString';
265 tkVariant
: result
:= 'Variant';
266 tkArray
: result
:= 'Array';
267 tkRecord
: result
:= 'Record';
268 tkInterface
: result
:= 'Interface';
269 tkClass
: result
:= 'Class';
270 tkObject
: result
:= 'Object';
271 tkWChar
: result
:= 'WChar';
272 tkBool
: result
:= 'Bool';
273 tkInt64
: result
:= 'Int64';
274 tkQWord
: result
:= 'QWord';
275 tkDynArray
: result
:= 'DynArray';
276 tkInterfaceRaw
: result
:= 'InterfaceRaw';
277 tkProcVar
: result
:= 'ProcVar';
278 tkUString
: result
:= 'UString';
279 tkUChar
: result
:= 'UChar';
280 tkHelper
: result
:= 'Helper';
281 tkFile
: result
:= 'File';
282 tkClassRef
: result
:= 'ClassRef';
283 tkPointer
: result
:= 'Pointer';
284 else result
:= '<unknown>';
289 procedure dumpPublishedProperties (obj
: TObject
);
296 if (obj
= nil) then exit
;
297 e_LogWritefln('Object of type ''%s'':', [obj
.ClassName
]);
299 pt
:= GetTypeData(pi
);
300 e_LogWritefln('property count: %s', [pt
.PropCount
]);
301 GetMem(pp
, pt
^.PropCount
*sizeof(Pointer));
303 j
:= GetPropList(pi
, [tkInteger
, tkBool
, tkSString
, tkLString
, tkAString
, tkSet
, tkEnumeration
], pp
);
304 //e_LogWritefln('ordinal property count: %s', [j]);
307 if (typinfo
.PropType(obj
, pp
^[i
].name
) in [tkSString
, tkLString
, tkAString
]) then
309 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetStrProp(obj
, pp
^[i
])]);
311 else if (typinfo
.PropType(obj
, pp
^[i
].name
) = tkSet
) then
313 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)]);
315 else if (typinfo
.PropType(obj
, pp
^[i
].name
) = tkEnumeration
) then
317 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetEnumProp(obj
, pp
^[i
])]);
321 e_LogWritefln(' #%s: <%s>; type: %s; value: %s', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetOrdProp(obj
, pp
^[i
])]);
330 //FIXME: autogenerate
331 function trigType2Str (ttype
: Integer): AnsiString;
333 result
:= '<unknown>';
335 TRIGGER_NONE
: result
:= 'none';
336 TRIGGER_EXIT
: result
:= 'exit';
337 TRIGGER_TELEPORT
: result
:= 'teleport';
338 TRIGGER_OPENDOOR
: result
:= 'opendoor';
339 TRIGGER_CLOSEDOOR
: result
:= 'closedoor';
340 TRIGGER_DOOR
: result
:= 'door';
341 TRIGGER_DOOR5
: result
:= 'door5';
342 TRIGGER_CLOSETRAP
: result
:= 'closetrap';
343 TRIGGER_TRAP
: result
:= 'trap';
344 TRIGGER_PRESS
: result
:= 'press';
345 TRIGGER_SECRET
: result
:= 'secret';
346 TRIGGER_LIFTUP
: result
:= 'liftup';
347 TRIGGER_LIFTDOWN
: result
:= 'liftdown';
348 TRIGGER_LIFT
: result
:= 'lift';
349 TRIGGER_TEXTURE
: result
:= 'texture';
350 TRIGGER_ON
: result
:= 'on';
351 TRIGGER_OFF
: result
:= 'off';
352 TRIGGER_ONOFF
: result
:= 'onoff';
353 TRIGGER_SOUND
: result
:= 'sound';
354 TRIGGER_SPAWNMONSTER
: result
:= 'spawnmonster';
355 TRIGGER_SPAWNITEM
: result
:= 'spawnitem';
356 TRIGGER_MUSIC
: result
:= 'music';
357 TRIGGER_PUSH
: result
:= 'push';
358 TRIGGER_SCORE
: result
:= 'score';
359 TRIGGER_MESSAGE
: result
:= 'message';
360 TRIGGER_DAMAGE
: result
:= 'damage';
361 TRIGGER_HEALTH
: result
:= 'health';
362 TRIGGER_SHOT
: result
:= 'shot';
363 TRIGGER_EFFECT
: result
:= 'effect';
364 TRIGGER_SCRIPT
: result
:= 'script';
368 // ////////////////////////////////////////////////////////////////////////// //
369 {$INCLUDE g_holmes_cmd.inc}
370 procedure holmesInitCommands (); forward;
371 procedure holmesInitBinds (); forward;
374 // ////////////////////////////////////////////////////////////////////////// //
376 g_ol_nice
: Boolean = false;
377 g_ol_fill_walls
: Boolean = false;
378 g_ol_rlayer_back
: Boolean = false;
379 g_ol_rlayer_step
: Boolean = false;
380 g_ol_rlayer_wall
: Boolean = false;
381 g_ol_rlayer_door
: Boolean = false;
382 g_ol_rlayer_acid1
: Boolean = false;
383 g_ol_rlayer_acid2
: Boolean = false;
384 g_ol_rlayer_water
: Boolean = false;
385 g_ol_rlayer_fore
: Boolean = false;
388 // ////////////////////////////////////////////////////////////////////////// //
390 winHelp
: THTopWindow
= nil;
391 winOptions
: THTopWindow
= nil;
392 winLayers
: THTopWindow
= nil;
393 winOutlines
: THTopWindow
= nil;
396 procedure createHelpWindow (); forward;
397 procedure createOptionsWindow (); forward;
398 procedure createLayersWindow (); forward;
399 procedure createOutlinesWindow (); forward;
402 procedure toggleLayersWindowCB (me
: THControl
; checked
: Integer);
404 if showLayersWindow
then
406 if (winLayers
= nil) then createLayersWindow();
407 uiAddWindow(winLayers
);
411 uiRemoveWindow(winLayers
);
416 procedure toggleOutlineWindowCB (me
: THControl
; checked
: Integer);
418 if showOutlineWindow
then
420 if (winOutlines
= nil) then createOutlinesWindow();
421 uiAddWindow(winOutlines
);
425 uiRemoveWindow(winOutlines
);
430 procedure createHelpWindow ();
432 llb
: THCtlSimpleText
;
433 slist
: array of AnsiString = nil;
435 bind
: THolmesBinding
;
436 f
, maxkeylen
: Integer;
439 for cmd
in cmdlist
do cmd
.helpmark
:= false;
442 for bind
in keybinds
do
444 if (Length(bind
.key
) = 0) then continue
;
445 if cmdlist
.get(bind
.cmdName
, cmd
) then
447 if (Length(cmd
.help
) > 0) then
449 cmd
.helpmark
:= true;
450 if (maxkeylen
< Length(bind
.key
)) then maxkeylen
:= Length(bind
.key
);
455 for cmd
in cmdlist
do
457 if not cmd
.helpmark
then continue
;
458 if (Length(cmd
.help
) = 0) then continue
;
460 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
461 if (f
= Length(slist
)) then
463 SetLength(slist
, Length(slist
)+1);
464 slist
[High(slist
)] := cmd
.section
;
468 llb
:= THCtlSimpleText
.Create(0, 0);
469 for f
:= 0 to High(slist
) do
471 if (f
> 0) then llb
.appendItem('');
472 llb
.appendItem(slist
[f
], true, true);
473 for cmd
in cmdlist
do
475 if not cmd
.helpmark
then continue
;
476 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
477 for bind
in keybinds
do
479 if (Length(bind
.key
) = 0) then continue
;
480 if (cmd
.name
= bind
.cmdName
) then
483 while (Length(s
) < maxkeylen
) do s
+= ' ';
484 s
:= ' '+s
+' -- '+cmd
.help
;
492 for bind
in msbinds
do
494 if (Length(bind
.key
) = 0) then continue
;
495 if cmdlist
.get(bind
.cmdName
, cmd
) then
497 if (Length(cmd
.help
) > 0) then
499 cmd
.helpmark
:= true;
500 if (maxkeylen
< Length(bind
.key
)) then maxkeylen
:= Length(bind
.key
);
506 llb
.appendItem('mouse', true, true);
507 for bind
in msbinds
do
509 if (Length(bind
.key
) = 0) then continue
;
510 if cmdlist
.get(bind
.cmdName
, cmd
) then
512 if (Length(cmd
.help
) > 0) then
515 while (Length(s
) < maxkeylen
) do s
+= ' ';
516 s
:= ' '+s
+' -- '+cmd
.help
;
522 winHelp
:= THTopWindow
.Create('Holmes Help', 10, 10);
523 winHelp
.escClose
:= true;
524 winHelp
.appendChild(llb
);
525 winHelp
.centerInScreen();
529 procedure winLayersClosed (me
: THControl
; dummy
: Integer); begin showLayersWindow
:= false; end;
530 procedure winOutlinesClosed (me
: THControl
; dummy
: Integer); begin showOutlineWindow
:= false; end;
532 procedure createLayersWindow ();
536 llb
:= THCtlCBListBox
.Create(0, 0);
537 llb
.appendItem('background', @g_rlayer_back
);
538 llb
.appendItem('steps', @g_rlayer_step
);
539 llb
.appendItem('walls', @g_rlayer_wall
);
540 llb
.appendItem('doors', @g_rlayer_door
);
541 llb
.appendItem('acid1', @g_rlayer_acid1
);
542 llb
.appendItem('acid2', @g_rlayer_acid2
);
543 llb
.appendItem('water', @g_rlayer_water
);
544 llb
.appendItem('foreground', @g_rlayer_fore
);
545 winLayers
:= THTopWindow
.Create('layers', 10, 10);
546 winLayers
.escClose
:= true;
547 winLayers
.appendChild(llb
);
548 winLayers
.closeCB
:= winLayersClosed
;
552 procedure createOutlinesWindow ();
556 llb
:= THCtlCBListBox
.Create(0, 0);
557 llb
.appendItem('background', @g_ol_rlayer_back
);
558 llb
.appendItem('steps', @g_ol_rlayer_step
);
559 llb
.appendItem('walls', @g_ol_rlayer_wall
);
560 llb
.appendItem('doors', @g_ol_rlayer_door
);
561 llb
.appendItem('acid1', @g_ol_rlayer_acid1
);
562 llb
.appendItem('acid2', @g_ol_rlayer_acid2
);
563 llb
.appendItem('water', @g_ol_rlayer_water
);
564 llb
.appendItem('foreground', @g_ol_rlayer_fore
);
565 llb
.appendItem('OPTIONS', nil);
566 llb
.appendItem('fill walls', @g_ol_fill_walls
);
567 llb
.appendItem('contours', @g_ol_nice
);
568 winOutlines
:= THTopWindow
.Create('outlines', 100, 10);
569 winOutlines
.escClose
:= true;
570 winOutlines
.appendChild(llb
);
571 winOutlines
.closeCB
:= winOutlinesClosed
;
575 procedure createOptionsWindow ();
579 llb
:= THCtlCBListBox
.Create(0, 0);
580 llb
.appendItem('map grid', @showGrid
);
581 llb
.appendItem('cursor position on map', @showMapCurPos
);
582 llb
.appendItem('monster info', @showMonsInfo
);
583 llb
.appendItem('monster LOS to player', @showMonsLOS2Plr
);
584 llb
.appendItem('monster cells (SLOW!)', @showAllMonsCells
);
585 llb
.appendItem('draw triggers (SLOW!)', @showTriggers
);
586 llb
.appendItem('WINDOWS', nil);
587 llb
.appendItem('layers window', @showLayersWindow
, toggleLayersWindowCB
);
588 llb
.appendItem('outline window', @showOutlineWindow
, toggleOutlineWindowCB
);
589 winOptions
:= THTopWindow
.Create('Holmes Options', 100, 100);
590 winOptions
.escClose
:= true;
591 winOptions
.appendChild(llb
);
592 winOptions
.centerInScreen();
596 procedure toggleLayersWindow (arg
: Integer=-1);
598 showLayersWindow
:= not showLayersWindow
;
599 toggleLayersWindowCB(nil, 0);
602 procedure toggleOutlineWindow (arg
: Integer=-1);
604 showOutlineWindow
:= not showOutlineWindow
;
605 toggleOutlineWindowCB(nil, 0);
608 procedure toggleHelpWindow (arg
: Integer=-1);
610 if (winHelp
= nil) then createHelpWindow();
611 if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
);
614 procedure toggleOptionsWindow (arg
: Integer=-1);
616 if (winOptions
= nil) then createOptionsWindow();
617 if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
);
621 // ////////////////////////////////////////////////////////////////////////// //
622 procedure g_Holmes_VidModeChanged ();
624 e_WriteLog(Format('Holmes: videomode changed: %dx%d', [gScreenWidth
, gScreenHeight
]), MSG_NOTIFY
);
625 // texture space is possibly lost here, idc
631 //createCursorTexture();
634 procedure g_Holmes_WindowFocused ();
640 procedure g_Holmes_WindowBlured ();
645 // ////////////////////////////////////////////////////////////////////////// //
647 vpSet
: Boolean = false;
650 laserSet
: Boolean = false;
651 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
652 monMarkedUID
: Integer = -1;
655 procedure g_Holmes_plrView (viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer);
664 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
671 laserSet
:= laserSet
; // shut up, fpc!
675 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
676 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
679 procedure plrDebugMouse (var ev
: THMouseEvent
);
681 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
682 if (gPlayer1
= nil) or not vpSet
then exit
;
683 //if (ev.kind <> THMouseEvent.Press) then exit;
684 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
690 edgeBmp
: array of Byte = nil;
693 procedure drawOutlines ();
697 procedure clearEdgeBmp ();
699 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
700 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
703 procedure drawPanel (pan
: TPanel
);
705 sx
, len
, y0
, y1
: Integer;
707 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
708 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
709 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
710 if g_ol_nice
or g_ol_fill_walls
then
714 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
715 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
716 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
717 if (len
< 1) then exit
;
719 assert(sx
+len
<= gWinSizeX
+4);
722 if (y0
< 0) then y0
:= 0;
723 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
726 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
732 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
741 procedure flushLine ();
743 if (lsy
> 0) and (lsx
> 0) then
748 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
754 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
755 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
763 procedure startLine (y
: Integer);
769 procedure putPixel (x
: Integer);
771 if (x
< 1) then exit
;
772 if (lex
+1 <> x
) then flushLine();
773 if (lsx
< 0) then lsx
:= x
;
777 procedure drawEdges ();
783 glDisable(GL_TEXTURE_2D
);
786 glDisable(GL_LINE_SMOOTH
);
787 glDisable(GL_POLYGON_SMOOTH
);
788 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
791 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
797 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
798 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
799 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
810 procedure drawFilledWalls ();
816 glDisable(GL_TEXTURE_2D
);
819 glDisable(GL_LINE_SMOOTH
);
820 glDisable(GL_POLYGON_SMOOTH
);
821 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
824 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
828 if (a
[0] <> 0) then putPixel(x
);
835 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
843 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
844 for f
:= 0 to High(parr
) do
847 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
848 if ((pan
.PanelType
and ptype
) = 0) then continue
;
851 if g_ol_nice
then drawEdges();
852 if g_ol_fill_walls
then drawFilledWalls();
858 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
860 result
:= false; // don't stop
861 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
862 if ((pan
.PanelType
and xptag
) = 0) then exit
;
866 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
872 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
873 else panelTypeToTag(ptype
);
874 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
875 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
876 if g_ol_nice
then drawEdges();
877 if g_ol_fill_walls
then drawFilledWalls();
881 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
882 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
883 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
884 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
885 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
886 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
887 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
888 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
892 procedure plrDebugDraw ();
893 procedure drawTileGrid ();
897 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
899 drawLine(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, 96, 96, 96, 255);
902 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
904 drawLine(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
, 96, 96, 96, 255);
908 procedure hilightCell (cx
, cy
: Integer);
910 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 0, 128, 0, 64);
913 procedure hilightCell1 (cx
, cy
: Integer);
915 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
916 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 255, 255, 0, 92);
919 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
921 result
:= false; // don't stop
922 if (pan
= nil) then exit
; // cell completion, ignore
923 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
924 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, 0, 128, 128, 64);
927 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
930 mx
, my
, mw
, mh
: Integer;
933 mon
.getMapBox(mx
, my
, mw
, mh
);
934 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
935 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
937 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
941 procedure drawMonsterInfo (mon
: TMonster
);
943 mx
, my
, mw
, mh
: Integer;
945 procedure drawMonsterTargetLine ();
947 emx
, emy
, emw
, emh
: Integer;
952 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
954 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
955 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
957 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
959 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
960 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
966 mon
.getMapBox(mx
, my
, mw
, mh
);
967 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
968 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
970 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
974 procedure drawLOS2Plr ();
976 emx
, emy
, emw
, emh
: Integer;
981 if (eplr
= nil) then exit
;
982 eplr
.getMapBox(emx
, emy
, emw
, emh
);
983 mon
.getMapBox(mx
, my
, mw
, mh
);
984 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
985 {$IF DEFINED(D2F_DEBUG)}
986 //mapGrid.dbgRayTraceTileHitCB := hilightCell1;
988 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
989 //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
991 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
993 {$IF DEFINED(D2F_DEBUG)}
994 //mapGrid.dbgRayTraceTileHitCB := nil;
999 if (mon
= nil) then exit
;
1000 mon
.getMapBox(mx
, my
, mw
, mh
);
1003 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1005 if showMonsInfo
then
1007 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1008 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
1013 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), 255, 127, 0); my
-= 8;
1015 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), 255, 127, 0); my
-= 8;
1017 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), 255, 127, 0); my
-= 8;
1019 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), 255, 127, 0); my
-= 8;
1021 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), 255, 127, 0); my
-= 8;
1023 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), 255, 127, 0); my
-= 8;
1024 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), 255, 127, 0); my
-= 8;
1027 drawMonsterTargetLine();
1028 if showMonsLOS2Plr
then drawLOS2Plr();
1030 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1031 property MonsterPain: Integer read FPain write FPain;
1032 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1036 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1038 result
:= false; // don't stop
1039 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1042 procedure drawTrigger (var trig
: TTrigger
);
1044 procedure drawPanelDest (pguid
: Integer);
1048 pan
:= g_Map_PanelByGUID(pguid
);
1049 if (pan
= nil) then exit
;
1051 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1052 pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2,
1060 fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
, 255, 0, 255, 96);
1061 tts
:= trigType2Str(trig
.TriggerType
);
1062 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1063 darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1064 drawText6(tx
, trig
.y
-9, tts
, 255, 127, 0);
1065 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1066 darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1067 drawText6(tx
, trig
.y
-19, trig
.mapId
, 255, 255, 0);
1068 drawPanelDest(trig
.trigPanelGUID
);
1069 case trig
.TriggerType
of
1070 TRIGGER_NONE
: begin end;
1071 TRIGGER_EXIT
: begin end;
1072 TRIGGER_TELEPORT
: begin end;
1073 TRIGGER_OPENDOOR
: begin end;
1074 TRIGGER_CLOSEDOOR
: begin end;
1075 TRIGGER_DOOR
: begin end;
1076 TRIGGER_DOOR5
: begin end;
1077 TRIGGER_CLOSETRAP
: begin end;
1078 TRIGGER_TRAP
: begin end;
1079 TRIGGER_SECRET
: begin end;
1080 TRIGGER_LIFTUP
: begin end;
1081 TRIGGER_LIFTDOWN
: begin end;
1082 TRIGGER_LIFT
: begin end;
1083 TRIGGER_TEXTURE
: begin end;
1084 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1086 if (trig
.trigData
.trigTWidth
> 0) and (trig
.trigData
.trigTHeight
> 0) then
1089 trig
.trigData
.trigTX
, trig
.trigData
.trigTY
,
1090 trig
.trigData
.trigTWidth
, trig
.trigData
.trigTHeight
,
1093 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1094 trig
.trigData
.trigTX
+trig
.trigData
.trigTWidth
div 2,
1095 trig
.trigData
.trigTY
+trig
.trigData
.trigTHeight
div 2,
1099 TRIGGER_SOUND
: begin end;
1100 TRIGGER_SPAWNMONSTER
: begin end;
1101 TRIGGER_SPAWNITEM
: begin end;
1102 TRIGGER_MUSIC
: begin end;
1103 TRIGGER_PUSH
: begin end;
1104 TRIGGER_SCORE
: begin end;
1105 TRIGGER_MESSAGE
: begin end;
1106 TRIGGER_DAMAGE
: begin end;
1107 TRIGGER_HEALTH
: begin end;
1108 TRIGGER_SHOT
: begin end;
1109 TRIGGER_EFFECT
: begin end;
1110 TRIGGER_SCRIPT
: begin end;
1113 //trigPanelId: Integer;
1116 procedure drawTriggers ();
1120 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1125 mx
, my
, mw
, mh
: Integer;
1127 if (gPlayer1
= nil) then exit
;
1129 glEnable(GL_SCISSOR_TEST
);
1130 glScissor(0, gWinSizeY
-gPlayerScreenSize
.Y
-1, vpw
, vph
);
1133 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
1134 glTranslatef(-vpx
, -vpy
, 0);
1136 if (showGrid
) then drawTileGrid();
1139 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
1141 if (monMarkedUID
<> -1) then
1143 mon
:= g_Monsters_ByUID(monMarkedUID
);
1144 if (mon
<> nil) then
1146 mon
.getMapBox(mx
, my
, mw
, mh
);
1147 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
1148 drawMonsterInfo(mon
);
1152 if showAllMonsCells
then g_Mons_ForEach(highlightAllMonsterCells
);
1153 if showTriggers
then drawTriggers();
1157 glDisable(GL_SCISSOR_TEST
);
1159 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), 255, 255, 0);
1163 // ////////////////////////////////////////////////////////////////////////// //
1164 function g_Holmes_MouseEvent (var ev
: THMouseEvent
): Boolean;
1166 holmesInitCommands();
1174 if not uiMouseEvent(ev
) then plrDebugMouse(ev
);
1178 // ////////////////////////////////////////////////////////////////////////// //
1179 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean;
1180 {$IF DEFINED(D2F_DEBUG)}
1187 procedure dummyWallTrc (cx
, cy
: Integer);
1192 holmesInitCommands();
1198 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1199 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1200 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1203 if uiKeyEvent(ev
) then begin result
:= true; exit
; end;
1204 if keybindExecute(ev
) then begin result
:= true; exit
; end;
1206 if (ev
.kind
= THKeyEvent
.Press
) then
1208 {$IF DEFINED(D2F_DEBUG)}
1209 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1210 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
1211 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
1217 SDL_SCANCODE_UP
: dy
-= 120;
1218 SDL_SCANCODE_DOWN
: dy
+= 120;
1219 SDL_SCANCODE_LEFT
: dx
-= 120;
1220 SDL_SCANCODE_RIGHT
: dx
+= 120;
1222 {$IF DEFINED(D2F_DEBUG)}
1223 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1224 mapGrid
.dbgShowTraceLog
:= true;
1226 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1227 {$IF DEFINED(D2F_DEBUG)}
1228 //mapGrid.dbgRayTraceTileHitCB := nil;
1229 mapGrid
.dbgShowTraceLog
:= false;
1231 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1239 // ////////////////////////////////////////////////////////////////////////// //
1240 procedure g_Holmes_Draw ();
1242 {$IF not DEFINED(HEADLESS)}
1243 holmesInitCommands();
1246 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1247 glDisable(GL_STENCIL_TEST
);
1248 glDisable(GL_BLEND
);
1249 glDisable(GL_SCISSOR_TEST
);
1250 glDisable(GL_TEXTURE_2D
);
1262 procedure g_Holmes_DrawUI ();
1264 {$IF not DEFINED(HEADLESS)}
1271 // ////////////////////////////////////////////////////////////////////////// //
1272 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1273 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1274 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1275 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1276 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1278 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1279 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1281 procedure bcMonsterWakeup ();
1285 if (monMarkedUID
<> -1) then
1287 mon
:= g_Monsters_ByUID(monMarkedUID
);
1288 if (mon
<> nil) then mon
.WakeUp();
1292 procedure bcPlayerTeleport ();
1294 x
, y
, w
, h
: Integer;
1296 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1297 if (gPlayers
[0] <> nil) then
1299 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1300 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1304 procedure cbAtcurSelectMonster ();
1305 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1307 result
:= true; // stop
1308 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1309 monMarkedUID
:= mon
.UID
;
1310 dumpPublishedProperties(mon
);
1314 x
, y
, w
, h
: Integer;
1317 if (Length(gPlayers
) > 0) then
1320 if (plr
<> nil) then
1322 plr
.getMapBox(x
, y
, w
, h
);
1323 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1325 dumpPublishedProperties(plr
);
1329 //e_WriteLog('===========================', MSG_NOTIFY);
1330 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1331 //e_WriteLog('---------------------------', MSG_NOTIFY);
1334 procedure cbAtcurDumpMonsters ();
1335 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1337 result
:= false; // don't stop
1338 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1341 e_WriteLog('===========================', MSG_NOTIFY
);
1342 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1343 e_WriteLog('---------------------------', MSG_NOTIFY
);
1346 procedure cbAtcurDumpWalls ();
1347 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1349 result
:= false; // don't stop
1350 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
]);
1351 dumpPublishedProperties(pan
);
1354 hasTrigs
: Boolean = false;
1358 e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY
);
1359 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1360 e_WriteLog('--- toggle wall ---', MSG_NOTIFY
);
1361 if showTriggers
then
1363 for f
:= 0 to High(gTriggers
) do
1365 trig
:= @gTriggers
[f
];
1366 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1368 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1369 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1372 if hasTrigs
then writeln('--- triggers ---');
1376 procedure cbAtcurToggleWalls ();
1377 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1379 result
:= false; // don't stop
1380 //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);
1381 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1384 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1385 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1386 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1390 // ////////////////////////////////////////////////////////////////////////// //
1391 procedure holmesInitCommands ();
1393 if (cmdlist
<> nil) then exit
;
1394 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1395 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1396 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1397 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1399 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1400 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1401 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1402 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1403 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1405 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1407 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1408 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1409 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1411 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1412 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1413 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1414 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1418 procedure holmesInitBinds ();
1421 pr
: TTextParser
= nil;
1422 s
, kn
, v
: AnsiString;
1427 if not keybindsInited
then
1430 keybindAdd('F1', 'win_help');
1431 keybindAdd('M-F1', 'win_options');
1432 keybindAdd('C-O', 'win_outline');
1433 keybindAdd('C-L', 'win_layers');
1435 keybindAdd('M-M', 'mon_think_step');
1436 keybindAdd('M-I', 'mon_info');
1437 keybindAdd('M-L', 'mon_los_plr');
1438 keybindAdd('M-G', 'mon_cells');
1439 keybindAdd('M-A', 'mon_wakeup');
1441 keybindAdd('C-T', 'plr_teleport');
1443 keybindAdd('C-P', 'dbg_curpos');
1444 keybindAdd('C-G', 'dbg_grid');
1445 keybindAdd('C-X', 'dbg_triggers');
1448 msbindAdd('LMB', 'atcur_select_monster');
1449 msbindAdd('M-LMB', 'atcur_dump_monsters');
1450 msbindAdd('RMB', 'atcur_dump_walls');
1451 msbindAdd('M-RMB', 'atcur_disable_walls');
1453 // load bindings from file
1455 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1456 pr
:= TFileTextParser
.Create(st
);
1457 conwriteln('parsing "holmes.rc"...');
1458 while (pr
.tokType
<> pr
.TTEOF
) do
1461 if (s
= 'stop') then break
1462 else if (s
= 'unbind_keys') then keybinds
:= nil
1463 else if (s
= 'unbind_mouse') then msbinds
:= nil
1464 else if (s
= 'bind') then
1466 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1467 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1468 else s
:= pr
.expectId();
1470 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1471 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1472 else v
:= pr
.expectId();
1474 kn
:= parseModKeys(s
, kmods
, mbuts
);
1475 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1485 except on e
: Exception
do // sorry
1486 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1488 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership