DEADSOFTWARE

Holmes: better UI hotkeys; fitting windows to screen
[d2df-sdl.git] / src / game / g_holmes.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
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.
7 *
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.
12 *
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/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_holmes;
19 interface
21 uses
22 {$IFDEF USE_MEMPOOL}mempool,{$ENDIF} geom,
23 e_log, e_input,
24 g_textures, g_basic, e_graphics, g_phys, g_grid, g_player, g_monsters,
25 g_window, g_map, g_triggers, g_items, g_game, g_panel, g_console, g_gfx,
26 xprofiler,
27 sdlcarcass, glgfx, gh_ui_common, gh_ui;
30 procedure g_Holmes_Draw ();
31 procedure g_Holmes_DrawUI ();
33 procedure g_Holmes_MouseEvent (var ev: THMouseEvent);
34 procedure g_Holmes_KeyEvent (var ev: THKeyEvent);
36 // hooks for player
37 procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer);
38 procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer);
39 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
42 var
43 g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
46 implementation
48 uses
49 {rttiobj,} typinfo, e_texture,
50 SysUtils, Classes, GL, SDL2,
51 MAPDEF, g_main, g_options,
52 utils, hashtable, xparser;
55 var
56 //globalInited: Boolean = false;
57 msX: Integer = -666;
58 msY: Integer = -666;
59 msB: Word = 0; // button state
60 kbS: Word = 0; // keyboard modifiers state
61 showGrid: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
62 showMonsInfo: Boolean = false;
63 showMonsLOS2Plr: Boolean = false;
64 showAllMonsCells: Boolean = false;
65 showMapCurPos: Boolean = false;
66 showLayersWindow: Boolean = false;
67 showOutlineWindow: Boolean = false;
68 showTriggers: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
69 showTraceBox: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
72 // ////////////////////////////////////////////////////////////////////////// //
73 {$INCLUDE g_holmes.inc}
74 {$INCLUDE g_holmes_ol.inc} // outliner
77 // ////////////////////////////////////////////////////////////////////////// //
78 {$INCLUDE g_holmes_cmd.inc}
79 procedure holmesInitCommands (); forward;
80 procedure holmesInitBinds (); forward;
83 // ////////////////////////////////////////////////////////////////////////// //
84 var
85 g_ol_nice: Boolean = false;
86 g_ol_fill_walls: Boolean = false;
87 g_ol_rlayer_back: Boolean = false;
88 g_ol_rlayer_step: Boolean = false;
89 g_ol_rlayer_wall: Boolean = false;
90 g_ol_rlayer_door: Boolean = false;
91 g_ol_rlayer_acid1: Boolean = false;
92 g_ol_rlayer_acid2: Boolean = false;
93 g_ol_rlayer_water: Boolean = false;
94 g_ol_rlayer_fore: Boolean = false;
97 // ////////////////////////////////////////////////////////////////////////// //
98 var
99 winHelp: TUITopWindow = nil;
100 winOptions: TUITopWindow = nil;
101 winLayers: TUITopWindow = nil;
102 winOutlines: TUITopWindow = nil;
105 procedure createHelpWindow (); forward;
106 procedure createOptionsWindow (); forward;
107 procedure createLayersWindow (); forward;
108 procedure createOutlinesWindow (); forward;
111 procedure toggleLayersWindowCB (me: TUIControl);
112 begin
113 showLayersWindow := not showLayersWindow;
114 if showLayersWindow then
115 begin
116 if (winLayers = nil) then createLayersWindow();
117 uiAddWindow(winLayers);
118 end
119 else
120 begin
121 uiRemoveWindow(winLayers);
122 end;
123 end;
125 procedure toggleOutlineWindowCB (me: TUIControl);
126 begin
127 showOutlineWindow := not showOutlineWindow;
128 if showOutlineWindow then
129 begin
130 if (winOutlines = nil) then createOutlinesWindow();
131 uiAddWindow(winOutlines);
132 end
133 else
134 begin
135 uiRemoveWindow(winOutlines);
136 end;
137 end;
140 procedure createHelpWindow ();
141 procedure addHelpEmptyLine ();
142 var
143 stx: TUIStaticText;
144 begin
145 stx := TUIStaticText.Create();
146 stx.flExpand := true;
147 stx.halign := 0; // center
148 stx.text := '';
149 stx.header := false;
150 stx.line := false;
151 winHelp.appendChild(stx);
152 end;
154 procedure addHelpCaptionLine (const txt: AnsiString);
155 var
156 stx: TUIStaticText;
157 begin
158 stx := TUIStaticText.Create();
159 stx.flExpand := true;
160 stx.halign := 0; // center
161 stx.text := txt;
162 stx.header := true;
163 stx.line := true;
164 winHelp.appendChild(stx);
165 end;
167 procedure addHelpCaption (const txt: AnsiString);
168 var
169 stx: TUIStaticText;
170 begin
171 stx := TUIStaticText.Create();
172 stx.flExpand := true;
173 stx.halign := 0; // center
174 stx.text := txt;
175 stx.header := true;
176 stx.line := false;
177 winHelp.appendChild(stx);
178 end;
180 procedure addHelpKeyMouse (const key, txt, grp: AnsiString);
181 var
182 box: TUIHBox;
183 span: TUISpan;
184 stx: TUIStaticText;
185 begin
186 box := TUIHBox.Create();
187 box.flExpand := true;
188 // key
189 stx := TUIStaticText.Create();
190 stx.flExpand := true;
191 stx.halign := 1; // right
192 stx.valign := 0; // center
193 stx.text := key;
194 stx.header := true;
195 stx.line := false;
196 stx.flHGroup := grp;
197 box.appendChild(stx);
198 // span
199 span := TUISpan.Create();
200 span.flDefaultSize := TLaySize.Create(4, 1);
201 span.flExpand := true;
202 box.appendChild(span);
203 // text
204 stx := TUIStaticText.Create();
205 stx.flExpand := true;
206 stx.halign := -1; // left
207 stx.valign := 0; // center
208 stx.text := txt;
209 stx.header := false;
210 stx.line := false;
211 box.appendChild(stx);
212 winHelp.appendChild(box);
213 end;
215 procedure addHelpKey (const key, txt: AnsiString); begin addHelpKeyMouse(key, txt, 'help-keys'); end;
216 procedure addHelpMouse (const key, txt: AnsiString); begin addHelpKeyMouse(key, txt, 'help-mouse'); end;
218 var
219 slist: array of AnsiString = nil;
220 cmd: PHolmesCommand;
221 bind: THolmesBinding;
222 f: Integer;
224 llb: TUISimpleText;
225 maxkeylen: Integer;
226 s: AnsiString;
228 begin
229 winHelp := TUITopWindow.Create('Holmes Help');
230 winHelp.escClose := true;
231 winHelp.flHoriz := false;
233 // keyboard
234 for cmd in cmdlist do cmd.helpmark := false;
236 //maxkeylen := 0;
237 for bind in keybinds do
238 begin
239 if (Length(bind.key) = 0) then continue;
240 if cmdlist.get(bind.cmdName, cmd) then
241 begin
242 if (Length(cmd.help) > 0) then
243 begin
244 cmd.helpmark := true;
245 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
246 end;
247 end;
248 end;
250 for cmd in cmdlist do
251 begin
252 if not cmd.helpmark then continue;
253 if (Length(cmd.help) = 0) then begin cmd.helpmark := false; continue; end;
254 f := 0;
255 while (f < Length(slist)) and (CompareText(slist[f], cmd.section) <> 0) do Inc(f);
256 if (f = Length(slist)) then
257 begin
258 SetLength(slist, Length(slist)+1);
259 slist[High(slist)] := cmd.section;
260 end;
261 end;
263 addHelpCaptionLine('KEYBOARD');
264 //llb := TUISimpleText.Create(0, 0);
265 for f := 0 to High(slist) do
266 begin
267 //if (f > 0) then llb.appendItem('');
268 if (f > 0) then addHelpEmptyLine();
269 //llb.appendItem(slist[f], true, true);
270 addHelpCaption(slist[f]);
271 for cmd in cmdlist do
272 begin
273 if not cmd.helpmark then continue;
274 if (CompareText(cmd.section, slist[f]) <> 0) then continue;
275 for bind in keybinds do
276 begin
277 if (Length(bind.key) = 0) then continue;
278 if (cmd.name = bind.cmdName) then
279 begin
280 //s := bind.key;
281 //while (Length(s) < maxkeylen) do s += ' ';
282 //s := ' '+s+' -- '+cmd.help;
283 //llb.appendItem(s);
284 addHelpMouse(bind.key, cmd.help);
285 end;
286 end;
287 end;
288 end;
290 // mouse
291 for cmd in cmdlist do cmd.helpmark := false;
293 //maxkeylen := 0;
294 for bind in msbinds do
295 begin
296 if (Length(bind.key) = 0) then continue;
297 if cmdlist.get(bind.cmdName, cmd) then
298 begin
299 if (Length(cmd.help) > 0) then
300 begin
301 cmd.helpmark := true;
302 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
303 end;
304 end;
305 end;
307 //llb.appendItem('');
308 //llb.appendItem('mouse', true, true);
309 if (f > 0) then addHelpEmptyLine();
310 addHelpCaptionLine('MOUSE');
311 for bind in msbinds do
312 begin
313 if (Length(bind.key) = 0) then continue;
314 if cmdlist.get(bind.cmdName, cmd) then
315 begin
316 if (Length(cmd.help) > 0) then
317 begin
318 //s := bind.key;
319 //while (Length(s) < maxkeylen) do s += ' ';
320 //s := ' '+s+' -- '+cmd.help;
321 //llb.appendItem(s);
322 addHelpKey(bind.key, cmd.help);
323 end;
324 end;
325 end;
327 //winHelp.appendChild(llb);
329 uiLayoutCtl(winHelp);
330 winHelp.centerInScreen();
331 end;
334 procedure winLayersClosed (me: TUIControl); begin showLayersWindow := false; end;
335 procedure winOutlinesClosed (me: TUIControl); begin showOutlineWindow := false; end;
337 procedure addCheckBox (parent: TUIControl; const text: AnsiString; pvar: PBoolean);
338 var
339 cb: TUICheckBox;
340 begin
341 cb := TUICheckBox.Create();
342 cb.flExpand := true;
343 cb.setVar(pvar);
344 cb.text := text;
345 parent.appendChild(cb);
346 end;
348 procedure addButton (parent: TUIControl; const text: AnsiString; cb: TUIControl.TActionCB);
349 var
350 but: TUIButton;
351 begin
352 but := TUIButton.Create();
353 //but.flExpand := true;
354 but.actionCB := cb;
355 but.text := text;
356 parent.appendChild(but);
357 end;
360 procedure createLayersWindow ();
361 var
362 box: TUIVBox;
363 begin
364 winLayers := TUITopWindow.Create('layers');
365 winLayers.flHoriz := false;
366 winLayers.x0 := 10;
367 winLayers.y0 := 10;
368 winLayers.flHoriz := false;
369 winLayers.escClose := true;
370 winLayers.closeCB := winLayersClosed;
372 box := TUIVBox.Create();
373 addCheckBox(box, '~background', @g_rlayer_back);
374 addCheckBox(box, '~steps', @g_rlayer_step);
375 addCheckBox(box, '~walls', @g_rlayer_wall);
376 addCheckBox(box, '~doors', @g_rlayer_door);
377 addCheckBox(box, 'acid~1', @g_rlayer_acid1);
378 addCheckBox(box, 'acid~2', @g_rlayer_acid2);
379 addCheckBox(box, 'wate~r', @g_rlayer_water);
380 addCheckBox(box, '~foreground', @g_rlayer_fore);
381 winLayers.appendChild(box);
383 uiLayoutCtl(winLayers);
384 end;
387 procedure createOutlinesWindow ();
388 var
389 box: TUIVBox;
390 begin
391 winOutlines := TUITopWindow.Create('outlines');
392 winOutlines.flHoriz := false;
393 winOutlines.x0 := 100;
394 winOutlines.y0 := 30;
395 winOutlines.flHoriz := false;
396 winOutlines.escClose := true;
397 winOutlines.closeCB := winOutlinesClosed;
399 box := TUIVBox.Create();
400 box.hasFrame := true;
401 box.caption := 'layers';
402 addCheckBox(box, '~background', @g_ol_rlayer_back);
403 addCheckBox(box, '~steps', @g_ol_rlayer_step);
404 addCheckBox(box, '~walls', @g_ol_rlayer_wall);
405 addCheckBox(box, '~doors', @g_ol_rlayer_door);
406 addCheckBox(box, 'acid~1', @g_ol_rlayer_acid1);
407 addCheckBox(box, 'acid~2', @g_ol_rlayer_acid2);
408 addCheckBox(box, 'wate~r', @g_ol_rlayer_water);
409 addCheckBox(box, '~foreground', @g_ol_rlayer_fore);
410 winOutlines.appendChild(box);
412 box := TUIVBox.Create();
413 box.hasFrame := true;
414 box.caption := 'options';
415 addCheckBox(box, 'fi~ll walls', @g_ol_fill_walls);
416 addCheckBox(box, 'con~tours', @g_ol_nice);
417 winOutlines.appendChild(box);
419 uiLayoutCtl(winOutlines);
420 end;
423 procedure createOptionsWindow ();
424 var
425 box: TUIBox;
426 span: TUISpan;
427 begin
428 winOptions := TUITopWindow.Create('Holmes Options');
429 winOptions.flHoriz := false;
430 winOptions.flHoriz := false;
431 winOptions.escClose := true;
433 box := TUIVBox.Create();
434 box.hasFrame := true;
435 box.caption := 'visual';
436 addCheckBox(box, 'map ~grid', @showGrid);
437 addCheckBox(box, 'cursor ~position on map', @showMapCurPos);
438 addCheckBox(box, '~monster info', @showMonsInfo);
439 addCheckBox(box, 'monster LO~S to player', @showMonsLOS2Plr);
440 addCheckBox(box, 'monster ~cells (SLOW!)', @showAllMonsCells);
441 addCheckBox(box, 'draw ~triggers (SLOW!)', @showTriggers);
442 winOptions.appendChild(box);
444 box := TUIHBox.Create();
445 box.hasFrame := true;
446 box.caption := 'windows';
447 box.captionAlign := 0;
448 box.flAlign := 0;
449 addButton(box, '~layers', toggleLayersWindowCB);
450 span := TUISpan.Create();
451 span.flExpand := true;
452 span.flDefaultSize := TLaySize.Create(4, 1);
453 box.appendChild(span);
454 addButton(box, '~outline', toggleOutlineWindowCB);
455 winOptions.appendChild(box);
457 uiLayoutCtl(winOptions);
458 winOptions.centerInScreen();
459 end;
462 procedure toggleLayersWindow (arg: Integer=-1);
463 begin
464 if (arg < 0) then showLayersWindow := not showLayersWindow else showLayersWindow := (arg > 0);
465 showLayersWindow := not showLayersWindow; // hack for callback
466 toggleLayersWindowCB(nil);
467 end;
469 procedure toggleOutlineWindow (arg: Integer=-1);
470 begin
471 if (arg < 0) then showOutlineWindow := not showOutlineWindow else showOutlineWindow := (arg > 0);
472 showOutlineWindow := not showOutlineWindow; // hack for callback
473 toggleOutlineWindowCB(nil);
474 end;
476 procedure toggleHelpWindow (arg: Integer=-1);
477 begin
478 if (winHelp = nil) then createHelpWindow();
479 if (arg < 0) then begin if not uiVisibleWindow(winHelp) then uiAddWindow(winHelp) else uiRemoveWindow(winHelp); end
480 else if (arg = 0) then begin if uiVisibleWindow(winHelp) then uiRemoveWindow(winHelp); end
481 else begin if not uiVisibleWindow(winHelp) then uiAddWindow(winHelp); end
482 end;
484 procedure toggleOptionsWindow (arg: Integer=-1);
485 begin
486 if (winOptions = nil) then createOptionsWindow();
487 if (arg < 0) then begin if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions) else uiRemoveWindow(winOptions); end
488 else if (arg = 0) then begin if uiVisibleWindow(winOptions) then uiRemoveWindow(winOptions); end
489 else begin if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions); end
490 end;
493 // ////////////////////////////////////////////////////////////////////////// //
494 var
495 vpSet: Boolean = false;
496 vpx, vpy: Integer;
497 vpw, vph: Integer;
498 laserSet: Boolean = false;
499 laserX0, laserY0, laserX1, laserY1: Integer;
500 monMarkedUID: Integer = -1;
501 platMarkedGUID: Integer = -1;
504 procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer);
505 begin
506 vpSet := true;
507 vpx := viewPortX;
508 vpy := viewPortY;
509 end;
511 procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer);
512 begin
513 vpSet := true;
514 vpw := viewPortW;
515 vph := viewPortH;
516 end;
518 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
519 begin
520 laserSet := true;
521 laserX0 := ax0;
522 laserY0 := ay0;
523 laserX1 := ax1;
524 laserY1 := ay1;
525 laserSet := laserSet; // shut up, fpc!
526 end;
529 function pmsCurMapX (): Integer; inline; begin result := round(msX/g_dbg_scale)+vpx; end;
530 function pmsCurMapY (): Integer; inline; begin result := round(msY/g_dbg_scale)+vpy; end;
533 procedure plrDebugMouse (var ev: THMouseEvent);
534 begin
535 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
536 if (gPlayer1 = nil) or not vpSet then exit;
537 //if (ev.kind <> THMouseEvent.Press) then exit;
538 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
539 msbindExecute(ev);
540 end;
543 {$IFDEF HOLMES_OLD_OUTLINES}
544 var
545 edgeBmp: array of Byte = nil;
548 procedure drawOutlines ();
549 var
550 r, g, b: Integer;
552 procedure clearEdgeBmp ();
553 begin
554 SetLength(edgeBmp, (gWinSizeX+4)*(gWinSizeY+4));
555 FillChar(edgeBmp[0], Length(edgeBmp)*sizeof(edgeBmp[0]), 0);
556 end;
558 procedure drawPanel (pan: TPanel);
559 var
560 sx, len, y0, y1: Integer;
561 begin
562 if (pan = nil) or (pan.Width < 1) or (pan.Height < 1) then exit;
563 if (pan.X+pan.Width <= vpx-1) or (pan.Y+pan.Height <= vpy-1) then exit;
564 if (pan.X >= vpx+vpw+1) or (pan.Y >= vpy+vph+1) then exit;
565 if g_ol_nice or g_ol_fill_walls then
566 begin
567 sx := pan.X-(vpx-1);
568 len := pan.Width;
569 if (len > gWinSizeX+4) then len := gWinSizeX+4;
570 if (sx < 0) then begin len += sx; sx := 0; end;
571 if (sx+len > gWinSizeX+4) then len := gWinSizeX+4-sx;
572 if (len < 1) then exit;
573 assert(sx >= 0);
574 assert(sx+len <= gWinSizeX+4);
575 y0 := pan.Y-(vpy-1);
576 y1 := y0+pan.Height;
577 if (y0 < 0) then y0 := 0;
578 if (y1 > gWinSizeY+4) then y1 := gWinSizeY+4;
579 while (y0 < y1) do
580 begin
581 FillChar(edgeBmp[y0*(gWinSizeX+4)+sx], len*sizeof(edgeBmp[0]), 1);
582 Inc(y0);
583 end;
584 end
585 else
586 begin
587 drawRect(pan.X, pan.Y, pan.Width, pan.Height, r, g, b);
588 end;
589 end;
591 var
592 lsx: Integer = -1;
593 lex: Integer = -1;
594 lsy: Integer = -1;
596 procedure flushLine ();
597 begin
598 if (lsy > 0) and (lsx > 0) then
599 begin
600 if (lex = lsx) then
601 begin
602 glBegin(GL_POINTS);
603 glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
604 glEnd();
605 end
606 else
607 begin
608 glBegin(GL_LINES);
609 glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
610 glVertex2f(lex-0+vpx+0.37, lsy-1+vpy+0.37);
611 glEnd();
612 end;
613 end;
614 lsx := -1;
615 lex := -1;
616 end;
618 procedure startLine (y: Integer);
619 begin
620 flushLine();
621 lsy := y;
622 end;
624 procedure putPixel (x: Integer);
625 begin
626 if (x < 1) then exit;
627 if (lex+1 <> x) then flushLine();
628 if (lsx < 0) then lsx := x;
629 lex := x;
630 end;
632 procedure drawEdges ();
633 var
634 x, y: Integer;
635 a: PByte;
636 begin
637 glDisable(GL_BLEND);
638 glDisable(GL_TEXTURE_2D);
639 glLineWidth(1);
640 glPointSize(1);
641 glDisable(GL_LINE_SMOOTH);
642 glDisable(GL_POLYGON_SMOOTH);
643 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
644 for y := 1 to vph do
645 begin
646 a := @edgeBmp[y*(gWinSizeX+4)+1];
647 startLine(y);
648 for x := 1 to vpw do
649 begin
650 if (a[0] <> 0) then
651 begin
652 if (a[-1] = 0) or (a[1] = 0) or (a[-(gWinSizeX+4)] = 0) or (a[gWinSizeX+4] = 0) or
653 (a[-(gWinSizeX+4)-1] = 0) or (a[-(gWinSizeX+4)+1] = 0) or
654 (a[gWinSizeX+4-1] = 0) or (a[gWinSizeX+4+1] = 0) then
655 begin
656 putPixel(x);
657 end;
658 end;
659 Inc(a);
660 end;
661 flushLine();
662 end;
663 end;
665 procedure drawFilledWalls ();
666 var
667 x, y: Integer;
668 a: PByte;
669 begin
670 glDisable(GL_BLEND);
671 glDisable(GL_TEXTURE_2D);
672 glLineWidth(1);
673 glPointSize(1);
674 glDisable(GL_LINE_SMOOTH);
675 glDisable(GL_POLYGON_SMOOTH);
676 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
677 for y := 1 to vph do
678 begin
679 a := @edgeBmp[y*(gWinSizeX+4)+1];
680 startLine(y);
681 for x := 1 to vpw do
682 begin
683 if (a[0] <> 0) then putPixel(x);
684 Inc(a);
685 end;
686 flushLine();
687 end;
688 end;
690 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
691 var
692 f: Integer;
693 pan: TPanel;
694 begin
695 r := ar;
696 g := ag;
697 b := ab;
698 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
699 for f := 0 to High(parr) do
700 begin
701 pan := parr[f];
702 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
703 if ((pan.PanelType and ptype) = 0) then continue;
704 drawPanel(pan);
705 end;
706 if g_ol_nice then drawEdges();
707 if g_ol_fill_walls then drawFilledWalls();
708 end;
710 var
711 xptag: Word;
713 function doWallCB (pan: TPanel; tag: Integer): Boolean;
714 begin
715 result := false; // don't stop
716 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
717 if ((pan.PanelType and xptag) = 0) then exit;
718 drawPanel(pan);
719 end;
721 procedure doWalls (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
722 begin
723 r := ar;
724 g := ag;
725 b := ab;
726 xptag := ptype;
727 if ((ptype and (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR)) <> 0) then ptype := GridTagWall or GridTagDoor
728 else panelTypeToTag(ptype);
729 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
730 mapGrid.forEachInAABB(vpx-1, vpy-1, vpw+2, vph+2, doWallCB, ptype);
731 if g_ol_nice then drawEdges();
732 if g_ol_fill_walls then drawFilledWalls();
733 end;
735 begin
736 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
737 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
738 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
739 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
740 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
741 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
742 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
743 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
744 end;
746 {$ELSE}
747 var
748 oliner: TOutliner = nil;
750 procedure drawOutlines ();
751 var
752 r, g, b: Integer;
754 procedure clearOliner ();
755 begin
756 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
757 if (oliner = nil) then oliner := TOutliner.Create(vpw+2, vph+2) else oliner.setup(vpw+2, vph+2);
758 end;
760 procedure drawOutline (ol: TOutliner; sx, sy: Integer);
761 procedure xline (x0, x1, y: Integer);
762 var
763 x: Integer;
764 begin
765 if (g_dbg_scale < 1.0) then
766 begin
767 glBegin(GL_POINTS);
768 for x := x0 to x1 do glVertex2f(sx+x+0.375, sy+y+0.375);
769 glEnd();
770 end
771 else
772 begin
773 glBegin(GL_QUADS);
774 glVertex2f(sx+x0+0, sy+y+0);
775 glVertex2f(sx+x1+1, sy+y+0);
776 glVertex2f(sx+x1+1, sy+y+1);
777 glVertex2f(sx+x0+0, sy+y+1);
778 glEnd();
779 end;
780 end;
781 var
782 y: Integer;
783 sp: TOutliner.TSpanX;
784 begin
785 if (ol = nil) then exit;
786 glPointSize(1);
787 glDisable(GL_POINT_SMOOTH);
788 for y := 0 to ol.height-1 do
789 begin
790 for sp in ol.eachSpanAtY(y) do
791 begin
792 if (g_dbg_scale <= 1.0) then
793 begin
794 glBegin(GL_POINTS);
795 glVertex2f(sx+sp.x0+0.375, sy+y+0.375);
796 glVertex2f(sx+sp.x1+0.375, sy+y+0.375);
797 glEnd();
798 end
799 else
800 begin
801 glBegin(GL_QUADS);
802 glVertex2f(sx+sp.x0+0, sy+y+0);
803 glVertex2f(sx+sp.x0+1, sy+y+0);
804 glVertex2f(sx+sp.x0+1, sy+y+1);
805 glVertex2f(sx+sp.x0+0, sy+y+1);
807 glVertex2f(sx+sp.x1+0, sy+y+0);
808 glVertex2f(sx+sp.x1+1, sy+y+0);
809 glVertex2f(sx+sp.x1+1, sy+y+1);
810 glVertex2f(sx+sp.x1+0, sy+y+1);
811 glEnd();
812 end;
813 end;
814 for sp in ol.eachSpanEdgeAtY(y, -1) do
815 begin
816 xline(sp.x0, sp.x1, y);
818 glBegin(GL_QUADS);
819 glVertex2f(sx+sp.x0+0, sy+y+0);
820 glVertex2f(sx+sp.x1+1, sy+y+0);
821 glVertex2f(sx+sp.x1+1, sy+y+1);
822 glVertex2f(sx+sp.x0+0, sy+y+1);
823 glEnd();
825 end;
826 for sp in ol.eachSpanEdgeAtY(y, +1) do
827 begin
828 xline(sp.x0, sp.x1, y);
830 glBegin(GL_QUADS);
831 glVertex2f(sx+sp.x0+0, sy+y+0);
832 glVertex2f(sx+sp.x1+1, sy+y+0);
833 glVertex2f(sx+sp.x1+1, sy+y+1);
834 glVertex2f(sx+sp.x0+0, sy+y+1);
835 glEnd();
837 end;
838 end;
839 end;
841 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
842 var
843 f: Integer;
844 pan: TPanel;
845 begin
846 r := ar;
847 g := ag;
848 b := ab;
849 if g_ol_nice then clearOliner();
850 for f := 0 to High(parr) do
851 begin
852 pan := parr[f];
853 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
854 if ((pan.PanelType and ptype) = 0) then continue;
855 if (pan.X > vpx+vpw+41) or (pan.Y > vpy+vph+41) then continue;
856 if (pan.X+pan.Width < vpx-41) then continue;
857 if (pan.Y+pan.Height < vpy-41) then continue;
858 if g_ol_nice then
859 begin
860 oliner.addRect(pan.X-(vpx+1), pan.Y-(vpy+1), pan.Width, pan.Height);
861 end;
862 if g_ol_fill_walls then
863 begin
864 fillRect(pan.X, pan.Y, pan.Width, pan.Height, TGxRGBA.Create(r, g, b));
865 end
866 else if not g_ol_nice then
867 begin
868 drawRect(pan.X, pan.Y, pan.Width, pan.Height, TGxRGBA.Create(r, g, b));
869 end;
870 end;
871 if g_ol_nice then
872 begin
873 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
874 drawOutline(oliner, vpx+1, vpy+1);
875 end;
876 end;
878 begin
879 if (vpw < 2) or (vph < 2) then exit;
880 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
881 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
882 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
883 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
884 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
885 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
886 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
887 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
888 end;
889 {$ENDIF}
892 procedure plrDebugDraw ();
893 procedure drawTileGrid ();
894 var
895 x, y: Integer;
896 begin
897 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
898 begin
899 drawLine(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize, TGxRGBA.Create(96, 96, 96));
900 end;
902 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
903 begin
904 drawLine(mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0, mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0+y*mapGrid.gridHeight, TGxRGBA.Create(96, 96, 96));
905 end;
906 end;
908 procedure drawAwakeCells ();
909 var
910 x, y: Integer;
911 begin
912 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
913 begin
914 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
915 begin
916 if awmIsSetHolmes(x*mapGrid.tileSize+mapGrid.gridX0+1, y*mapGrid.tileSize++mapGrid.gridY0+1) then
917 begin
918 fillRect(x*mapGrid.tileSize++mapGrid.gridX0, y*mapGrid.tileSize++mapGrid.gridY0, monsGrid.tileSize, monsGrid.tileSize, TGxRGBA.Create(128, 0, 128, 64));
919 end;
920 end;
921 end;
922 end;
924 procedure drawTraceBox ();
925 var
926 plr: TPlayer;
927 px, py, pw, ph: Integer;
928 pdx, pdy: Integer;
929 ex, ey: Integer;
930 pan: TPanel;
931 begin
932 if (Length(gPlayers) < 1) then exit;
933 plr := gPlayers[0];
934 if (plr = nil) then exit;
935 plr.getMapBox(px, py, pw, ph);
936 drawRect(px, py, pw, ph, TGxRGBA.Create(255, 0, 255, 200));
937 pdx := pmsCurMapX-(px+pw div 2);
938 pdy := pmsCurMapY-(py+ph div 2);
939 drawLine(px+pw div 2, py+ph div 2, px+pw div 2+pdx, py+ph div 2+pdy, TGxRGBA.Create(255, 0, 255, 200));
940 pan := mapGrid.traceBox(ex, ey, px, py, pw, ph, pdx, pdy, nil, GridTagObstacle);
941 if (pan = nil) then
942 begin
943 drawRect(px+pdx, py+pdy, pw, ph, TGxRGBA.Create(255, 255, 255, 180));
944 end
945 else
946 begin
947 drawRect(px+pdx, py+pdy, pw, ph, TGxRGBA.Create(255, 255, 0, 180));
948 end;
949 drawRect(ex, ey, pw, ph, TGxRGBA.Create(255, 127, 0, 180));
950 end;
952 procedure hilightCell (cx, cy: Integer);
953 begin
954 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, TGxRGBA.Create(0, 128, 0, 64));
955 end;
957 procedure hilightCell1 (cx, cy: Integer);
958 begin
959 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
960 cx := cx and (not (monsGrid.tileSize-1));
961 cy := cy and (not (monsGrid.tileSize-1));
962 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, TGxRGBA.Create(255, 255, 0, 92));
963 end;
965 function hilightWallTrc (pan: TPanel; tag: Integer; x, y, prevx, prevy: Integer): Boolean;
966 begin
967 result := false; // don't stop
968 if (pan = nil) then exit; // cell completion, ignore
969 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
970 fillRect(pan.X, pan.Y, pan.Width, pan.Height, TGxRGBA.Create(0, 128, 128, 64));
971 end;
973 function monsCollector (mon: TMonster; tag: Integer): Boolean;
974 var
975 ex, ey: Integer;
976 mx, my, mw, mh: Integer;
977 begin
978 result := false;
979 mon.getMapBox(mx, my, mw, mh);
980 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
981 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
982 begin
983 e_DrawPoint(8, ex, ey, 0, 255, 0);
984 end;
985 end;
987 procedure drawMonsterInfo (mon: TMonster);
988 var
989 mx, my, mw, mh: Integer;
991 procedure drawMonsterTargetLine ();
992 var
993 emx, emy, emw, emh: Integer;
994 enemy: TMonster;
995 eplr: TPlayer;
996 ex, ey: Integer;
997 begin
998 if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
999 begin
1000 eplr := g_Player_Get(mon.MonsterTargetUID);
1001 if (eplr <> nil) then eplr.getMapBox(emx, emy, emw, emh) else exit;
1002 end
1003 else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then
1004 begin
1005 enemy := g_Monsters_ByUID(mon.MonsterTargetUID);
1006 if (enemy <> nil) then enemy.getMapBox(emx, emy, emw, emh) else exit;
1007 end
1008 else
1009 begin
1010 exit;
1011 end;
1012 mon.getMapBox(mx, my, mw, mh);
1013 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, TGxRGBA.Create(255, 0, 0));
1014 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
1015 begin
1016 drawLine(mx+mw div 2, my+mh div 2, ex, ey, TGxRGBA.Create(0, 255, 0));
1017 end;
1018 end;
1020 procedure drawLOS2Plr ();
1021 var
1022 emx, emy, emw, emh: Integer;
1023 eplr: TPlayer;
1024 ex, ey: Integer;
1025 begin
1026 eplr := gPlayers[0];
1027 if (eplr = nil) then exit;
1028 eplr.getMapBox(emx, emy, emw, emh);
1029 mon.getMapBox(mx, my, mw, mh);
1030 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, TGxRGBA.Create(255, 0, 0));
1031 {$IF DEFINED(D2F_DEBUG)}
1032 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1033 {$ENDIF}
1034 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
1035 //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
1036 begin
1037 drawLine(mx+mw div 2, my+mh div 2, ex, ey, TGxRGBA.Create(0, 255, 0));
1038 end;
1039 {$IF DEFINED(D2F_DEBUG)}
1040 mapGrid.dbgRayTraceTileHitCB := nil;
1041 {$ENDIF}
1042 end;
1044 begin
1045 if (mon = nil) then exit;
1046 mon.getMapBox(mx, my, mw, mh);
1047 //mx += mw div 2;
1049 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1051 if showMonsInfo then
1052 begin
1053 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1054 darkenRect(mx-4, my-7*8-6, 110, 7*8+6, 128);
1055 my -= 8;
1056 my -= 2;
1058 // type
1059 drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1060 // beh
1061 drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1062 // state
1063 drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1064 // health
1065 drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1066 // ammo
1067 drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1068 // target
1069 drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1070 drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1071 end;
1073 drawMonsterTargetLine();
1074 if showMonsLOS2Plr then drawLOS2Plr();
1076 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1077 property MonsterPain: Integer read FPain write FPain;
1078 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1080 end;
1082 function highlightAllMonsterCells (mon: TMonster): Boolean;
1083 begin
1084 result := false; // don't stop
1085 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1086 end;
1088 procedure drawSelectedPlatformCells ();
1089 var
1090 pan: TPanel;
1091 begin
1092 if not showGrid then exit;
1093 pan := g_Map_PanelByGUID(platMarkedGUID);
1094 if (pan = nil) then exit;
1095 mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
1096 drawRect(pan.x, pan.y, pan.width, pan.height, TGxRGBA.Create(0, 200, 0, 200));
1097 end;
1099 procedure drawTrigger (var trig: TTrigger);
1101 procedure drawPanelDest (pguid: Integer);
1102 var
1103 pan: TPanel;
1104 begin
1105 pan := g_Map_PanelByGUID(pguid);
1106 if (pan = nil) then exit;
1107 drawLine(
1108 trig.trigCenter.x, trig.trigCenter.y,
1109 pan.x+pan.width div 2, pan.y+pan.height div 2,
1110 TGxRGBA.Create(255, 0, 255, 220));
1111 end;
1113 var
1114 tts: AnsiString;
1115 tx: Integer;
1116 begin
1117 fillRect(trig.x, trig.y, trig.width, trig.height, TGxRGBA.Create(255, 0, 255, 96));
1118 tts := trigType2Str(trig.TriggerType);
1119 tx := trig.x+(trig.width-Length(tts)*6) div 2;
1120 darkenRect(tx-2, trig.y-10, Length(tts)*6+4, 10, 64);
1121 drawText6(tx, trig.y-9, tts, TGxRGBA.Create(255, 127, 0));
1122 tx := trig.x+(trig.width-Length(trig.mapId)*6) div 2;
1123 darkenRect(tx-2, trig.y-20, Length(trig.mapId)*6+4, 10, 64);
1124 drawText6(tx, trig.y-19, trig.mapId, TGxRGBA.Create(255, 255, 0));
1125 drawPanelDest(trig.trigPanelGUID);
1126 case trig.TriggerType of
1127 TRIGGER_NONE: begin end;
1128 TRIGGER_EXIT: begin end;
1129 TRIGGER_TELEPORT: begin end;
1130 TRIGGER_OPENDOOR: begin end;
1131 TRIGGER_CLOSEDOOR: begin end;
1132 TRIGGER_DOOR: begin end;
1133 TRIGGER_DOOR5: begin end;
1134 TRIGGER_CLOSETRAP: begin end;
1135 TRIGGER_TRAP: begin end;
1136 TRIGGER_SECRET: begin end;
1137 TRIGGER_LIFTUP: begin end;
1138 TRIGGER_LIFTDOWN: begin end;
1139 TRIGGER_LIFT: begin end;
1140 TRIGGER_TEXTURE: begin end;
1141 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF, TRIGGER_PRESS:
1142 begin
1143 if (trig.trigDataRec.trigTWidth > 0) and (trig.trigDataRec.trigTHeight > 0) then
1144 begin
1145 fillRect(
1146 trig.trigDataRec.trigTX, trig.trigDataRec.trigTY,
1147 trig.trigDataRec.trigTWidth, trig.trigDataRec.trigTHeight,
1148 TGxRGBA.Create(0, 255, 255, 42));
1149 drawLine(
1150 trig.trigCenter.x, trig.trigCenter.y,
1151 trig.trigDataRec.trigTX+trig.trigDataRec.trigTWidth div 2,
1152 trig.trigDataRec.trigTY+trig.trigDataRec.trigTHeight div 2,
1153 TGxRGBA.Create(255, 0, 255, 220));
1154 end;
1155 end;
1156 TRIGGER_SOUND: begin end;
1157 TRIGGER_SPAWNMONSTER: begin end;
1158 TRIGGER_SPAWNITEM: begin end;
1159 TRIGGER_MUSIC: begin end;
1160 TRIGGER_PUSH: begin end;
1161 TRIGGER_SCORE: begin end;
1162 TRIGGER_MESSAGE: begin end;
1163 TRIGGER_DAMAGE: begin end;
1164 TRIGGER_HEALTH: begin end;
1165 TRIGGER_SHOT: begin end;
1166 TRIGGER_EFFECT: begin end;
1167 TRIGGER_SCRIPT: begin end;
1168 end;
1169 //trigType2Str
1170 //trigPanelId: Integer;
1171 end;
1173 procedure drawTriggers ();
1174 var
1175 f: Integer;
1176 begin
1177 for f := 0 to High(gTriggers) do drawTrigger(gTriggers[f]);
1178 end;
1180 procedure drawGibsBoxes ();
1181 var
1182 f: Integer;
1183 px, py, pw, ph: Integer;
1184 gib: PGib;
1185 begin
1186 for f := 0 to High(gGibs) do
1187 begin
1188 gib := @gGibs[f];
1189 if gib.alive then
1190 begin
1191 gib.getMapBox(px, py, pw, ph);
1192 drawRect(px, py, pw, ph, TGxRGBA.Create(255, 0, 255));
1193 end;
1194 end;
1195 end;
1197 var
1198 scisave: TScissorSave;
1199 mon: TMonster;
1200 mx, my, mw, mh: Integer;
1201 //pan: TPanel;
1202 //ex, ey: Integer;
1203 begin
1204 if (gPlayer1 = nil) then exit;
1206 scisave.save(true); // enable scissoring
1207 glPushMatrix();
1208 try
1209 //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
1210 glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1212 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
1213 glTranslatef(-vpx, -vpy, 0);
1215 if (showGrid) then drawTileGrid();
1216 drawOutlines();
1218 if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
1220 if (monMarkedUID <> -1) then
1221 begin
1222 mon := g_Monsters_ByUID(monMarkedUID);
1223 if (mon <> nil) then
1224 begin
1225 mon.getMapBox(mx, my, mw, mh);
1226 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
1227 drawMonsterInfo(mon);
1228 end;
1229 end;
1231 if showAllMonsCells and showGrid then g_Mons_ForEach(highlightAllMonsterCells);
1232 if showTriggers then drawTriggers();
1233 if showGrid then drawSelectedPlatformCells();
1235 //drawAwakeCells();
1237 if showTraceBox then drawTraceBox();
1239 //drawGibsBoxes();
1242 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1243 (*
1244 {$IF DEFINED(D2F_DEBUG)}
1245 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1246 {$ENDIF}
1247 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1248 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1249 {$IF DEFINED(D2F_DEBUG)}
1250 mapGrid.dbgRayTraceTileHitCB := nil;
1251 {$ENDIF}
1253 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1254 if (pan <> nil) then writeln('hit!');
1255 *)
1257 finally
1258 glPopMatrix();
1259 scisave.restore();
1260 end;
1262 if showMapCurPos then drawText8(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]), TGxRGBA.Create(255, 255, 0));
1263 end;
1266 // ////////////////////////////////////////////////////////////////////////// //
1267 procedure g_Holmes_MouseEvent (var ev: THMouseEvent);
1268 var
1269 he: THMouseEvent;
1270 begin
1271 if g_Game_IsNet then exit;
1272 if not g_holmes_enabled then exit;
1274 holmesInitCommands();
1275 holmesInitBinds();
1276 msX := ev.x;
1277 msY := ev.y;
1278 msB := ev.bstate;
1279 kbS := ev.kstate;
1280 msB := msB;
1281 he := ev;
1282 he.x := he.x;
1283 he.y := he.y;
1284 uiMouseEvent(he);
1285 if (not he.eaten) then plrDebugMouse(he);
1286 ev.eat();
1287 end;
1290 // ////////////////////////////////////////////////////////////////////////// //
1291 procedure g_Holmes_KeyEvent (var ev: THKeyEvent);
1292 var
1293 doeat: Boolean = false;
1294 {$IF DEFINED(D2F_DEBUG)}
1295 pan: TPanel;
1296 ex, ey: Integer;
1297 dx, dy: Integer;
1298 {$ENDIF}
1300 procedure dummyWallTrc (cx, cy: Integer);
1301 begin
1302 end;
1304 begin
1305 if g_Game_IsNet then exit;
1306 if not g_holmes_enabled then exit;
1308 holmesInitCommands();
1309 holmesInitBinds();
1311 msB := ev.bstate;
1312 kbS := ev.kstate;
1313 case ev.scan of
1314 SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL,
1315 SDL_SCANCODE_LALT, SDL_SCANCODE_RALT,
1316 SDL_SCANCODE_LSHIFT, SDL_SCANCODE_RSHIFT:
1317 doeat := true;
1318 end;
1320 uiKeyEvent(ev);
1321 if (ev.eaten) then exit;
1322 if keybindExecute(ev) then begin ev.eat(); exit; end;
1323 // press
1324 if (ev.press) then
1325 begin
1326 {$IF DEFINED(D2F_DEBUG)}
1327 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1328 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
1329 ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
1330 begin
1331 ev.eat();
1332 dx := pmsCurMapX;
1333 dy := pmsCurMapY;
1334 case ev.scan of
1335 SDL_SCANCODE_UP: dy -= 120;
1336 SDL_SCANCODE_DOWN: dy += 120;
1337 SDL_SCANCODE_LEFT: dx -= 120;
1338 SDL_SCANCODE_RIGHT: dx += 120;
1339 end;
1340 {$IF DEFINED(D2F_DEBUG)}
1341 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1342 mapGrid.dbgShowTraceLog := true;
1343 {$ENDIF}
1344 pan := g_Map_traceToNearest(pmsCurMapX, pmsCurMapY, dx, dy, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
1345 {$IF DEFINED(D2F_DEBUG)}
1346 //mapGrid.dbgRayTraceTileHitCB := nil;
1347 mapGrid.dbgShowTraceLog := false;
1348 {$ENDIF}
1349 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, dx, dy, ex, ey, (pan <> nil)]);
1350 exit;
1351 end;
1352 {$ENDIF}
1353 end;
1354 if (doeat) then ev.eat();
1355 end;
1358 // ////////////////////////////////////////////////////////////////////////// //
1359 procedure g_Holmes_Draw ();
1360 begin
1361 if g_Game_IsNet then exit;
1363 {$IF not DEFINED(HEADLESS)}
1364 holmesInitCommands();
1365 holmesInitBinds();
1367 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
1368 glDisable(GL_STENCIL_TEST);
1369 glDisable(GL_BLEND);
1370 glDisable(GL_SCISSOR_TEST);
1371 glDisable(GL_TEXTURE_2D);
1373 if gGameOn then plrDebugDraw();
1374 {$ENDIF}
1376 laserSet := false;
1377 end;
1380 procedure g_Holmes_DrawUI ();
1381 begin
1382 if g_Game_IsNet then exit;
1383 if not g_holmes_enabled then exit;
1384 {$IF not DEFINED(HEADLESS)}
1385 gGfxDoClear := false;
1386 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1387 uiDraw();
1388 glMatrixMode(GL_MODELVIEW);
1389 glPushMatrix();
1390 try
1391 //glLoadIdentity();
1392 if assigned(postrenderFrameCB) then postrenderFrameCB();
1393 finally
1394 glPopMatrix();
1395 end;
1396 {$ENDIF}
1397 end;
1400 // ////////////////////////////////////////////////////////////////////////// //
1401 procedure bcOneMonsterThinkStep (); begin gmon_debug_think := false; gmon_debug_one_think_step := true; end;
1402 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active := false; g_dbgpan_mplat_step := true; end;
1403 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active := not g_dbgpan_mplat_active; end;
1405 procedure bcToggleMonsterInfo (arg: Integer=-1); begin if (arg < 0) then showMonsInfo := not showMonsInfo else showMonsInfo := (arg > 0); end;
1406 procedure bcToggleMonsterLOSPlr (arg: Integer=-1); begin if (arg < 0) then showMonsLOS2Plr := not showMonsLOS2Plr else showMonsLOS2Plr := (arg > 0); end;
1407 procedure bcToggleMonsterCells (arg: Integer=-1); begin if (arg < 0) then showAllMonsCells := not showAllMonsCells else showAllMonsCells := (arg > 0); end;
1408 procedure bcToggleDrawTriggers (arg: Integer=-1); begin if (arg < 0) then showTriggers := not showTriggers else showTriggers := (arg > 0); end;
1410 procedure bcToggleCurPos (arg: Integer=-1); begin if (arg < 0) then showMapCurPos := not showMapCurPos else showMapCurPos := (arg > 0); end;
1411 procedure bcToggleGrid (arg: Integer=-1); begin if (arg < 0) then showGrid := not showGrid else showGrid := (arg > 0); end;
1413 procedure bcMonsterSpawn (s: AnsiString);
1414 var
1415 mon: TMonster;
1416 begin
1417 if not gGameOn or g_Game_IsClient then
1418 begin
1419 conwriteln('cannot spawn monster in this mode');
1420 exit;
1421 end;
1422 mon := g_Mons_SpawnAt(s, pmsCurMapX, pmsCurMapY);
1423 if (mon = nil) then begin conwritefln('unknown monster id: ''%s''', [s]); exit; end;
1424 monMarkedUID := mon.UID;
1425 end;
1427 procedure bcMonsterWakeup ();
1428 var
1429 mon: TMonster;
1430 begin
1431 if (monMarkedUID <> -1) then
1432 begin
1433 mon := g_Monsters_ByUID(monMarkedUID);
1434 if (mon <> nil) then mon.WakeUp();
1435 end;
1436 end;
1438 procedure bcPlayerTeleport ();
1439 var
1440 x, y, w, h: Integer;
1441 begin
1442 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1443 if (gPlayers[0] <> nil) then
1444 begin
1445 gPlayers[0].getMapBox(x, y, w, h);
1446 gPlayers[0].TeleportTo(pmsCurMapX-w div 2, pmsCurMapY-h div 2, true, 69); // 69: don't change dir
1447 end;
1448 end;
1450 procedure dbgToggleTraceBox (arg: Integer=-1); begin if (arg < 0) then showTraceBox := not showTraceBox else showTraceBox := (arg > 0); end;
1452 procedure dbgToggleHolmesPause (arg: Integer=-1); begin if (arg < 0) then g_Game_HolmesPause(not gPauseHolmes) else g_Game_HolmesPause(arg > 0); end;
1454 procedure cbAtcurSelectMonster ();
1455 function monsAtDump (mon: TMonster; tag: Integer): Boolean;
1456 begin
1457 result := true; // stop
1458 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), TMsgType.Notify);
1459 monMarkedUID := mon.UID;
1460 dumpPublishedProperties(mon);
1461 end;
1462 var
1463 plr: TPlayer;
1464 x, y, w, h: Integer;
1465 begin
1466 monMarkedUID := -1;
1467 if (Length(gPlayers) > 0) then
1468 begin
1469 plr := gPlayers[0];
1470 if (plr <> nil) then
1471 begin
1472 plr.getMapBox(x, y, w, h);
1473 if (pmsCurMapX >= x) and (pmsCurMapY >= y) and (pmsCurMapX < x+w) and (pmsCurMapY < y+h) then
1474 begin
1475 dumpPublishedProperties(plr);
1476 end;
1477 end;
1478 end;
1479 //e_WriteLog('===========================', MSG_NOTIFY);
1480 monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
1481 //e_WriteLog('---------------------------', MSG_NOTIFY);
1482 end;
1484 procedure cbAtcurDumpMonsters ();
1485 function monsAtDump (mon: TMonster; tag: Integer): Boolean;
1486 begin
1487 result := false; // don't stop
1488 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), TMsgType.Notify);
1489 end;
1490 begin
1491 e_WriteLog('===========================', TMsgType.Notify);
1492 monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
1493 e_WriteLog('---------------------------', TMsgType.Notify);
1494 end;
1496 procedure cbAtcurDumpWalls ();
1497 function wallToggle (pan: TPanel; tag: Integer): Boolean;
1498 begin
1499 result := false; // don't stop
1500 if (platMarkedGUID = -1) then platMarkedGUID := pan.guid;
1501 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]);
1502 dumpPublishedProperties(pan);
1503 end;
1504 var
1505 hasTrigs: Boolean = false;
1506 f: Integer;
1507 trig: PTrigger;
1508 begin
1509 platMarkedGUID := -1;
1510 e_WriteLog('=== TOGGLE WALL ===', TMsgType.Notify);
1511 mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
1512 e_WriteLog('--- toggle wall ---', TMsgType.Notify);
1513 if showTriggers then
1514 begin
1515 for f := 0 to High(gTriggers) do
1516 begin
1517 trig := @gTriggers[f];
1518 if (pmsCurMapX >= trig.x) and (pmsCurMapY >= trig.y) and (pmsCurMapX < trig.x+trig.width) and (pmsCurMapY < trig.y+trig.height) then
1519 begin
1520 if not hasTrigs then begin writeln('=== TRIGGERS ==='); hasTrigs := true; end;
1521 writeln('trigger ''', trig.mapId, ''' of type ''', trigType2Str(trig.TriggerType), '''');
1522 end;
1523 end;
1524 if hasTrigs then writeln('--- triggers ---');
1525 end;
1526 end;
1528 procedure cbAtcurToggleWalls ();
1529 function wallToggle (pan: TPanel; tag: Integer): Boolean;
1530 begin
1531 result := false; // don't stop
1532 //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);
1533 if pan.Enabled then g_Map_DisableWallGUID(pan.guid) else g_Map_EnableWallGUID(pan.guid);
1534 end;
1535 begin
1536 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1537 mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
1538 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1539 end;
1542 // ////////////////////////////////////////////////////////////////////////// //
1543 procedure holmesInitCommands ();
1544 begin
1545 if (cmdlist <> nil) then exit;
1546 cmdAdd('win_layers', toggleLayersWindow, 'toggle layers window', 'window control');
1547 cmdAdd('win_outline', toggleOutlineWindow, 'toggle outline window', 'window control');
1548 cmdAdd('win_help', toggleHelpWindow, 'toggle help window', 'window control');
1549 cmdAdd('win_options', toggleOptionsWindow, 'toggle options window', 'window control');
1551 cmdAdd('mon_think_step', bcOneMonsterThinkStep, 'one monster think step', 'monster control');
1552 cmdAdd('mon_info', bcToggleMonsterInfo, 'toggle monster info', 'monster control');
1553 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr, 'toggle monster LOS to player', 'monster control');
1554 cmdAdd('mon_cells', bcToggleMonsterCells, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1555 cmdAdd('mon_wakeup', bcMonsterWakeup, 'wake up selected monster', 'monster control');
1557 cmdAdd('mon_spawn', bcMonsterSpawn, 'spawn monster', 'monster control');
1559 cmdAdd('mplat_step', bcOneMPlatThinkStep, 'one mplat think step', 'mplat control');
1560 cmdAdd('mplat_toggle', bcMPlatToggle, 'activate/deactivate moving platforms', 'mplat control');
1562 cmdAdd('plr_teleport', bcPlayerTeleport, 'teleport player', 'player control');
1564 cmdAdd('dbg_curpos', bcToggleCurPos, 'toggle "show cursor position on the map"', 'various');
1565 cmdAdd('dbg_grid', bcToggleGrid, 'toggle grid', 'various');
1566 cmdAdd('dbg_triggers', bcToggleDrawTriggers, 'show/hide triggers (SLOW!)', 'various');
1568 cmdAdd('atcur_select_monster', cbAtcurSelectMonster, 'select monster to operate', 'monster control');
1569 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters, 'dump monsters in cell', 'monster control');
1570 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls, 'dump walls in cell', 'wall control');
1571 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls, 'disable walls', 'wall control');
1573 cmdAdd('dbg_tracebox', dbgToggleTraceBox, 'test traceBox()', 'player control');
1575 cmdAdd('hlm_pause', dbgToggleHolmesPause, '"Holmes" pause mode', 'game control');
1576 end;
1579 procedure holmesInitBinds ();
1580 var
1581 st: TStream = nil;
1582 pr: TTextParser = nil;
1583 s, kn, v: AnsiString;
1584 kmods: Byte;
1585 mbuts: Byte;
1586 begin
1587 kbS := kbS;
1588 if not keybindsInited then
1589 begin
1590 // keyboard
1591 keybindAdd('F1', 'win_help');
1592 keybindAdd('M-F1', 'win_options');
1593 keybindAdd('C-O', 'win_outline');
1594 keybindAdd('C-L', 'win_layers');
1596 keybindAdd('M-M', 'mon_think_step');
1597 keybindAdd('M-I', 'mon_info');
1598 keybindAdd('M-L', 'mon_los_plr');
1599 keybindAdd('M-G', 'mon_cells');
1600 keybindAdd('M-A', 'mon_wakeup');
1602 keybindAdd('M-P', 'mplat_step');
1603 keybindAdd('M-O', 'mplat_toggle');
1605 keybindAdd('C-T', 'plr_teleport');
1606 keybindAdd('M-T', 'dbg_tracebox');
1608 keybindAdd('C-P', 'dbg_curpos');
1609 keybindAdd('C-G', 'dbg_grid');
1610 keybindAdd('C-X', 'dbg_triggers');
1612 keybindAdd('C-1', 'mon_spawn zombie');
1614 keybindAdd('C-S-P', 'hlm_pause');
1616 // mouse
1617 msbindAdd('LMB', 'atcur_select_monster');
1618 msbindAdd('M-LMB', 'atcur_dump_monsters');
1619 msbindAdd('RMB', 'atcur_dump_walls');
1620 msbindAdd('M-RMB', 'atcur_disable_walls');
1622 // load bindings from file
1623 try
1624 st := openDiskFileRO(GameDir+'holmes.rc');
1625 pr := TFileTextParser.Create(st);
1626 conwriteln('parsing "holmes.rc"...');
1627 while (pr.tokType <> pr.TTEOF) do
1628 begin
1629 s := pr.expectId();
1630 if (s = 'stop') then break
1631 else if (s = 'unbind_keys') then keybinds := nil
1632 else if (s = 'unbind_mouse') then msbinds := nil
1633 else if (s = 'bind') then
1634 begin
1635 if (pr.tokType = pr.TTStr) then s := pr.expectStr(false)
1636 else if (pr.tokType = pr.TTInt) then s := Format('%d', [pr.expectInt()])
1637 else s := pr.expectId();
1639 if (pr.tokType = pr.TTStr) then v := pr.expectStr(false)
1640 else if (pr.tokType = pr.TTInt) then v := Format('%d', [pr.expectInt()])
1641 else v := pr.expectId();
1643 kn := parseModKeys(s, kmods, mbuts);
1644 if (CompareText(kn, 'lmb') = 0) or (CompareText(kn, 'rmb') = 0) or (CompareText(kn, 'mmb') = 0) or (CompareText(kn, 'None') = 0) then
1645 begin
1646 msbindAdd(s, v);
1647 end
1648 else
1649 begin
1650 keybindAdd(s, v);
1651 end;
1652 end;
1653 end;
1654 except on e: Exception do // sorry
1655 if (pr <> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr.tokLine, pr.tokCol, e.message]);
1656 end;
1657 if (pr <> nil) then pr.Free() else st.Free(); // ownership
1658 end;
1659 end;
1662 procedure onMouseEvent (var ev: THMouseEvent);
1663 begin
1664 if not g_holmes_enabled then exit;
1665 g_Holmes_MouseEvent(ev);
1666 end;
1668 procedure onKeyEvent (var ev: THKeyEvent);
1669 begin
1670 if not g_holmes_enabled then exit;
1671 g_Holmes_KeyEvent(ev);
1672 end;
1675 begin
1676 evMouseCB := onMouseEvent;
1677 evKeyCB := onKeyEvent;
1679 conRegVar('hlm_ui_scale', @gh_ui_scale, 0.01, 5.0, 'Holmes UI scale', '', false);
1680 end.