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_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 drawAwakeCells ();
915 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
917 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
919 if awmIsSetHolmes(x
*mapGrid
.tileSize
+mapGrid
.gridX0
+1, y
*mapGrid
.tileSize
++mapGrid
.gridY0
+1) then
921 fillRect(x
*mapGrid
.tileSize
++mapGrid
.gridX0
, y
*mapGrid
.tileSize
++mapGrid
.gridY0
, monsGrid
.tileSize
, monsGrid
.tileSize
, 128, 0, 128, 64);
927 procedure hilightCell (cx
, cy
: Integer);
929 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 0, 128, 0, 64);
932 procedure hilightCell1 (cx
, cy
: Integer);
934 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
935 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 255, 255, 0, 92);
938 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
940 result
:= false; // don't stop
941 if (pan
= nil) then exit
; // cell completion, ignore
942 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
943 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, 0, 128, 128, 64);
946 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
949 mx
, my
, mw
, mh
: Integer;
952 mon
.getMapBox(mx
, my
, mw
, mh
);
953 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
954 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
956 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
960 procedure drawMonsterInfo (mon
: TMonster
);
962 mx
, my
, mw
, mh
: Integer;
964 procedure drawMonsterTargetLine ();
966 emx
, emy
, emw
, emh
: Integer;
971 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
973 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
974 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
976 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
978 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
979 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
985 mon
.getMapBox(mx
, my
, mw
, mh
);
986 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
987 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 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
993 procedure drawLOS2Plr ();
995 emx
, emy
, emw
, emh
: Integer;
1000 if (eplr
= nil) then exit
;
1001 eplr
.getMapBox(emx
, emy
, emw
, emh
);
1002 mon
.getMapBox(mx
, my
, mw
, mh
);
1003 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
1004 {$IF DEFINED(D2F_DEBUG)}
1005 //mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1007 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
1008 //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
1010 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
1012 {$IF DEFINED(D2F_DEBUG)}
1013 //mapGrid.dbgRayTraceTileHitCB := nil;
1018 if (mon
= nil) then exit
;
1019 mon
.getMapBox(mx
, my
, mw
, mh
);
1022 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1024 if showMonsInfo
then
1026 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1027 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
1032 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), 255, 127, 0); my
-= 8;
1034 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), 255, 127, 0); my
-= 8;
1036 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), 255, 127, 0); my
-= 8;
1038 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), 255, 127, 0); my
-= 8;
1040 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), 255, 127, 0); my
-= 8;
1042 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), 255, 127, 0); my
-= 8;
1043 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), 255, 127, 0); my
-= 8;
1046 drawMonsterTargetLine();
1047 if showMonsLOS2Plr
then drawLOS2Plr();
1049 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1050 property MonsterPain: Integer read FPain write FPain;
1051 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1055 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
1057 result
:= false; // don't stop
1058 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
1061 procedure drawSelectedPlatformCells ();
1065 if not showGrid
then exit
;
1066 pan
:= g_Map_PanelByGUID(platMarkedGUID
);
1067 if (pan
= nil) then exit
;
1068 mapGrid
.forEachBodyCell(pan
.proxyId
, hilightCell
);
1069 drawRect(pan
.x
, pan
.y
, pan
.width
, pan
.height
, 0, 200, 0, 200);
1072 procedure drawTrigger (var trig
: TTrigger
);
1074 procedure drawPanelDest (pguid
: Integer);
1078 pan
:= g_Map_PanelByGUID(pguid
);
1079 if (pan
= nil) then exit
;
1081 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1082 pan
.x
+pan
.width
div 2, pan
.y
+pan
.height
div 2,
1090 fillRect(trig
.x
, trig
.y
, trig
.width
, trig
.height
, 255, 0, 255, 96);
1091 tts
:= trigType2Str(trig
.TriggerType
);
1092 tx
:= trig
.x
+(trig
.width
-Length(tts
)*6) div 2;
1093 darkenRect(tx
-2, trig
.y
-10, Length(tts
)*6+4, 10, 64);
1094 drawText6(tx
, trig
.y
-9, tts
, 255, 127, 0);
1095 tx
:= trig
.x
+(trig
.width
-Length(trig
.mapId
)*6) div 2;
1096 darkenRect(tx
-2, trig
.y
-20, Length(trig
.mapId
)*6+4, 10, 64);
1097 drawText6(tx
, trig
.y
-19, trig
.mapId
, 255, 255, 0);
1098 drawPanelDest(trig
.trigPanelGUID
);
1099 case trig
.TriggerType
of
1100 TRIGGER_NONE
: begin end;
1101 TRIGGER_EXIT
: begin end;
1102 TRIGGER_TELEPORT
: begin end;
1103 TRIGGER_OPENDOOR
: begin end;
1104 TRIGGER_CLOSEDOOR
: begin end;
1105 TRIGGER_DOOR
: begin end;
1106 TRIGGER_DOOR5
: begin end;
1107 TRIGGER_CLOSETRAP
: begin end;
1108 TRIGGER_TRAP
: begin end;
1109 TRIGGER_SECRET
: begin end;
1110 TRIGGER_LIFTUP
: begin end;
1111 TRIGGER_LIFTDOWN
: begin end;
1112 TRIGGER_LIFT
: begin end;
1113 TRIGGER_TEXTURE
: begin end;
1114 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
, TRIGGER_PRESS
:
1116 if (trig
.trigData
.trigTWidth
> 0) and (trig
.trigData
.trigTHeight
> 0) then
1119 trig
.trigData
.trigTX
, trig
.trigData
.trigTY
,
1120 trig
.trigData
.trigTWidth
, trig
.trigData
.trigTHeight
,
1123 trig
.trigCenter
.x
, trig
.trigCenter
.y
,
1124 trig
.trigData
.trigTX
+trig
.trigData
.trigTWidth
div 2,
1125 trig
.trigData
.trigTY
+trig
.trigData
.trigTHeight
div 2,
1129 TRIGGER_SOUND
: begin end;
1130 TRIGGER_SPAWNMONSTER
: begin end;
1131 TRIGGER_SPAWNITEM
: begin end;
1132 TRIGGER_MUSIC
: begin end;
1133 TRIGGER_PUSH
: begin end;
1134 TRIGGER_SCORE
: begin end;
1135 TRIGGER_MESSAGE
: begin end;
1136 TRIGGER_DAMAGE
: begin end;
1137 TRIGGER_HEALTH
: begin end;
1138 TRIGGER_SHOT
: begin end;
1139 TRIGGER_EFFECT
: begin end;
1140 TRIGGER_SCRIPT
: begin end;
1143 //trigPanelId: Integer;
1146 procedure drawTriggers ();
1150 for f
:= 0 to High(gTriggers
) do drawTrigger(gTriggers
[f
]);
1153 procedure drawGibsBoxes ();
1156 px
, py
, pw
, ph
: Integer;
1159 for f
:= 0 to High(gGibs
) do
1164 gib
.getMapBox(px
, py
, pw
, ph
);
1165 drawRect(px
, py
, pw
, ph
, 255, 0, 255);
1172 mx
, my
, mw
, mh
: Integer;
1174 if (gPlayer1
= nil) then exit
;
1176 glEnable(GL_SCISSOR_TEST
);
1177 glScissor(0, gWinSizeY
-gPlayerScreenSize
.Y
-1, vpw
, vph
);
1180 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
1181 glTranslatef(-vpx
, -vpy
, 0);
1183 if (showGrid
) then drawTileGrid();
1186 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
1188 if (monMarkedUID
<> -1) then
1190 mon
:= g_Monsters_ByUID(monMarkedUID
);
1191 if (mon
<> nil) then
1193 mon
.getMapBox(mx
, my
, mw
, mh
);
1194 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
1195 drawMonsterInfo(mon
);
1199 if showAllMonsCells
and showGrid
then g_Mons_ForEach(highlightAllMonsterCells
);
1200 if showTriggers
then drawTriggers();
1201 if showGrid
then drawSelectedPlatformCells();
1209 glDisable(GL_SCISSOR_TEST
);
1211 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), 255, 255, 0);
1215 // ////////////////////////////////////////////////////////////////////////// //
1216 function g_Holmes_MouseEvent (var ev
: THMouseEvent
): Boolean;
1220 holmesInitCommands();
1223 msX
:= trunc(ev
.x
/g_holmes_ui_scale
);
1224 msY
:= trunc(ev
.y
/g_holmes_ui_scale
);
1229 he
.x
:= trunc(he
.x
/g_holmes_ui_scale
);
1230 he
.y
:= trunc(he
.y
/g_holmes_ui_scale
);
1231 if not uiMouseEvent(he
) then plrDebugMouse(he
);
1235 // ////////////////////////////////////////////////////////////////////////// //
1236 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean;
1237 {$IF DEFINED(D2F_DEBUG)}
1244 procedure dummyWallTrc (cx
, cy
: Integer);
1249 holmesInitCommands();
1255 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
1256 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
1257 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
1260 if uiKeyEvent(ev
) then begin result
:= true; exit
; end;
1261 if keybindExecute(ev
) then begin result
:= true; exit
; end;
1263 if (ev
.kind
= THKeyEvent
.Press
) then
1265 {$IF DEFINED(D2F_DEBUG)}
1266 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1267 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
1268 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
1274 SDL_SCANCODE_UP
: dy
-= 120;
1275 SDL_SCANCODE_DOWN
: dy
+= 120;
1276 SDL_SCANCODE_LEFT
: dx
-= 120;
1277 SDL_SCANCODE_RIGHT
: dx
+= 120;
1279 {$IF DEFINED(D2F_DEBUG)}
1280 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1281 mapGrid
.dbgShowTraceLog
:= true;
1283 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
1284 {$IF DEFINED(D2F_DEBUG)}
1285 //mapGrid.dbgRayTraceTileHitCB := nil;
1286 mapGrid
.dbgShowTraceLog
:= false;
1288 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
1296 // ////////////////////////////////////////////////////////////////////////// //
1297 procedure g_Holmes_Draw ();
1299 {$IF not DEFINED(HEADLESS)}
1300 holmesInitCommands();
1303 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
1304 glDisable(GL_STENCIL_TEST
);
1305 glDisable(GL_BLEND
);
1306 glDisable(GL_SCISSOR_TEST
);
1307 glDisable(GL_TEXTURE_2D
);
1319 procedure g_Holmes_DrawUI ();
1321 {$IF not DEFINED(HEADLESS)}
1323 glScalef(g_holmes_ui_scale
, g_holmes_ui_scale
, 1.0);
1331 // ////////////////////////////////////////////////////////////////////////// //
1332 procedure bcOneMonsterThinkStep (); begin gmon_debug_think
:= false; gmon_debug_one_think_step
:= true; end;
1333 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active
:= false; g_dbgpan_mplat_step
:= true; end;
1334 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active
:= not g_dbgpan_mplat_active
; end;
1336 procedure bcToggleMonsterInfo (arg
: Integer=-1); begin if (arg
< 0) then showMonsInfo
:= not showMonsInfo
else showMonsInfo
:= (arg
> 0); end;
1337 procedure bcToggleMonsterLOSPlr (arg
: Integer=-1); begin if (arg
< 0) then showMonsLOS2Plr
:= not showMonsLOS2Plr
else showMonsLOS2Plr
:= (arg
> 0); end;
1338 procedure bcToggleMonsterCells (arg
: Integer=-1); begin if (arg
< 0) then showAllMonsCells
:= not showAllMonsCells
else showAllMonsCells
:= (arg
> 0); end;
1339 procedure bcToggleDrawTriggers (arg
: Integer=-1); begin if (arg
< 0) then showTriggers
:= not showTriggers
else showTriggers
:= (arg
> 0); end;
1341 procedure bcToggleCurPos (arg
: Integer=-1); begin if (arg
< 0) then showMapCurPos
:= not showMapCurPos
else showMapCurPos
:= (arg
> 0); end;
1342 procedure bcToggleGrid (arg
: Integer=-1); begin if (arg
< 0) then showGrid
:= not showGrid
else showGrid
:= (arg
> 0); end;
1344 procedure bcMonsterSpawn (s
: AnsiString);
1348 if not gGameOn
or g_Game_IsClient
then
1350 conwriteln('cannot spawn monster in this mode');
1353 mon
:= g_Mons_SpawnAt(s
, pmsCurMapX
, pmsCurMapY
);
1354 if (mon
= nil) then begin conwritefln('unknown monster id: ''%s''', [s
]); exit
; end;
1355 monMarkedUID
:= mon
.UID
;
1358 procedure bcMonsterWakeup ();
1362 if (monMarkedUID
<> -1) then
1364 mon
:= g_Monsters_ByUID(monMarkedUID
);
1365 if (mon
<> nil) then mon
.WakeUp();
1369 procedure bcPlayerTeleport ();
1371 x
, y
, w
, h
: Integer;
1373 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1374 if (gPlayers
[0] <> nil) then
1376 gPlayers
[0].getMapBox(x
, y
, w
, h
);
1377 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
1381 procedure cbAtcurSelectMonster ();
1382 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1384 result
:= true; // stop
1385 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1386 monMarkedUID
:= mon
.UID
;
1387 dumpPublishedProperties(mon
);
1391 x
, y
, w
, h
: Integer;
1394 if (Length(gPlayers
) > 0) then
1397 if (plr
<> nil) then
1399 plr
.getMapBox(x
, y
, w
, h
);
1400 if (pmsCurMapX
>= x
) and (pmsCurMapY
>= y
) and (pmsCurMapX
< x
+w
) and (pmsCurMapY
< y
+h
) then
1402 dumpPublishedProperties(plr
);
1406 //e_WriteLog('===========================', MSG_NOTIFY);
1407 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1408 //e_WriteLog('---------------------------', MSG_NOTIFY);
1411 procedure cbAtcurDumpMonsters ();
1412 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
1414 result
:= false; // don't stop
1415 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
1418 e_WriteLog('===========================', MSG_NOTIFY
);
1419 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
1420 e_WriteLog('---------------------------', MSG_NOTIFY
);
1423 procedure cbAtcurDumpWalls ();
1424 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1426 result
:= false; // don't stop
1427 if (platMarkedGUID
= -1) then platMarkedGUID
:= pan
.guid
;
1428 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
]);
1429 dumpPublishedProperties(pan
);
1432 hasTrigs
: Boolean = false;
1436 platMarkedGUID
:= -1;
1437 e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY
);
1438 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1439 e_WriteLog('--- toggle wall ---', MSG_NOTIFY
);
1440 if showTriggers
then
1442 for f
:= 0 to High(gTriggers
) do
1444 trig
:= @gTriggers
[f
];
1445 if (pmsCurMapX
>= trig
.x
) and (pmsCurMapY
>= trig
.y
) and (pmsCurMapX
< trig
.x
+trig
.width
) and (pmsCurMapY
< trig
.y
+trig
.height
) then
1447 if not hasTrigs
then begin writeln('=== TRIGGERS ==='); hasTrigs
:= true; end;
1448 writeln('trigger ''', trig
.mapId
, ''' of type ''', trigType2Str(trig
.TriggerType
), '''');
1451 if hasTrigs
then writeln('--- triggers ---');
1455 procedure cbAtcurToggleWalls ();
1456 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
1458 result
:= false; // don't stop
1459 //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);
1460 if pan
.Enabled
then g_Map_DisableWallGUID(pan
.guid
) else g_Map_EnableWallGUID(pan
.guid
);
1463 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1464 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
1465 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1469 // ////////////////////////////////////////////////////////////////////////// //
1470 procedure holmesInitCommands ();
1472 if (cmdlist
<> nil) then exit
;
1473 cmdAdd('win_layers', toggleLayersWindow
, 'toggle layers window', 'window control');
1474 cmdAdd('win_outline', toggleOutlineWindow
, 'toggle outline window', 'window control');
1475 cmdAdd('win_help', toggleHelpWindow
, 'toggle help window', 'window control');
1476 cmdAdd('win_options', toggleOptionsWindow
, 'toggle options window', 'window control');
1478 cmdAdd('mon_think_step', bcOneMonsterThinkStep
, 'one monster think step', 'monster control');
1479 cmdAdd('mon_info', bcToggleMonsterInfo
, 'toggle monster info', 'monster control');
1480 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr
, 'toggle monster LOS to player', 'monster control');
1481 cmdAdd('mon_cells', bcToggleMonsterCells
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1482 cmdAdd('mon_wakeup', bcMonsterWakeup
, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1484 cmdAdd('mon_spawn', bcMonsterSpawn
, 'spawn monster', 'monster control');
1486 cmdAdd('mplat_step', bcOneMPlatThinkStep
, 'one mplat think step', 'mplat control');
1487 cmdAdd('mplat_toggle', bcMPlatToggle
, 'activate/deactivate moving platforms', 'mplat control');
1489 cmdAdd('plr_teleport', bcPlayerTeleport
, 'teleport player', 'player control');
1491 cmdAdd('dbg_curpos', bcToggleCurPos
, 'toggle "show cursor position on the map"', 'various');
1492 cmdAdd('dbg_grid', bcToggleGrid
, 'toggle grid', 'various');
1493 cmdAdd('dbg_triggers', bcToggleDrawTriggers
, 'show/hide triggers (SLOW!)', 'various');
1495 cmdAdd('atcur_select_monster', cbAtcurSelectMonster
, 'select monster to operate', 'monster control');
1496 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters
, 'dump monsters in cell', 'monster control');
1497 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls
, 'dump walls in cell', 'wall control');
1498 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls
, 'disable walls', 'wall control');
1502 procedure holmesInitBinds ();
1505 pr
: TTextParser
= nil;
1506 s
, kn
, v
: AnsiString;
1511 if not keybindsInited
then
1514 keybindAdd('F1', 'win_help');
1515 keybindAdd('M-F1', 'win_options');
1516 keybindAdd('C-O', 'win_outline');
1517 keybindAdd('C-L', 'win_layers');
1519 keybindAdd('M-M', 'mon_think_step');
1520 keybindAdd('M-I', 'mon_info');
1521 keybindAdd('M-L', 'mon_los_plr');
1522 keybindAdd('M-G', 'mon_cells');
1523 keybindAdd('M-A', 'mon_wakeup');
1525 keybindAdd('M-P', 'mplat_step');
1526 keybindAdd('M-O', 'mplat_toggle');
1528 keybindAdd('C-T', 'plr_teleport');
1530 keybindAdd('C-P', 'dbg_curpos');
1531 keybindAdd('C-G', 'dbg_grid');
1532 keybindAdd('C-X', 'dbg_triggers');
1534 keybindAdd('C-1', 'mon_spawn zombie');
1537 msbindAdd('LMB', 'atcur_select_monster');
1538 msbindAdd('M-LMB', 'atcur_dump_monsters');
1539 msbindAdd('RMB', 'atcur_dump_walls');
1540 msbindAdd('M-RMB', 'atcur_disable_walls');
1542 // load bindings from file
1544 st
:= openDiskFileRO(GameDir
+'holmes.rc');
1545 pr
:= TFileTextParser
.Create(st
);
1546 conwriteln('parsing "holmes.rc"...');
1547 while (pr
.tokType
<> pr
.TTEOF
) do
1550 if (s
= 'stop') then break
1551 else if (s
= 'unbind_keys') then keybinds
:= nil
1552 else if (s
= 'unbind_mouse') then msbinds
:= nil
1553 else if (s
= 'bind') then
1555 if (pr
.tokType
= pr
.TTStr
) then s
:= pr
.expectStr(false)
1556 else if (pr
.tokType
= pr
.TTInt
) then s
:= Format('%d', [pr
.expectInt()])
1557 else s
:= pr
.expectId();
1559 if (pr
.tokType
= pr
.TTStr
) then v
:= pr
.expectStr(false)
1560 else if (pr
.tokType
= pr
.TTInt
) then v
:= Format('%d', [pr
.expectInt()])
1561 else v
:= pr
.expectId();
1563 kn
:= parseModKeys(s
, kmods
, mbuts
);
1564 if (CompareText(kn
, 'lmb') = 0) or (CompareText(kn
, 'rmb') = 0) or (CompareText(kn
, 'mmb') = 0) or (CompareText(kn
, 'None') = 0) then
1574 except on e
: Exception
do // sorry
1575 if (pr
<> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
1577 if (pr
<> nil) then pr
.Free() else st
.Free(); // ownership
1583 conRegVar('hlm_ui_scale', @g_holmes_ui_scale
, 0.01, 5.0, 'Holmes UI scale', '', false);