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
, g_gfx
,
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_plrViewPos (viewPortX
, viewPortY
: Integer);
87 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
88 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
91 operator
= (constref ev
: THKeyEvent
; const s
: AnsiString): Boolean;
92 operator
= (const s
: AnsiString; constref ev
: THKeyEvent
): Boolean;
94 operator
= (constref ev
: THMouseEvent
; const s
: AnsiString): Boolean;
95 operator
= (const s
: AnsiString; constref ev
: THMouseEvent
): Boolean;
99 g_holmes_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
100 g_holmes_ui_scale
: Single = 1.0;
107 SysUtils
, Classes
, GL
, SDL2
,
108 MAPDEF
, g_main
, g_options
,
109 utils
, hashtable
, xparser
;
113 //globalInited: Boolean = false;
116 msB
: Word = 0; // button state
117 kbS
: Word = 0; // keyboard modifiers state
118 showGrid
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
119 showMonsInfo
: Boolean = false;
120 showMonsLOS2Plr
: Boolean = false;
121 showAllMonsCells
: Boolean = false;
122 showMapCurPos
: Boolean = false;
123 showLayersWindow
: Boolean = false;
124 showOutlineWindow
: Boolean = false;
125 showTriggers
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
126 showTraceBox
: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
129 // ////////////////////////////////////////////////////////////////////////// //
130 {$INCLUDE g_holmes.inc}
131 {$INCLUDE g_holmes_ui.inc}
134 // ////////////////////////////////////////////////////////////////////////// //
135 // any mods = 255: nothing was defined
136 function parseModKeys (const s
: AnsiString; out kmods
: Byte; out mbuts
: Byte): AnsiString;
143 //while (pos <= Length(s)) and (s[pos] <= ' ') do Inc(pos);
144 if (pos
< Length(s
)) and ((s
[pos
] = '+') or (s
[pos
] = '-') or (s
[pos
] = '*')) then Inc(pos
);
145 while (pos
< Length(s
)) do
147 if (Length(s
)-pos
>= 2) and (s
[pos
+1] = '-') then
150 'C', 'c': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModCtrl
; Inc(pos
, 2); continue
; end;
151 'M', 'm': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModAlt
; Inc(pos
, 2); continue
; end;
152 'S', 's': begin if (kmods
= 255) then kmods
:= 0; kmods
:= kmods
or THKeyEvent
.ModShift
; Inc(pos
, 2); continue
; end;
156 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
159 'L', 'l': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Left
; Inc(pos
, 4); continue
; end;
160 'R', 'r': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Right
; Inc(pos
, 4); continue
; end;
161 'M', 'm': begin if (mbuts
= 255) then mbuts
:= 0; mbuts
:= mbuts
or THMouseEvent
.Middle
; Inc(pos
, 4); continue
; end;
168 while (epos
> pos
) and (s
[epos
-1] <= ' ') do Dec(epos
);
169 if (epos
> pos
) then result
:= Copy(s
, pos
, epos
-pos
) else result
:= '';
173 operator
= (constref ev
: THKeyEvent
; const s
: AnsiString): Boolean;
181 if (Length(s
) > 0) then
183 if (s
[1] = '+') then begin if (ev
.kind
<> ev
.Press
) then exit
; end
184 else if (s
[1] = '-') then begin if (ev
.kind
<> ev
.Release
) then exit
; end
185 else if (s
[1] = '*') then begin end
186 else if (ev
.kind
<> ev
.Press
) then exit
;
188 kname
:= parseModKeys(s
, kmods
, mbuts
);
189 if (kmods
= 255) then kmods
:= 0;
190 if (ev
.kstate
<> kmods
) then exit
;
191 if (mbuts
<> 255) and (ev
.bstate
<> mbuts
) then exit
;
192 for f
:= 1 to High(e_KeyNames
) do
194 if (CompareText(kname
, e_KeyNames
[f
]) = 0) then
196 result
:= (ev
.scan
= f
);
203 operator
= (const s
: AnsiString; constref ev
: THKeyEvent
): Boolean;
209 operator
= (constref ev
: THMouseEvent
; const s
: AnsiString): Boolean;
218 if (Length(s
) > 0) then
220 if (s
[1] = '+') then begin if (ev
.kind
<> ev
.Press
) then exit
; end
221 else if (s
[1] = '-') then begin if (ev
.kind
<> ev
.Release
) then exit
; end
222 else if (s
[1] = '*') then begin if (ev
.kind
<> ev
.Motion
) then exit
; end
223 else if (ev
.kind
<> ev
.Press
) then exit
;
226 kname
:= parseModKeys(s
, kmods
, mbuts
);
227 if (CompareText(kname
, 'LMB') = 0) then but
:= THMouseEvent
.Left
228 else if (CompareText(kname
, 'RMB') = 0) then but
:= THMouseEvent
.Right
229 else if (CompareText(kname
, 'MMB') = 0) then but
:= THMouseEvent
.Middle
230 else if (CompareText(kname
, 'None') = 0) then but
:= 0
233 //conwritefln('s=[%s]; kname=[%s]; kmods=%s; mbuts=%s; but=%s', [s, kname, kmods, mbuts, but]);
235 if (mbuts
= 255) then mbuts
:= 0;
236 if (kmods
= 255) then kmods
:= 0;
237 if (ev
.kstate
<> kmods
) then exit
;
239 if (ev
.kind
= ev
.Press
) then mbuts
:= mbuts
or but
240 else if (ev
.kind
= ev
.Release
) then mbuts
:= mbuts
and (not but
);
242 //conwritefln(' ev.bstate=%s; ev.but=%s; mbuts=%s', [ev.bstate, ev.but, mbuts]);
244 result
:= (ev
.bstate
= mbuts
) and (ev
.but
= but
);
248 operator
= (const s
: AnsiString; constref ev
: THMouseEvent
): Boolean;
254 // ////////////////////////////////////////////////////////////////////////// //
255 function typeKind2Str (t
: TTypeKind
): AnsiString;
258 tkUnknown
: result
:= 'Unknown';
259 tkInteger
: result
:= 'Integer';
260 tkChar
: result
:= 'Char';
261 tkEnumeration
: result
:= 'Enumeration';
262 tkFloat
: result
:= 'Float';
263 tkSet
: result
:= 'Set';
264 tkMethod
: result
:= 'Method';
265 tkSString
: result
:= 'SString';
266 tkLString
: result
:= 'LString';
267 tkAString
: result
:= 'AString';
268 tkWString
: result
:= 'WString';
269 tkVariant
: result
:= 'Variant';
270 tkArray
: result
:= 'Array';
271 tkRecord
: result
:= 'Record';
272 tkInterface
: result
:= 'Interface';
273 tkClass
: result
:= 'Class';
274 tkObject
: result
:= 'Object';
275 tkWChar
: result
:= 'WChar';
276 tkBool
: result
:= 'Bool';
277 tkInt64
: result
:= 'Int64';
278 tkQWord
: result
:= 'QWord';
279 tkDynArray
: result
:= 'DynArray';
280 tkInterfaceRaw
: result
:= 'InterfaceRaw';
281 tkProcVar
: result
:= 'ProcVar';
282 tkUString
: result
:= 'UString';
283 tkUChar
: result
:= 'UChar';
284 tkHelper
: result
:= 'Helper';
285 tkFile
: result
:= 'File';
286 tkClassRef
: result
:= 'ClassRef';
287 tkPointer
: result
:= 'Pointer';
288 else result
:= '<unknown>';
293 procedure dumpPublishedProperties (obj
: TObject
);
300 if (obj
= nil) then exit
;
301 e_LogWritefln('Object of type ''%s'':', [obj
.ClassName
]);
303 pt
:= GetTypeData(pi
);
304 e_LogWritefln('property count: %s', [pt
.PropCount
]);
305 GetMem(pp
, pt
^.PropCount
*sizeof(Pointer));
307 j
:= GetPropList(pi
, [tkInteger
, tkBool
, tkSString
, tkLString
, tkAString
, tkSet
, tkEnumeration
], pp
);
308 //e_LogWritefln('ordinal property count: %s', [j]);
311 if (typinfo
.PropType(obj
, pp
^[i
].name
) in [tkSString
, tkLString
, tkAString
]) then
313 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetStrProp(obj
, pp
^[i
])]);
315 else if (typinfo
.PropType(obj
, pp
^[i
].name
) = tkSet
) then
317 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)]);
319 else if (typinfo
.PropType(obj
, pp
^[i
].name
) = tkEnumeration
) then
321 e_LogWritefln(' #%s: <%s>; type: %s; value: <%s>', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetEnumProp(obj
, pp
^[i
])]);
325 e_LogWritefln(' #%s: <%s>; type: %s; value: %s', [i
+1, pp
^[i
].name
, typeKind2Str(typinfo
.PropType(obj
, pp
^[i
].name
)), GetOrdProp(obj
, pp
^[i
])]);
334 //FIXME: autogenerate
335 function trigType2Str (ttype
: Integer): AnsiString;
337 result
:= '<unknown>';
339 TRIGGER_NONE
: result
:= 'none';
340 TRIGGER_EXIT
: result
:= 'exit';
341 TRIGGER_TELEPORT
: result
:= 'teleport';
342 TRIGGER_OPENDOOR
: result
:= 'opendoor';
343 TRIGGER_CLOSEDOOR
: result
:= 'closedoor';
344 TRIGGER_DOOR
: result
:= 'door';
345 TRIGGER_DOOR5
: result
:= 'door5';
346 TRIGGER_CLOSETRAP
: result
:= 'closetrap';
347 TRIGGER_TRAP
: result
:= 'trap';
348 TRIGGER_PRESS
: result
:= 'press';
349 TRIGGER_SECRET
: result
:= 'secret';
350 TRIGGER_LIFTUP
: result
:= 'liftup';
351 TRIGGER_LIFTDOWN
: result
:= 'liftdown';
352 TRIGGER_LIFT
: result
:= 'lift';
353 TRIGGER_TEXTURE
: result
:= 'texture';
354 TRIGGER_ON
: result
:= 'on';
355 TRIGGER_OFF
: result
:= 'off';
356 TRIGGER_ONOFF
: result
:= 'onoff';
357 TRIGGER_SOUND
: result
:= 'sound';
358 TRIGGER_SPAWNMONSTER
: result
:= 'spawnmonster';
359 TRIGGER_SPAWNITEM
: result
:= 'spawnitem';
360 TRIGGER_MUSIC
: result
:= 'music';
361 TRIGGER_PUSH
: result
:= 'push';
362 TRIGGER_SCORE
: result
:= 'score';
363 TRIGGER_MESSAGE
: result
:= 'message';
364 TRIGGER_DAMAGE
: result
:= 'damage';
365 TRIGGER_HEALTH
: result
:= 'health';
366 TRIGGER_SHOT
: result
:= 'shot';
367 TRIGGER_EFFECT
: result
:= 'effect';
368 TRIGGER_SCRIPT
: result
:= 'script';
372 // ////////////////////////////////////////////////////////////////////////// //
373 {$INCLUDE g_holmes_cmd.inc}
374 procedure holmesInitCommands (); forward;
375 procedure holmesInitBinds (); forward;
378 // ////////////////////////////////////////////////////////////////////////// //
380 g_ol_nice
: Boolean = false;
381 g_ol_fill_walls
: Boolean = false;
382 g_ol_rlayer_back
: Boolean = false;
383 g_ol_rlayer_step
: Boolean = false;
384 g_ol_rlayer_wall
: Boolean = false;
385 g_ol_rlayer_door
: Boolean = false;
386 g_ol_rlayer_acid1
: Boolean = false;
387 g_ol_rlayer_acid2
: Boolean = false;
388 g_ol_rlayer_water
: Boolean = false;
389 g_ol_rlayer_fore
: Boolean = false;
392 // ////////////////////////////////////////////////////////////////////////// //
394 winHelp
: THTopWindow
= nil;
395 winOptions
: THTopWindow
= nil;
396 winLayers
: THTopWindow
= nil;
397 winOutlines
: THTopWindow
= nil;
400 procedure createHelpWindow (); forward;
401 procedure createOptionsWindow (); forward;
402 procedure createLayersWindow (); forward;
403 procedure createOutlinesWindow (); forward;
406 procedure toggleLayersWindowCB (me
: THControl
; checked
: Integer);
408 if showLayersWindow
then
410 if (winLayers
= nil) then createLayersWindow();
411 uiAddWindow(winLayers
);
415 uiRemoveWindow(winLayers
);
420 procedure toggleOutlineWindowCB (me
: THControl
; checked
: Integer);
422 if showOutlineWindow
then
424 if (winOutlines
= nil) then createOutlinesWindow();
425 uiAddWindow(winOutlines
);
429 uiRemoveWindow(winOutlines
);
434 procedure createHelpWindow ();
436 llb
: THCtlSimpleText
;
437 slist
: array of AnsiString = nil;
439 bind
: THolmesBinding
;
440 f
, maxkeylen
: Integer;
443 for cmd
in cmdlist
do cmd
.helpmark
:= false;
446 for bind
in keybinds
do
448 if (Length(bind
.key
) = 0) then continue
;
449 if cmdlist
.get(bind
.cmdName
, cmd
) then
451 if (Length(cmd
.help
) > 0) then
453 cmd
.helpmark
:= true;
454 if (maxkeylen
< Length(bind
.key
)) then maxkeylen
:= Length(bind
.key
);
459 for cmd
in cmdlist
do
461 if not cmd
.helpmark
then continue
;
462 if (Length(cmd
.help
) = 0) then continue
;
464 while (f
< Length(slist
)) and (CompareText(slist
[f
], cmd
.section
) <> 0) do Inc(f
);
465 if (f
= Length(slist
)) then
467 SetLength(slist
, Length(slist
)+1);
468 slist
[High(slist
)] := cmd
.section
;
472 llb
:= THCtlSimpleText
.Create(0, 0);
473 for f
:= 0 to High(slist
) do
475 if (f
> 0) then llb
.appendItem('');
476 llb
.appendItem(slist
[f
], true, true);
477 for cmd
in cmdlist
do
479 if not cmd
.helpmark
then continue
;
480 if (CompareText(cmd
.section
, slist
[f
]) <> 0) then continue
;
481 for bind
in keybinds
do
483 if (Length(bind
.key
) = 0) then continue
;
484 if (cmd
.name
= bind
.cmdName
) then
487 while (Length(s
) < maxkeylen
) do s
+= ' ';
488 s
:= ' '+s
+' -- '+cmd
.help
;
496 for bind
in msbinds
do
498 if (Length(bind
.key
) = 0) then continue
;
499 if cmdlist
.get(bind
.cmdName
, cmd
) then
501 if (Length(cmd
.help
) > 0) then
503 cmd
.helpmark
:= true;
504 if (maxkeylen
< Length(bind
.key
)) then maxkeylen
:= Length(bind
.key
);
510 llb
.appendItem('mouse', true, true);
511 for bind
in msbinds
do
513 if (Length(bind
.key
) = 0) then continue
;
514 if cmdlist
.get(bind
.cmdName
, cmd
) then
516 if (Length(cmd
.help
) > 0) then
519 while (Length(s
) < maxkeylen
) do s
+= ' ';
520 s
:= ' '+s
+' -- '+cmd
.help
;
526 winHelp
:= THTopWindow
.Create('Holmes Help', 10, 10);
527 winHelp
.escClose
:= true;
528 winHelp
.appendChild(llb
);
529 winHelp
.centerInScreen();
533 procedure winLayersClosed (me
: THControl
; dummy
: Integer); begin showLayersWindow
:= false; end;
534 procedure winOutlinesClosed (me
: THControl
; dummy
: Integer); begin showOutlineWindow
:= false; end;
536 procedure createLayersWindow ();
540 llb
:= THCtlCBListBox
.Create(0, 0);
541 llb
.appendItem('background', @g_rlayer_back
);
542 llb
.appendItem('steps', @g_rlayer_step
);
543 llb
.appendItem('walls', @g_rlayer_wall
);
544 llb
.appendItem('doors', @g_rlayer_door
);
545 llb
.appendItem('acid1', @g_rlayer_acid1
);
546 llb
.appendItem('acid2', @g_rlayer_acid2
);
547 llb
.appendItem('water', @g_rlayer_water
);
548 llb
.appendItem('foreground', @g_rlayer_fore
);
549 winLayers
:= THTopWindow
.Create('layers', 10, 10);
550 winLayers
.escClose
:= true;
551 winLayers
.appendChild(llb
);
552 winLayers
.closeCB
:= winLayersClosed
;
556 procedure createOutlinesWindow ();
560 llb
:= THCtlCBListBox
.Create(0, 0);
561 llb
.appendItem('background', @g_ol_rlayer_back
);
562 llb
.appendItem('steps', @g_ol_rlayer_step
);
563 llb
.appendItem('walls', @g_ol_rlayer_wall
);
564 llb
.appendItem('doors', @g_ol_rlayer_door
);
565 llb
.appendItem('acid1', @g_ol_rlayer_acid1
);
566 llb
.appendItem('acid2', @g_ol_rlayer_acid2
);
567 llb
.appendItem('water', @g_ol_rlayer_water
);
568 llb
.appendItem('foreground', @g_ol_rlayer_fore
);
569 llb
.appendItem('OPTIONS', nil);
570 llb
.appendItem('fill walls', @g_ol_fill_walls
);
571 llb
.appendItem('contours', @g_ol_nice
);
572 winOutlines
:= THTopWindow
.Create('outlines', 100, 10);
573 winOutlines
.escClose
:= true;
574 winOutlines
.appendChild(llb
);
575 winOutlines
.closeCB
:= winOutlinesClosed
;
579 procedure createOptionsWindow ();
583 llb
:= THCtlCBListBox
.Create(0, 0);
584 llb
.appendItem('map grid', @showGrid
);
585 llb
.appendItem('cursor position on map', @showMapCurPos
);
586 llb
.appendItem('monster info', @showMonsInfo
);
587 llb
.appendItem('monster LOS to player', @showMonsLOS2Plr
);
588 llb
.appendItem('monster cells (SLOW!)', @showAllMonsCells
);
589 llb
.appendItem('draw triggers (SLOW!)', @showTriggers
);
590 llb
.appendItem('WINDOWS', nil);
591 llb
.appendItem('layers window', @showLayersWindow
, toggleLayersWindowCB
);
592 llb
.appendItem('outline window', @showOutlineWindow
, toggleOutlineWindowCB
);
593 winOptions
:= THTopWindow
.Create('Holmes Options', 100, 100);
594 winOptions
.escClose
:= true;
595 winOptions
.appendChild(llb
);
596 winOptions
.centerInScreen();
600 procedure toggleLayersWindow (arg
: Integer=-1);
602 showLayersWindow
:= not showLayersWindow
;
603 toggleLayersWindowCB(nil, 0);
606 procedure toggleOutlineWindow (arg
: Integer=-1);
608 showOutlineWindow
:= not showOutlineWindow
;
609 toggleOutlineWindowCB(nil, 0);
612 procedure toggleHelpWindow (arg
: Integer=-1);
614 if (winHelp
= nil) then createHelpWindow();
615 if not uiVisibleWindow(winHelp
) then uiAddWindow(winHelp
) else uiRemoveWindow(winHelp
);
618 procedure toggleOptionsWindow (arg
: Integer=-1);
620 if (winOptions
= nil) then createOptionsWindow();
621 if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
);
625 // ////////////////////////////////////////////////////////////////////////// //
626 procedure g_Holmes_VidModeChanged ();
628 e_WriteLog(Format('Holmes: videomode changed: %dx%d', [gScreenWidth
, gScreenHeight
]), MSG_NOTIFY
);
629 // texture space is possibly lost here, idc
635 //createCursorTexture();
638 procedure g_Holmes_WindowFocused ();
644 procedure g_Holmes_WindowBlured ();
649 // ////////////////////////////////////////////////////////////////////////// //
651 vpSet
: Boolean = false;
654 laserSet
: Boolean = false;
655 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
656 monMarkedUID
: Integer = -1;
657 platMarkedGUID
: Integer = -1;
660 procedure g_Holmes_plrViewPos (viewPortX
, viewPortY
: Integer);
667 procedure g_Holmes_plrViewSize (viewPortW
, viewPortH
: Integer);
674 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
681 laserSet
:= laserSet
; // shut up, fpc!
685 function pmsCurMapX (): Integer; inline; begin result
:= round(msX
/g_dbg_scale
)+vpx
; end;
686 function pmsCurMapY (): Integer; inline; begin result
:= round(msY
/g_dbg_scale
)+vpy
; end;
689 procedure plrDebugMouse (var ev
: THMouseEvent
);
691 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
692 if (gPlayer1
= nil) or not vpSet
then exit
;
693 //if (ev.kind <> THMouseEvent.Press) then exit;
694 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
700 edgeBmp
: array of Byte = nil;
703 procedure drawOutlines ();
707 procedure clearEdgeBmp ();
709 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
710 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
713 procedure drawPanel (pan
: TPanel
);
715 sx
, len
, y0
, y1
: Integer;
717 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
718 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
719 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
720 if g_ol_nice
or g_ol_fill_walls
then
724 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
725 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
726 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
727 if (len
< 1) then exit
;
729 assert(sx
+len
<= gWinSizeX
+4);
732 if (y0
< 0) then y0
:= 0;
733 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
736 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
742 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
751 procedure flushLine ();
753 if (lsy
> 0) and (lsx
> 0) then
758 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
764 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
765 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
773 procedure startLine (y
: Integer);
779 procedure putPixel (x
: Integer);
781 if (x
< 1) then exit
;
782 if (lex
+1 <> x
) then flushLine();
783 if (lsx
< 0) then lsx
:= x
;
787 procedure drawEdges ();
793 glDisable(GL_TEXTURE_2D
);
796 glDisable(GL_LINE_SMOOTH
);
797 glDisable(GL_POLYGON_SMOOTH
);
798 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
801 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
807 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
808 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
809 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
820 procedure drawFilledWalls ();
826 glDisable(GL_TEXTURE_2D
);
829 glDisable(GL_LINE_SMOOTH
);
830 glDisable(GL_POLYGON_SMOOTH
);
831 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
834 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
838 if (a
[0] <> 0) then putPixel(x
);
845 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
853 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
854 for f
:= 0 to High(parr
) do
857 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
858 if ((pan
.PanelType
and ptype
) = 0) then continue
;
861 if g_ol_nice
then drawEdges();
862 if g_ol_fill_walls
then drawFilledWalls();
868 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
870 result
:= false; // don't stop
871 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
872 if ((pan
.PanelType
and xptag
) = 0) then exit
;
876 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
882 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
883 else panelTypeToTag(ptype
);
884 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
885 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
886 if g_ol_nice
then drawEdges();
887 if g_ol_fill_walls
then drawFilledWalls();
891 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
892 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
893 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
894 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
895 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
896 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
897 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
898 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
902 procedure plrDebugDraw ();
903 procedure drawTileGrid ();
907 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
909 drawLine(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, 96, 96, 96, 255);
912 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
914 drawLine(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
, 96, 96, 96, 255);
918 procedure drawAwakeCells ();
922 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
924 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
926 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
928 fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
, 128, 0, 128, 64);
934 procedure drawTraceBox ();
937 px
, py
, pw
, ph
: Integer;
942 if (Length(gPlayers
) < 1) then exit
;
944 if (plr
= nil) then exit
;
945 plr
.getMapBox(px
, py
, pw
, ph
);
946 drawRect(px
, py
, pw
, ph
, 255, 0, 255, 200);
947 pdx
:= pmsCurMapX
-(px
+pw
div 2);
948 pdy
:= pmsCurMapY
-(py
+ph
div 2);
949 drawLine(px
+pw
div 2, py
+ph
div 2, px
+pw
div 2+pdx
, py
+ph
div 2+pdy
, 255, 0, 255, 200);
950 pan
:= mapGrid
.traceBox(ex
, ey
, px
, py
, pw
, ph
, pdx
, pdy
, nil, GridTagObstacle
);
953 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, 255, 255, 255, 180);
957 drawRect(px
+pdx
, py
+pdy
, pw
, ph
, 255, 255, 0, 180);
959 drawRect(ex
, ey
, pw
, ph
, 255, 127, 0, 180);
962 procedure hilightCell (cx
, cy
: Integer);
964 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 0, 128, 0, 64);
967 procedure hilightCell1 (cx
, cy
: Integer);
969 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
970 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 255, 255, 0, 92);
973 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
975 result
:= false; // don't stop
976 if (pan
= nil) then exit
; // cell completion, ignore
977 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
978 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, 0, 128, 128, 64);
981 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
984 mx
, my
, mw
, mh
: Integer;
987 mon
.getMapBox(mx
, my
, mw
, mh
);
988 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
989 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
991 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
995 procedure drawMonsterInfo (mon
: TMonster
);
997 mx
, my
, mw
, mh
: Integer;
999 procedure drawMonsterTargetLine ();
1001 emx
, emy
, emw
, emh
: Integer;
1006 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
1008 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
1009 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1011 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
1013 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
1014 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
1020 mon
.getMapBox(mx
, my
, mw
, mh
);
1021 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
1022 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1024 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
1028 procedure drawLOS2Plr ();
1030 emx
, emy
, emw
, emh
: Integer;
1034 eplr
:= gPlayers
[0];
1035 if (eplr
= nil) then exit
;
1036 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1037 mon
.getMapBox(mx
, my
, mw
, mh
);
1038 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
1039 {$IF DEFINED(D2F_DEBUG)}
1040 //mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1042 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1043 //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
1045 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
1047 {$IF DEFINED(D2F_DEBUG)}
1048 //mapGrid.dbgRayTraceTileHitCB := nil;
1053 if (mon
= nil) then exit
;
1054 mon
.getMapBox(mx
, my
, mw
, mh
);
1057 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1059 if showMonsInfo
then
1061 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1062 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
1067 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), 255, 127, 0); my
-= 8;
1069 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), 255, 127, 0); my
-= 8;
1071 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), 255, 127, 0); my
-= 8;
1073 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), 255, 127, 0); my
-= 8;
1075 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), 255, 127, 0); my
-= 8;
1077 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), 255, 127, 0); my
-= 8;
1078 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), 255, 127, 0); my
-= 8;
1081 drawMonsterTargetLine();
1082 if showMonsLOS2Plr
then drawLOS2Plr();
1084 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1085 property MonsterPain: Integer read FPain write FPain;
1086 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1090 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1092 result
:= false; // don't stop
1093 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1096 procedure drawSelectedPlatformCells ();
1100 if not showGrid
then exit
;
1101 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1102 if (pan
= nil) then exit
;
1103 mapGrid
.forEachBodyCell(pan
.proxyId
, hilightCell
);
1104 drawRect(pan
.x
, pan
.y
, pan
.width
, pan
.height
, 0, 200, 0, 200);
1107 procedure drawTrigger (var trig
: TTrigger
);
1109 procedure drawPanelDest (pguid
: Integer);
1113 pan
:= g_Map_PanelByGUID(pguid
);
1114 if (pan
= nil) then exit
;
1116 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1117 pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2,
1125 fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
, 255, 0, 255, 96);
1126 tts
:= trigType2Str(trig
.TriggerType
);
1127 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1128 darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1129 drawText6(tx
, trig
.y
-9, tts
, 255, 127, 0);
1130 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1131 darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1132 drawText6(tx
, trig
.y
-19, trig
.mapId
, 255, 255, 0);
1133 drawPanelDest(trig
.trigPanelGUID
);
1134 case trig
.TriggerType
of
1135 TRIGGER_NONE
: begin end;
1136 TRIGGER_EXIT
: begin end;
1137 TRIGGER_TELEPORT
: begin end;
1138 TRIGGER_OPENDOOR
: begin end;
1139 TRIGGER_CLOSEDOOR
: begin end;
1140 TRIGGER_DOOR
: begin end;
1141 TRIGGER_DOOR5
: begin end;
1142 TRIGGER_CLOSETRAP
: begin end;
1143 TRIGGER_TRAP
: begin end;
1144 TRIGGER_SECRET
: begin end;
1145 TRIGGER_LIFTUP
: begin end;
1146 TRIGGER_LIFTDOWN
: begin end;
1147 TRIGGER_LIFT
: begin end;
1148 TRIGGER_TEXTURE
: begin end;
1149 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1151 if (trig
.trigDataRec
.trigTWidth
> 0) and (trig
.trigDataRec
.trigTHeight
> 0) then
1154 trig
.trigDataRec
.trigTX
, trig
.trigDataRec
.trigTY
,
1155 trig
.trigDataRec
.trigTWidth
, trig
.trigDataRec
.trigTHeight
,
1158 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1159 trig
.trigDataRec
.trigTX
+trig
.trigDataRec
.trigTWidth
div 2,
1160 trig
.trigDataRec
.trigTY
+trig
.trigDataRec
.trigTHeight
div 2,
1164 TRIGGER_SOUND
: begin end;
1165 TRIGGER_SPAWNMONSTER
: begin end;
1166 TRIGGER_SPAWNITEM
: begin end;
1167 TRIGGER_MUSIC
: begin end;
1168 TRIGGER_PUSH
: begin end;
1169 TRIGGER_SCORE
: begin end;
1170 TRIGGER_MESSAGE
: begin end;
1171 TRIGGER_DAMAGE
: begin end;
1172 TRIGGER_HEALTH
: begin end;
1173 TRIGGER_SHOT
: begin end;
1174 TRIGGER_EFFECT
: begin end;
1175 TRIGGER_SCRIPT
: begin end;
1178 //trigPanelId: Integer;
1181 procedure drawTriggers ();
1185 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1188 procedure drawGibsBoxes ();
1191 px
, py
, pw
, ph
: Integer;
1194 for f
:= 0 to High(gGibs
) do
1199 gib
.getMapBox(px
, py
, pw
, ph
);
1200 drawRect(px
, py
, pw
, ph
, 255, 0, 255);
1207 mx
, my
, mw
, mh
: Integer;
1209 if (gPlayer1
= nil) then exit
;
1211 glEnable(GL_SCISSOR_TEST
);
1212 glScissor(0, gWinSizeY
-gPlayerScreenSize
.Y
-1, vpw
, vph
);
1215 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
1216 glTranslatef(-vpx
, -vpy
, 0);
1218 if (showGrid
) then drawTileGrid();
1221 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
1223 if (monMarkedUID
<> -1) then
1225 mon
:= g_Monsters_ByUID(monMarkedUID
);
1226 if (mon
<> nil) then
1228 mon
.getMapBox(mx
, my
, mw
, mh
);
1229 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
1230 drawMonsterInfo(mon
);
1234 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1235 if showTriggers
then drawTriggers();
1236 if showGrid
then drawSelectedPlatformCells();
1240 if showTraceBox
then drawTraceBox();
1246 glDisable(GL_SCISSOR_TEST
);
1248 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), 255, 255, 0);
1252 // ////////////////////////////////////////////////////////////////////////// //
1253 function g_Holmes_MouseEvent (var ev
: THMouseEvent
): Boolean;
1257 holmesInitCommands();
1260 msX
:= trunc(ev
.x
/g_holmes_ui_scale
);
1261 msY
:= trunc(ev
.y
/g_holmes_ui_scale
);
1266 he
.x
:= trunc(he
.x
/g_holmes_ui_scale
);
1267 he
.y
:= trunc(he
.y
/g_holmes_ui_scale
);
1268 if not uiMouseEvent(he
) then plrDebugMouse(he
);
1272 // ////////////////////////////////////////////////////////////////////////// //
1273 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean;
1274 {$IF DEFINED(D2F_DEBUG)}
1281 procedure dummyWallTrc (cx
, cy
: Integer);
1286 holmesInitCommands();
1292 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1293 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1294 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1297 if uiKeyEvent(ev
) then begin result
:= true; exit
; end;
1298 if keybindExecute(ev
) then begin result
:= true; exit
; end;
1300 if (ev
.kind
= THKeyEvent
.Press
) then
1302 {$IF DEFINED(D2F_DEBUG)}
1303 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1304 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
1305 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
1311 SDL_SCANCODE_UP
: dy
-= 120;
1312 SDL_SCANCODE_DOWN
: dy
+= 120;
1313 SDL_SCANCODE_LEFT
: dx
-= 120;
1314 SDL_SCANCODE_RIGHT
: dx
+= 120;
1316 {$IF DEFINED(D2F_DEBUG)}
1317 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1318 mapGrid
.dbgShowTraceLog
:= true;
1320 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1321 {$IF DEFINED(D2F_DEBUG)}
1322 //mapGrid.dbgRayTraceTileHitCB := nil;
1323 mapGrid
.dbgShowTraceLog
:= false;
1325 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1333 // ////////////////////////////////////////////////////////////////////////// //
1334 procedure g_Holmes_Draw ();
1336 {$IF not DEFINED(HEADLESS)}
1337 holmesInitCommands();
1340 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1341 glDisable(GL_STENCIL_TEST
);
1342 glDisable(GL_BLEND
);
1343 glDisable(GL_SCISSOR_TEST
);
1344 glDisable(GL_TEXTURE_2D
);
1356 procedure g_Holmes_DrawUI ();
1358 {$IF not DEFINED(HEADLESS)}
1360 glScalef(g_holmes_ui_scale
, g_holmes_ui_scale
, 1.0);
1368 // ////////////////////////////////////////////////////////////////////////// //
1369 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1370 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1371 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1373 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1374 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1375 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1376 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1378 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1379 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1381 procedure bcMonsterSpawn (s
: AnsiString);
1385 if not gGameOn
or g_Game_IsClient
then
1387 conwriteln('cannot spawn monster in this mode');
1390 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1391 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1392 monMarkedUID
:= mon
.UID
;
1395 procedure bcMonsterWakeup ();
1399 if (monMarkedUID
<> -1) then
1401 mon
:= g_Monsters_ByUID(monMarkedUID
);
1402 if (mon
<> nil) then mon
.WakeUp();
1406 procedure bcPlayerTeleport ();
1408 x
, y
, w
, h
: Integer;
1410 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1411 if (gPlayers
[0] <> nil) then
1413 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1414 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1418 procedure dbgToggleTraceBox (arg
: Integer=-1); begin if (arg
< 0) then showTraceBox
:= not showTraceBox
else showTraceBox
:= (arg
> 0); end;
1420 procedure cbAtcurSelectMonster ();
1421 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1423 result
:= true; // stop
1424 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1425 monMarkedUID
:= mon
.UID
;
1426 dumpPublishedProperties(mon
);
1430 x
, y
, w
, h
: Integer;
1433 if (Length(gPlayers
) > 0) then
1436 if (plr
<> nil) then
1438 plr
.getMapBox(x
, y
, w
, h
);
1439 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1441 dumpPublishedProperties(plr
);
1445 //e_WriteLog('===========================', MSG_NOTIFY);
1446 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1447 //e_WriteLog('---------------------------', MSG_NOTIFY);
1450 procedure cbAtcurDumpMonsters ();
1451 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1453 result
:= false; // don't stop
1454 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1457 e_WriteLog('===========================', MSG_NOTIFY
);
1458 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1459 e_WriteLog('---------------------------', MSG_NOTIFY
);
1462 procedure cbAtcurDumpWalls ();
1463 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1465 result
:= false; // don't stop
1466 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1467 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
]);
1468 dumpPublishedProperties(pan
);
1471 hasTrigs
: Boolean = false;
1475 platMarkedGUID
:= -1;
1476 e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY
);
1477 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1478 e_WriteLog('--- toggle wall ---', MSG_NOTIFY
);
1479 if showTriggers
then
1481 for f
:= 0 to High(gTriggers
) do
1483 trig
:= @gTriggers
[f
];
1484 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1486 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1487 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1490 if hasTrigs
then writeln('--- triggers ---');
1494 procedure cbAtcurToggleWalls ();
1495 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1497 result
:= false; // don't stop
1498 //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);
1499 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1502 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1503 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1504 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1508 // ////////////////////////////////////////////////////////////////////////// //
1509 procedure holmesInitCommands ();
1511 if (cmdlist
<> nil) then exit
;
1512 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1513 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1514 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1515 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1517 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1518 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1519 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1520 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1521 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'wake up selected monster', 'monster control');
1523 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1525 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1526 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1528 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1530 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1531 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1532 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1534 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1535 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1536 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1537 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1539 cmdAdd('dbg_tracebox', dbgToggleTraceBox
, 'test traceBox()', 'player control');
1543 procedure holmesInitBinds ();
1546 pr
: TTextParser
= nil;
1547 s
, kn
, v
: AnsiString;
1552 if not keybindsInited
then
1555 keybindAdd('F1', 'win_help');
1556 keybindAdd('M-F1', 'win_options');
1557 keybindAdd('C-O', 'win_outline');
1558 keybindAdd('C-L', 'win_layers');
1560 keybindAdd('M-M', 'mon_think_step');
1561 keybindAdd('M-I', 'mon_info');
1562 keybindAdd('M-L', 'mon_los_plr');
1563 keybindAdd('M-G', 'mon_cells');
1564 keybindAdd('M-A', 'mon_wakeup');
1566 keybindAdd('M-P', 'mplat_step');
1567 keybindAdd('M-O', 'mplat_toggle');
1569 keybindAdd('C-T', 'plr_teleport');
1570 keybindAdd('M-T', 'dbg_tracebox');
1572 keybindAdd('C-P', 'dbg_curpos');
1573 keybindAdd('C-G', 'dbg_grid');
1574 keybindAdd('C-X', 'dbg_triggers');
1576 keybindAdd('C-1', 'mon_spawn zombie');
1579 msbindAdd('LMB', 'atcur_select_monster');
1580 msbindAdd('M-LMB', 'atcur_dump_monsters');
1581 msbindAdd('RMB', 'atcur_dump_walls');
1582 msbindAdd('M-RMB', 'atcur_disable_walls');
1584 // load bindings from file
1586 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1587 pr
:= TFileTextParser
.Create(st
);
1588 conwriteln('parsing "holmes.rc"...');
1589 while (pr
.tokType
<> pr
.TTEOF
) do
1592 if (s
= 'stop') then break
1593 else if (s
= 'unbind_keys') then keybinds
:= nil
1594 else if (s
= 'unbind_mouse') then msbinds
:= nil
1595 else if (s
= 'bind') then
1597 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1598 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1599 else s
:= pr
.expectId();
1601 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1602 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1603 else v
:= pr
.expectId();
1605 kn
:= parseModKeys(s
, kmods
, mbuts
);
1606 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1616 except on e
: Exception
do // sorry
1617 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1619 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1625 conRegVar('hlm_ui_scale', @g_holmes_ui_scale
, 0.01, 5.0, 'Holmes UI scale', '', false);