DEADSOFTWARE

Holmes: UI cosmetix
[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 winHelp.flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale), trunc(getScrHgt/gh_ui_scale));
330 uiLayoutCtl(winHelp);
331 winHelp.centerInScreen();
332 end;
335 procedure winLayersClosed (me: TUIControl); begin showLayersWindow := false; end;
336 procedure winOutlinesClosed (me: TUIControl); begin showOutlineWindow := false; end;
338 procedure addCheckBox (parent: TUIControl; const text: AnsiString; pvar: PBoolean);
339 var
340 cb: TUICheckBox;
341 begin
342 cb := TUICheckBox.Create();
343 cb.flExpand := true;
344 cb.setVar(pvar);
345 cb.text := text;
346 parent.appendChild(cb);
347 end;
349 procedure addButton (parent: TUIControl; const text: AnsiString; cb: TUIControl.TActionCB);
350 var
351 but: TUIButton;
352 begin
353 but := TUIButton.Create();
354 //but.flExpand := true;
355 but.actionCB := cb;
356 but.text := text;
357 parent.appendChild(but);
358 end;
361 procedure createLayersWindow ();
362 var
363 box: TUIVBox;
364 begin
365 winLayers := TUITopWindow.Create('layers');
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 winLayers.flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale), trunc(getScrHgt/gh_ui_scale));
384 uiLayoutCtl(winLayers);
385 end;
388 procedure createOutlinesWindow ();
389 var
390 box: TUIVBox;
391 begin
392 winOutlines := TUITopWindow.Create('outlines');
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 winOutlines.flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale), trunc(getScrHgt/gh_ui_scale));
420 uiLayoutCtl(winOutlines);
421 end;
424 procedure createOptionsWindow ();
425 var
426 box: TUIBox;
427 span: TUISpan;
428 begin
429 winOptions := TUITopWindow.Create('Holmes Options');
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 winOptions.flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale), trunc(getScrHgt/gh_ui_scale));
458 uiLayoutCtl(winOptions);
459 winOptions.centerInScreen();
460 end;
463 procedure toggleLayersWindow (arg: Integer=-1);
464 begin
465 if (arg < 0) then showLayersWindow := not showLayersWindow else showLayersWindow := (arg > 0);
466 showLayersWindow := not showLayersWindow; // hack for callback
467 toggleLayersWindowCB(nil);
468 end;
470 procedure toggleOutlineWindow (arg: Integer=-1);
471 begin
472 if (arg < 0) then showOutlineWindow := not showOutlineWindow else showOutlineWindow := (arg > 0);
473 showOutlineWindow := not showOutlineWindow; // hack for callback
474 toggleOutlineWindowCB(nil);
475 end;
477 procedure toggleHelpWindow (arg: Integer=-1);
478 begin
479 if (winHelp = nil) then createHelpWindow();
480 if (arg < 0) then begin if not uiVisibleWindow(winHelp) then uiAddWindow(winHelp) else uiRemoveWindow(winHelp); end
481 else if (arg = 0) then begin if uiVisibleWindow(winHelp) then uiRemoveWindow(winHelp); end
482 else begin if not uiVisibleWindow(winHelp) then uiAddWindow(winHelp); end
483 end;
485 procedure toggleOptionsWindow (arg: Integer=-1);
486 begin
487 if (winOptions = nil) then createOptionsWindow();
488 if (arg < 0) then begin if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions) else uiRemoveWindow(winOptions); end
489 else if (arg = 0) then begin if uiVisibleWindow(winOptions) then uiRemoveWindow(winOptions); end
490 else begin if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions); end
491 end;
494 // ////////////////////////////////////////////////////////////////////////// //
495 var
496 vpSet: Boolean = false;
497 vpx, vpy: Integer;
498 vpw, vph: Integer;
499 laserSet: Boolean = false;
500 laserX0, laserY0, laserX1, laserY1: Integer;
501 monMarkedUID: Integer = -1;
502 platMarkedGUID: Integer = -1;
505 procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer);
506 begin
507 vpSet := true;
508 vpx := viewPortX;
509 vpy := viewPortY;
510 end;
512 procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer);
513 begin
514 vpSet := true;
515 vpw := viewPortW;
516 vph := viewPortH;
517 end;
519 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
520 begin
521 laserSet := true;
522 laserX0 := ax0;
523 laserY0 := ay0;
524 laserX1 := ax1;
525 laserY1 := ay1;
526 laserSet := laserSet; // shut up, fpc!
527 end;
530 function pmsCurMapX (): Integer; inline; begin result := round(msX/g_dbg_scale)+vpx; end;
531 function pmsCurMapY (): Integer; inline; begin result := round(msY/g_dbg_scale)+vpy; end;
534 procedure plrDebugMouse (var ev: THMouseEvent);
535 begin
536 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
537 if (gPlayer1 = nil) or not vpSet then exit;
538 //if (ev.kind <> THMouseEvent.Press) then exit;
539 //e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
540 msbindExecute(ev);
541 end;
544 {$IFDEF HOLMES_OLD_OUTLINES}
545 var
546 edgeBmp: array of Byte = nil;
549 procedure drawOutlines ();
550 var
551 r, g, b: Integer;
553 procedure clearEdgeBmp ();
554 begin
555 SetLength(edgeBmp, (gWinSizeX+4)*(gWinSizeY+4));
556 FillChar(edgeBmp[0], Length(edgeBmp)*sizeof(edgeBmp[0]), 0);
557 end;
559 procedure drawPanel (pan: TPanel);
560 var
561 sx, len, y0, y1: Integer;
562 begin
563 if (pan = nil) or (pan.Width < 1) or (pan.Height < 1) then exit;
564 if (pan.X+pan.Width <= vpx-1) or (pan.Y+pan.Height <= vpy-1) then exit;
565 if (pan.X >= vpx+vpw+1) or (pan.Y >= vpy+vph+1) then exit;
566 if g_ol_nice or g_ol_fill_walls then
567 begin
568 sx := pan.X-(vpx-1);
569 len := pan.Width;
570 if (len > gWinSizeX+4) then len := gWinSizeX+4;
571 if (sx < 0) then begin len += sx; sx := 0; end;
572 if (sx+len > gWinSizeX+4) then len := gWinSizeX+4-sx;
573 if (len < 1) then exit;
574 assert(sx >= 0);
575 assert(sx+len <= gWinSizeX+4);
576 y0 := pan.Y-(vpy-1);
577 y1 := y0+pan.Height;
578 if (y0 < 0) then y0 := 0;
579 if (y1 > gWinSizeY+4) then y1 := gWinSizeY+4;
580 while (y0 < y1) do
581 begin
582 FillChar(edgeBmp[y0*(gWinSizeX+4)+sx], len*sizeof(edgeBmp[0]), 1);
583 Inc(y0);
584 end;
585 end
586 else
587 begin
588 drawRect(pan.X, pan.Y, pan.Width, pan.Height, r, g, b);
589 end;
590 end;
592 var
593 lsx: Integer = -1;
594 lex: Integer = -1;
595 lsy: Integer = -1;
597 procedure flushLine ();
598 begin
599 if (lsy > 0) and (lsx > 0) then
600 begin
601 if (lex = lsx) then
602 begin
603 glBegin(GL_POINTS);
604 glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
605 glEnd();
606 end
607 else
608 begin
609 glBegin(GL_LINES);
610 glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
611 glVertex2f(lex-0+vpx+0.37, lsy-1+vpy+0.37);
612 glEnd();
613 end;
614 end;
615 lsx := -1;
616 lex := -1;
617 end;
619 procedure startLine (y: Integer);
620 begin
621 flushLine();
622 lsy := y;
623 end;
625 procedure putPixel (x: Integer);
626 begin
627 if (x < 1) then exit;
628 if (lex+1 <> x) then flushLine();
629 if (lsx < 0) then lsx := x;
630 lex := x;
631 end;
633 procedure drawEdges ();
634 var
635 x, y: Integer;
636 a: PByte;
637 begin
638 glDisable(GL_BLEND);
639 glDisable(GL_TEXTURE_2D);
640 glLineWidth(1);
641 glPointSize(1);
642 glDisable(GL_LINE_SMOOTH);
643 glDisable(GL_POLYGON_SMOOTH);
644 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
645 for y := 1 to vph do
646 begin
647 a := @edgeBmp[y*(gWinSizeX+4)+1];
648 startLine(y);
649 for x := 1 to vpw do
650 begin
651 if (a[0] <> 0) then
652 begin
653 if (a[-1] = 0) or (a[1] = 0) or (a[-(gWinSizeX+4)] = 0) or (a[gWinSizeX+4] = 0) or
654 (a[-(gWinSizeX+4)-1] = 0) or (a[-(gWinSizeX+4)+1] = 0) or
655 (a[gWinSizeX+4-1] = 0) or (a[gWinSizeX+4+1] = 0) then
656 begin
657 putPixel(x);
658 end;
659 end;
660 Inc(a);
661 end;
662 flushLine();
663 end;
664 end;
666 procedure drawFilledWalls ();
667 var
668 x, y: Integer;
669 a: PByte;
670 begin
671 glDisable(GL_BLEND);
672 glDisable(GL_TEXTURE_2D);
673 glLineWidth(1);
674 glPointSize(1);
675 glDisable(GL_LINE_SMOOTH);
676 glDisable(GL_POLYGON_SMOOTH);
677 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
678 for y := 1 to vph do
679 begin
680 a := @edgeBmp[y*(gWinSizeX+4)+1];
681 startLine(y);
682 for x := 1 to vpw do
683 begin
684 if (a[0] <> 0) then putPixel(x);
685 Inc(a);
686 end;
687 flushLine();
688 end;
689 end;
691 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
692 var
693 f: Integer;
694 pan: TPanel;
695 begin
696 r := ar;
697 g := ag;
698 b := ab;
699 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
700 for f := 0 to High(parr) do
701 begin
702 pan := parr[f];
703 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
704 if ((pan.PanelType and ptype) = 0) then continue;
705 drawPanel(pan);
706 end;
707 if g_ol_nice then drawEdges();
708 if g_ol_fill_walls then drawFilledWalls();
709 end;
711 var
712 xptag: Word;
714 function doWallCB (pan: TPanel; tag: Integer): Boolean;
715 begin
716 result := false; // don't stop
717 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
718 if ((pan.PanelType and xptag) = 0) then exit;
719 drawPanel(pan);
720 end;
722 procedure doWalls (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
723 begin
724 r := ar;
725 g := ag;
726 b := ab;
727 xptag := ptype;
728 if ((ptype and (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR)) <> 0) then ptype := GridTagWall or GridTagDoor
729 else panelTypeToTag(ptype);
730 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
731 mapGrid.forEachInAABB(vpx-1, vpy-1, vpw+2, vph+2, doWallCB, ptype);
732 if g_ol_nice then drawEdges();
733 if g_ol_fill_walls then drawFilledWalls();
734 end;
736 begin
737 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
738 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
739 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
740 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
741 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
742 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
743 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
744 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
745 end;
747 {$ELSE}
748 var
749 oliner: TOutliner = nil;
751 procedure drawOutlines ();
752 var
753 r, g, b: Integer;
755 procedure clearOliner ();
756 begin
757 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
758 if (oliner = nil) then oliner := TOutliner.Create(vpw+2, vph+2) else oliner.setup(vpw+2, vph+2);
759 end;
761 procedure drawOutline (ol: TOutliner; sx, sy: Integer);
762 procedure xline (x0, x1, y: Integer);
763 var
764 x: Integer;
765 begin
766 if (g_dbg_scale < 1.0) then
767 begin
768 glBegin(GL_POINTS);
769 for x := x0 to x1 do glVertex2f(sx+x+0.375, sy+y+0.375);
770 glEnd();
771 end
772 else
773 begin
774 glBegin(GL_QUADS);
775 glVertex2f(sx+x0+0, sy+y+0);
776 glVertex2f(sx+x1+1, sy+y+0);
777 glVertex2f(sx+x1+1, sy+y+1);
778 glVertex2f(sx+x0+0, sy+y+1);
779 glEnd();
780 end;
781 end;
782 var
783 y: Integer;
784 sp: TOutliner.TSpanX;
785 begin
786 if (ol = nil) then exit;
787 glPointSize(1);
788 glDisable(GL_POINT_SMOOTH);
789 for y := 0 to ol.height-1 do
790 begin
791 for sp in ol.eachSpanAtY(y) do
792 begin
793 if (g_dbg_scale <= 1.0) then
794 begin
795 glBegin(GL_POINTS);
796 glVertex2f(sx+sp.x0+0.375, sy+y+0.375);
797 glVertex2f(sx+sp.x1+0.375, sy+y+0.375);
798 glEnd();
799 end
800 else
801 begin
802 glBegin(GL_QUADS);
803 glVertex2f(sx+sp.x0+0, sy+y+0);
804 glVertex2f(sx+sp.x0+1, sy+y+0);
805 glVertex2f(sx+sp.x0+1, sy+y+1);
806 glVertex2f(sx+sp.x0+0, sy+y+1);
808 glVertex2f(sx+sp.x1+0, sy+y+0);
809 glVertex2f(sx+sp.x1+1, sy+y+0);
810 glVertex2f(sx+sp.x1+1, sy+y+1);
811 glVertex2f(sx+sp.x1+0, sy+y+1);
812 glEnd();
813 end;
814 end;
815 for sp in ol.eachSpanEdgeAtY(y, -1) do
816 begin
817 xline(sp.x0, sp.x1, y);
819 glBegin(GL_QUADS);
820 glVertex2f(sx+sp.x0+0, sy+y+0);
821 glVertex2f(sx+sp.x1+1, sy+y+0);
822 glVertex2f(sx+sp.x1+1, sy+y+1);
823 glVertex2f(sx+sp.x0+0, sy+y+1);
824 glEnd();
826 end;
827 for sp in ol.eachSpanEdgeAtY(y, +1) do
828 begin
829 xline(sp.x0, sp.x1, y);
831 glBegin(GL_QUADS);
832 glVertex2f(sx+sp.x0+0, sy+y+0);
833 glVertex2f(sx+sp.x1+1, sy+y+0);
834 glVertex2f(sx+sp.x1+1, sy+y+1);
835 glVertex2f(sx+sp.x0+0, sy+y+1);
836 glEnd();
838 end;
839 end;
840 end;
842 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
843 var
844 f: Integer;
845 pan: TPanel;
846 begin
847 r := ar;
848 g := ag;
849 b := ab;
850 if g_ol_nice then clearOliner();
851 for f := 0 to High(parr) do
852 begin
853 pan := parr[f];
854 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
855 if ((pan.PanelType and ptype) = 0) then continue;
856 if (pan.X > vpx+vpw+41) or (pan.Y > vpy+vph+41) then continue;
857 if (pan.X+pan.Width < vpx-41) then continue;
858 if (pan.Y+pan.Height < vpy-41) then continue;
859 if g_ol_nice then
860 begin
861 oliner.addRect(pan.X-(vpx+1), pan.Y-(vpy+1), pan.Width, pan.Height);
862 end;
863 if g_ol_fill_walls then
864 begin
865 fillRect(pan.X, pan.Y, pan.Width, pan.Height, TGxRGBA.Create(r, g, b));
866 end
867 else if not g_ol_nice then
868 begin
869 drawRect(pan.X, pan.Y, pan.Width, pan.Height, TGxRGBA.Create(r, g, b));
870 end;
871 end;
872 if g_ol_nice then
873 begin
874 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
875 drawOutline(oliner, vpx+1, vpy+1);
876 end;
877 end;
879 begin
880 if (vpw < 2) or (vph < 2) then exit;
881 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
882 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
883 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
884 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
885 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
886 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
887 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
888 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
889 end;
890 {$ENDIF}
893 procedure plrDebugDraw ();
894 procedure drawTileGrid ();
895 var
896 x, y: Integer;
897 begin
898 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
899 begin
900 drawLine(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize, TGxRGBA.Create(96, 96, 96));
901 end;
903 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
904 begin
905 drawLine(mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0, mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0+y*mapGrid.gridHeight, TGxRGBA.Create(96, 96, 96));
906 end;
907 end;
909 procedure drawAwakeCells ();
910 var
911 x, y: Integer;
912 begin
913 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
914 begin
915 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
916 begin
917 if awmIsSetHolmes(x*mapGrid.tileSize+mapGrid.gridX0+1, y*mapGrid.tileSize++mapGrid.gridY0+1) then
918 begin
919 fillRect(x*mapGrid.tileSize++mapGrid.gridX0, y*mapGrid.tileSize++mapGrid.gridY0, monsGrid.tileSize, monsGrid.tileSize, TGxRGBA.Create(128, 0, 128, 64));
920 end;
921 end;
922 end;
923 end;
925 procedure drawTraceBox ();
926 var
927 plr: TPlayer;
928 px, py, pw, ph: Integer;
929 pdx, pdy: Integer;
930 ex, ey: Integer;
931 pan: TPanel;
932 begin
933 if (Length(gPlayers) < 1) then exit;
934 plr := gPlayers[0];
935 if (plr = nil) then exit;
936 plr.getMapBox(px, py, pw, ph);
937 drawRect(px, py, pw, ph, TGxRGBA.Create(255, 0, 255, 200));
938 pdx := pmsCurMapX-(px+pw div 2);
939 pdy := pmsCurMapY-(py+ph div 2);
940 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));
941 pan := mapGrid.traceBox(ex, ey, px, py, pw, ph, pdx, pdy, nil, GridTagObstacle);
942 if (pan = nil) then
943 begin
944 drawRect(px+pdx, py+pdy, pw, ph, TGxRGBA.Create(255, 255, 255, 180));
945 end
946 else
947 begin
948 drawRect(px+pdx, py+pdy, pw, ph, TGxRGBA.Create(255, 255, 0, 180));
949 end;
950 drawRect(ex, ey, pw, ph, TGxRGBA.Create(255, 127, 0, 180));
951 end;
953 procedure hilightCell (cx, cy: Integer);
954 begin
955 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, TGxRGBA.Create(0, 128, 0, 64));
956 end;
958 procedure hilightCell1 (cx, cy: Integer);
959 begin
960 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
961 cx := cx and (not (monsGrid.tileSize-1));
962 cy := cy and (not (monsGrid.tileSize-1));
963 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, TGxRGBA.Create(255, 255, 0, 92));
964 end;
966 function hilightWallTrc (pan: TPanel; tag: Integer; x, y, prevx, prevy: Integer): Boolean;
967 begin
968 result := false; // don't stop
969 if (pan = nil) then exit; // cell completion, ignore
970 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
971 fillRect(pan.X, pan.Y, pan.Width, pan.Height, TGxRGBA.Create(0, 128, 128, 64));
972 end;
974 function monsCollector (mon: TMonster; tag: Integer): Boolean;
975 var
976 ex, ey: Integer;
977 mx, my, mw, mh: Integer;
978 begin
979 result := false;
980 mon.getMapBox(mx, my, mw, mh);
981 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
982 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
983 begin
984 e_DrawPoint(8, ex, ey, 0, 255, 0);
985 end;
986 end;
988 procedure drawMonsterInfo (mon: TMonster);
989 var
990 mx, my, mw, mh: Integer;
992 procedure drawMonsterTargetLine ();
993 var
994 emx, emy, emw, emh: Integer;
995 enemy: TMonster;
996 eplr: TPlayer;
997 ex, ey: Integer;
998 begin
999 if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
1000 begin
1001 eplr := g_Player_Get(mon.MonsterTargetUID);
1002 if (eplr <> nil) then eplr.getMapBox(emx, emy, emw, emh) else exit;
1003 end
1004 else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then
1005 begin
1006 enemy := g_Monsters_ByUID(mon.MonsterTargetUID);
1007 if (enemy <> nil) then enemy.getMapBox(emx, emy, emw, emh) else exit;
1008 end
1009 else
1010 begin
1011 exit;
1012 end;
1013 mon.getMapBox(mx, my, mw, mh);
1014 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, TGxRGBA.Create(255, 0, 0));
1015 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
1016 begin
1017 drawLine(mx+mw div 2, my+mh div 2, ex, ey, TGxRGBA.Create(0, 255, 0));
1018 end;
1019 end;
1021 procedure drawLOS2Plr ();
1022 var
1023 emx, emy, emw, emh: Integer;
1024 eplr: TPlayer;
1025 ex, ey: Integer;
1026 begin
1027 eplr := gPlayers[0];
1028 if (eplr = nil) then exit;
1029 eplr.getMapBox(emx, emy, emw, emh);
1030 mon.getMapBox(mx, my, mw, mh);
1031 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, TGxRGBA.Create(255, 0, 0));
1032 {$IF DEFINED(D2F_DEBUG)}
1033 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1034 {$ENDIF}
1035 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
1036 //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
1037 begin
1038 drawLine(mx+mw div 2, my+mh div 2, ex, ey, TGxRGBA.Create(0, 255, 0));
1039 end;
1040 {$IF DEFINED(D2F_DEBUG)}
1041 mapGrid.dbgRayTraceTileHitCB := nil;
1042 {$ENDIF}
1043 end;
1045 begin
1046 if (mon = nil) then exit;
1047 mon.getMapBox(mx, my, mw, mh);
1048 //mx += mw div 2;
1050 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1052 if showMonsInfo then
1053 begin
1054 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1055 darkenRect(mx-4, my-7*8-6, 110, 7*8+6, 128);
1056 my -= 8;
1057 my -= 2;
1059 // type
1060 drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1061 // beh
1062 drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1063 // state
1064 drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1065 // health
1066 drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1067 // ammo
1068 drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1069 // target
1070 drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1071 drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), TGxRGBA.Create(255, 127, 0)); my -= 8;
1072 end;
1074 drawMonsterTargetLine();
1075 if showMonsLOS2Plr then drawLOS2Plr();
1077 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1078 property MonsterPain: Integer read FPain write FPain;
1079 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1081 end;
1083 function highlightAllMonsterCells (mon: TMonster): Boolean;
1084 begin
1085 result := false; // don't stop
1086 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1087 end;
1089 procedure drawSelectedPlatformCells ();
1090 var
1091 pan: TPanel;
1092 begin
1093 if not showGrid then exit;
1094 pan := g_Map_PanelByGUID(platMarkedGUID);
1095 if (pan = nil) then exit;
1096 mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
1097 drawRect(pan.x, pan.y, pan.width, pan.height, TGxRGBA.Create(0, 200, 0, 200));
1098 end;
1100 procedure drawTrigger (var trig: TTrigger);
1102 procedure drawPanelDest (pguid: Integer);
1103 var
1104 pan: TPanel;
1105 begin
1106 pan := g_Map_PanelByGUID(pguid);
1107 if (pan = nil) then exit;
1108 drawLine(
1109 trig.trigCenter.x, trig.trigCenter.y,
1110 pan.x+pan.width div 2, pan.y+pan.height div 2,
1111 TGxRGBA.Create(255, 0, 255, 220));
1112 end;
1114 var
1115 tts: AnsiString;
1116 tx: Integer;
1117 begin
1118 fillRect(trig.x, trig.y, trig.width, trig.height, TGxRGBA.Create(255, 0, 255, 96));
1119 tts := trigType2Str(trig.TriggerType);
1120 tx := trig.x+(trig.width-Length(tts)*6) div 2;
1121 darkenRect(tx-2, trig.y-10, Length(tts)*6+4, 10, 64);
1122 drawText6(tx, trig.y-9, tts, TGxRGBA.Create(255, 127, 0));
1123 tx := trig.x+(trig.width-Length(trig.mapId)*6) div 2;
1124 darkenRect(tx-2, trig.y-20, Length(trig.mapId)*6+4, 10, 64);
1125 drawText6(tx, trig.y-19, trig.mapId, TGxRGBA.Create(255, 255, 0));
1126 drawPanelDest(trig.trigPanelGUID);
1127 case trig.TriggerType of
1128 TRIGGER_NONE: begin end;
1129 TRIGGER_EXIT: begin end;
1130 TRIGGER_TELEPORT: begin end;
1131 TRIGGER_OPENDOOR: begin end;
1132 TRIGGER_CLOSEDOOR: begin end;
1133 TRIGGER_DOOR: begin end;
1134 TRIGGER_DOOR5: begin end;
1135 TRIGGER_CLOSETRAP: begin end;
1136 TRIGGER_TRAP: begin end;
1137 TRIGGER_SECRET: begin end;
1138 TRIGGER_LIFTUP: begin end;
1139 TRIGGER_LIFTDOWN: begin end;
1140 TRIGGER_LIFT: begin end;
1141 TRIGGER_TEXTURE: begin end;
1142 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF, TRIGGER_PRESS:
1143 begin
1144 if (trig.trigDataRec.trigTWidth > 0) and (trig.trigDataRec.trigTHeight > 0) then
1145 begin
1146 fillRect(
1147 trig.trigDataRec.trigTX, trig.trigDataRec.trigTY,
1148 trig.trigDataRec.trigTWidth, trig.trigDataRec.trigTHeight,
1149 TGxRGBA.Create(0, 255, 255, 42));
1150 drawLine(
1151 trig.trigCenter.x, trig.trigCenter.y,
1152 trig.trigDataRec.trigTX+trig.trigDataRec.trigTWidth div 2,
1153 trig.trigDataRec.trigTY+trig.trigDataRec.trigTHeight div 2,
1154 TGxRGBA.Create(255, 0, 255, 220));
1155 end;
1156 end;
1157 TRIGGER_SOUND: begin end;
1158 TRIGGER_SPAWNMONSTER: begin end;
1159 TRIGGER_SPAWNITEM: begin end;
1160 TRIGGER_MUSIC: begin end;
1161 TRIGGER_PUSH: begin end;
1162 TRIGGER_SCORE: begin end;
1163 TRIGGER_MESSAGE: begin end;
1164 TRIGGER_DAMAGE: begin end;
1165 TRIGGER_HEALTH: begin end;
1166 TRIGGER_SHOT: begin end;
1167 TRIGGER_EFFECT: begin end;
1168 TRIGGER_SCRIPT: begin end;
1169 end;
1170 //trigType2Str
1171 //trigPanelId: Integer;
1172 end;
1174 procedure drawTriggers ();
1175 var
1176 f: Integer;
1177 begin
1178 for f := 0 to High(gTriggers) do drawTrigger(gTriggers[f]);
1179 end;
1181 procedure drawGibsBoxes ();
1182 var
1183 f: Integer;
1184 px, py, pw, ph: Integer;
1185 gib: PGib;
1186 begin
1187 for f := 0 to High(gGibs) do
1188 begin
1189 gib := @gGibs[f];
1190 if gib.alive then
1191 begin
1192 gib.getMapBox(px, py, pw, ph);
1193 drawRect(px, py, pw, ph, TGxRGBA.Create(255, 0, 255));
1194 end;
1195 end;
1196 end;
1198 var
1199 scisave: TScissorSave;
1200 mon: TMonster;
1201 mx, my, mw, mh: Integer;
1202 //pan: TPanel;
1203 //ex, ey: Integer;
1204 begin
1205 if (gPlayer1 = nil) then exit;
1207 scisave.save(true); // enable scissoring
1208 glPushMatrix();
1209 try
1210 //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
1211 glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1213 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
1214 glTranslatef(-vpx, -vpy, 0);
1216 if (showGrid) then drawTileGrid();
1217 drawOutlines();
1219 if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
1221 if (monMarkedUID <> -1) then
1222 begin
1223 mon := g_Monsters_ByUID(monMarkedUID);
1224 if (mon <> nil) then
1225 begin
1226 mon.getMapBox(mx, my, mw, mh);
1227 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
1228 drawMonsterInfo(mon);
1229 end;
1230 end;
1232 if showAllMonsCells and showGrid then g_Mons_ForEach(highlightAllMonsterCells);
1233 if showTriggers then drawTriggers();
1234 if showGrid then drawSelectedPlatformCells();
1236 //drawAwakeCells();
1238 if showTraceBox then drawTraceBox();
1240 //drawGibsBoxes();
1243 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1244 (*
1245 {$IF DEFINED(D2F_DEBUG)}
1246 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1247 {$ENDIF}
1248 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1249 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1250 {$IF DEFINED(D2F_DEBUG)}
1251 mapGrid.dbgRayTraceTileHitCB := nil;
1252 {$ENDIF}
1254 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1255 if (pan <> nil) then writeln('hit!');
1256 *)
1258 finally
1259 glPopMatrix();
1260 scisave.restore();
1261 end;
1263 if showMapCurPos then drawText8(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]), TGxRGBA.Create(255, 255, 0));
1264 end;
1267 // ////////////////////////////////////////////////////////////////////////// //
1268 procedure g_Holmes_MouseEvent (var ev: THMouseEvent);
1269 var
1270 he: THMouseEvent;
1271 begin
1272 if g_Game_IsNet then exit;
1273 if not g_holmes_enabled then exit;
1275 holmesInitCommands();
1276 holmesInitBinds();
1277 msX := ev.x;
1278 msY := ev.y;
1279 msB := ev.bstate;
1280 kbS := ev.kstate;
1281 msB := msB;
1282 he := ev;
1283 he.x := he.x;
1284 he.y := he.y;
1285 uiMouseEvent(he);
1286 if (not he.eaten) then plrDebugMouse(he);
1287 ev.eat();
1288 end;
1291 // ////////////////////////////////////////////////////////////////////////// //
1292 procedure g_Holmes_KeyEvent (var ev: THKeyEvent);
1293 var
1294 doeat: Boolean = false;
1295 {$IF DEFINED(D2F_DEBUG)}
1296 pan: TPanel;
1297 ex, ey: Integer;
1298 dx, dy: Integer;
1299 {$ENDIF}
1301 procedure dummyWallTrc (cx, cy: Integer);
1302 begin
1303 end;
1305 begin
1306 if g_Game_IsNet then exit;
1307 if not g_holmes_enabled then exit;
1309 holmesInitCommands();
1310 holmesInitBinds();
1312 msB := ev.bstate;
1313 kbS := ev.kstate;
1314 case ev.scan of
1315 SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL,
1316 SDL_SCANCODE_LALT, SDL_SCANCODE_RALT,
1317 SDL_SCANCODE_LSHIFT, SDL_SCANCODE_RSHIFT:
1318 doeat := true;
1319 end;
1321 uiKeyEvent(ev);
1322 if (ev.eaten) then exit;
1323 if keybindExecute(ev) then begin ev.eat(); exit; end;
1324 // press
1325 if (ev.press) then
1326 begin
1327 {$IF DEFINED(D2F_DEBUG)}
1328 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1329 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
1330 ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
1331 begin
1332 ev.eat();
1333 dx := pmsCurMapX;
1334 dy := pmsCurMapY;
1335 case ev.scan of
1336 SDL_SCANCODE_UP: dy -= 120;
1337 SDL_SCANCODE_DOWN: dy += 120;
1338 SDL_SCANCODE_LEFT: dx -= 120;
1339 SDL_SCANCODE_RIGHT: dx += 120;
1340 end;
1341 {$IF DEFINED(D2F_DEBUG)}
1342 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1343 mapGrid.dbgShowTraceLog := true;
1344 {$ENDIF}
1345 pan := g_Map_traceToNearest(pmsCurMapX, pmsCurMapY, dx, dy, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
1346 {$IF DEFINED(D2F_DEBUG)}
1347 //mapGrid.dbgRayTraceTileHitCB := nil;
1348 mapGrid.dbgShowTraceLog := false;
1349 {$ENDIF}
1350 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, dx, dy, ex, ey, (pan <> nil)]);
1351 exit;
1352 end;
1353 {$ENDIF}
1354 end;
1355 if (doeat) then ev.eat();
1356 end;
1359 // ////////////////////////////////////////////////////////////////////////// //
1360 procedure g_Holmes_Draw ();
1361 begin
1362 if g_Game_IsNet then exit;
1364 {$IF not DEFINED(HEADLESS)}
1365 holmesInitCommands();
1366 holmesInitBinds();
1368 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
1369 glDisable(GL_STENCIL_TEST);
1370 glDisable(GL_BLEND);
1371 glDisable(GL_SCISSOR_TEST);
1372 glDisable(GL_TEXTURE_2D);
1374 if gGameOn then plrDebugDraw();
1375 {$ENDIF}
1377 laserSet := false;
1378 end;
1381 procedure g_Holmes_DrawUI ();
1382 begin
1383 if g_Game_IsNet then exit;
1384 if not g_holmes_enabled then exit;
1385 {$IF not DEFINED(HEADLESS)}
1386 gGfxDoClear := false;
1387 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1388 uiDraw();
1389 glMatrixMode(GL_MODELVIEW);
1390 glPushMatrix();
1391 try
1392 //glLoadIdentity();
1393 if assigned(postrenderFrameCB) then postrenderFrameCB();
1394 finally
1395 glPopMatrix();
1396 end;
1397 {$ENDIF}
1398 end;
1401 // ////////////////////////////////////////////////////////////////////////// //
1402 procedure bcOneMonsterThinkStep (); begin gmon_debug_think := false; gmon_debug_one_think_step := true; end;
1403 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active := false; g_dbgpan_mplat_step := true; end;
1404 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active := not g_dbgpan_mplat_active; end;
1406 procedure bcToggleMonsterInfo (arg: Integer=-1); begin if (arg < 0) then showMonsInfo := not showMonsInfo else showMonsInfo := (arg > 0); end;
1407 procedure bcToggleMonsterLOSPlr (arg: Integer=-1); begin if (arg < 0) then showMonsLOS2Plr := not showMonsLOS2Plr else showMonsLOS2Plr := (arg > 0); end;
1408 procedure bcToggleMonsterCells (arg: Integer=-1); begin if (arg < 0) then showAllMonsCells := not showAllMonsCells else showAllMonsCells := (arg > 0); end;
1409 procedure bcToggleDrawTriggers (arg: Integer=-1); begin if (arg < 0) then showTriggers := not showTriggers else showTriggers := (arg > 0); end;
1411 procedure bcToggleCurPos (arg: Integer=-1); begin if (arg < 0) then showMapCurPos := not showMapCurPos else showMapCurPos := (arg > 0); end;
1412 procedure bcToggleGrid (arg: Integer=-1); begin if (arg < 0) then showGrid := not showGrid else showGrid := (arg > 0); end;
1414 procedure bcMonsterSpawn (s: AnsiString);
1415 var
1416 mon: TMonster;
1417 begin
1418 if not gGameOn or g_Game_IsClient then
1419 begin
1420 conwriteln('cannot spawn monster in this mode');
1421 exit;
1422 end;
1423 mon := g_Mons_SpawnAt(s, pmsCurMapX, pmsCurMapY);
1424 if (mon = nil) then begin conwritefln('unknown monster id: ''%s''', [s]); exit; end;
1425 monMarkedUID := mon.UID;
1426 end;
1428 procedure bcMonsterWakeup ();
1429 var
1430 mon: TMonster;
1431 begin
1432 if (monMarkedUID <> -1) then
1433 begin
1434 mon := g_Monsters_ByUID(monMarkedUID);
1435 if (mon <> nil) then mon.WakeUp();
1436 end;
1437 end;
1439 procedure bcPlayerTeleport ();
1440 var
1441 x, y, w, h: Integer;
1442 begin
1443 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1444 if (gPlayers[0] <> nil) then
1445 begin
1446 gPlayers[0].getMapBox(x, y, w, h);
1447 gPlayers[0].TeleportTo(pmsCurMapX-w div 2, pmsCurMapY-h div 2, true, 69); // 69: don't change dir
1448 end;
1449 end;
1451 procedure dbgToggleTraceBox (arg: Integer=-1); begin if (arg < 0) then showTraceBox := not showTraceBox else showTraceBox := (arg > 0); end;
1453 procedure dbgToggleHolmesPause (arg: Integer=-1); begin if (arg < 0) then g_Game_HolmesPause(not gPauseHolmes) else g_Game_HolmesPause(arg > 0); end;
1455 procedure cbAtcurSelectMonster ();
1456 function monsAtDump (mon: TMonster; tag: Integer): Boolean;
1457 begin
1458 result := true; // stop
1459 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), TMsgType.Notify);
1460 monMarkedUID := mon.UID;
1461 dumpPublishedProperties(mon);
1462 end;
1463 var
1464 plr: TPlayer;
1465 x, y, w, h: Integer;
1466 begin
1467 monMarkedUID := -1;
1468 if (Length(gPlayers) > 0) then
1469 begin
1470 plr := gPlayers[0];
1471 if (plr <> nil) then
1472 begin
1473 plr.getMapBox(x, y, w, h);
1474 if (pmsCurMapX >= x) and (pmsCurMapY >= y) and (pmsCurMapX < x+w) and (pmsCurMapY < y+h) then
1475 begin
1476 dumpPublishedProperties(plr);
1477 end;
1478 end;
1479 end;
1480 //e_WriteLog('===========================', MSG_NOTIFY);
1481 monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
1482 //e_WriteLog('---------------------------', MSG_NOTIFY);
1483 end;
1485 procedure cbAtcurDumpMonsters ();
1486 function monsAtDump (mon: TMonster; tag: Integer): Boolean;
1487 begin
1488 result := false; // don't stop
1489 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), TMsgType.Notify);
1490 end;
1491 begin
1492 e_WriteLog('===========================', TMsgType.Notify);
1493 monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
1494 e_WriteLog('---------------------------', TMsgType.Notify);
1495 end;
1497 procedure cbAtcurDumpWalls ();
1498 function wallToggle (pan: TPanel; tag: Integer): Boolean;
1499 begin
1500 result := false; // don't stop
1501 if (platMarkedGUID = -1) then platMarkedGUID := pan.guid;
1502 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]);
1503 dumpPublishedProperties(pan);
1504 end;
1505 var
1506 hasTrigs: Boolean = false;
1507 f: Integer;
1508 trig: PTrigger;
1509 begin
1510 platMarkedGUID := -1;
1511 e_WriteLog('=== TOGGLE WALL ===', TMsgType.Notify);
1512 mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
1513 e_WriteLog('--- toggle wall ---', TMsgType.Notify);
1514 if showTriggers then
1515 begin
1516 for f := 0 to High(gTriggers) do
1517 begin
1518 trig := @gTriggers[f];
1519 if (pmsCurMapX >= trig.x) and (pmsCurMapY >= trig.y) and (pmsCurMapX < trig.x+trig.width) and (pmsCurMapY < trig.y+trig.height) then
1520 begin
1521 if not hasTrigs then begin writeln('=== TRIGGERS ==='); hasTrigs := true; end;
1522 writeln('trigger ''', trig.mapId, ''' of type ''', trigType2Str(trig.TriggerType), '''');
1523 end;
1524 end;
1525 if hasTrigs then writeln('--- triggers ---');
1526 end;
1527 end;
1529 procedure cbAtcurToggleWalls ();
1530 function wallToggle (pan: TPanel; tag: Integer): Boolean;
1531 begin
1532 result := false; // don't stop
1533 //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);
1534 if pan.Enabled then g_Map_DisableWallGUID(pan.guid) else g_Map_EnableWallGUID(pan.guid);
1535 end;
1536 begin
1537 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1538 mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
1539 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1540 end;
1543 // ////////////////////////////////////////////////////////////////////////// //
1544 procedure holmesInitCommands ();
1545 begin
1546 if (cmdlist <> nil) then exit;
1547 cmdAdd('win_layers', toggleLayersWindow, 'toggle layers window', 'window control');
1548 cmdAdd('win_outline', toggleOutlineWindow, 'toggle outline window', 'window control');
1549 cmdAdd('win_help', toggleHelpWindow, 'toggle help window', 'window control');
1550 cmdAdd('win_options', toggleOptionsWindow, 'toggle options window', 'window control');
1552 cmdAdd('mon_think_step', bcOneMonsterThinkStep, 'one monster think step', 'monster control');
1553 cmdAdd('mon_info', bcToggleMonsterInfo, 'toggle monster info', 'monster control');
1554 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr, 'toggle monster LOS to player', 'monster control');
1555 cmdAdd('mon_cells', bcToggleMonsterCells, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1556 cmdAdd('mon_wakeup', bcMonsterWakeup, 'wake up selected monster', 'monster control');
1558 cmdAdd('mon_spawn', bcMonsterSpawn, 'spawn monster', 'monster control');
1560 cmdAdd('mplat_step', bcOneMPlatThinkStep, 'one mplat think step', 'mplat control');
1561 cmdAdd('mplat_toggle', bcMPlatToggle, 'activate/deactivate moving platforms', 'mplat control');
1563 cmdAdd('plr_teleport', bcPlayerTeleport, 'teleport player', 'player control');
1565 cmdAdd('dbg_curpos', bcToggleCurPos, 'toggle "show cursor position on the map"', 'various');
1566 cmdAdd('dbg_grid', bcToggleGrid, 'toggle grid', 'various');
1567 cmdAdd('dbg_triggers', bcToggleDrawTriggers, 'show/hide triggers (SLOW!)', 'various');
1569 cmdAdd('atcur_select_monster', cbAtcurSelectMonster, 'select monster to operate', 'monster control');
1570 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters, 'dump monsters in cell', 'monster control');
1571 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls, 'dump walls in cell', 'wall control');
1572 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls, 'disable walls', 'wall control');
1574 cmdAdd('dbg_tracebox', dbgToggleTraceBox, 'test traceBox()', 'player control');
1576 cmdAdd('hlm_pause', dbgToggleHolmesPause, '"Holmes" pause mode', 'game control');
1577 end;
1580 procedure holmesInitBinds ();
1581 var
1582 st: TStream = nil;
1583 pr: TTextParser = nil;
1584 s, kn, v: AnsiString;
1585 kmods: Byte;
1586 mbuts: Byte;
1587 begin
1588 kbS := kbS;
1589 if not keybindsInited then
1590 begin
1591 // keyboard
1592 keybindAdd('F1', 'win_help');
1593 keybindAdd('M-F1', 'win_options');
1594 keybindAdd('C-O', 'win_outline');
1595 keybindAdd('C-L', 'win_layers');
1597 keybindAdd('M-M', 'mon_think_step');
1598 keybindAdd('M-I', 'mon_info');
1599 keybindAdd('M-L', 'mon_los_plr');
1600 keybindAdd('M-G', 'mon_cells');
1601 keybindAdd('M-A', 'mon_wakeup');
1603 keybindAdd('M-P', 'mplat_step');
1604 keybindAdd('M-O', 'mplat_toggle');
1606 keybindAdd('C-T', 'plr_teleport');
1607 keybindAdd('M-T', 'dbg_tracebox');
1609 keybindAdd('C-P', 'dbg_curpos');
1610 keybindAdd('C-G', 'dbg_grid');
1611 keybindAdd('C-X', 'dbg_triggers');
1613 keybindAdd('C-1', 'mon_spawn zombie');
1615 keybindAdd('C-S-P', 'hlm_pause');
1617 // mouse
1618 msbindAdd('LMB', 'atcur_select_monster');
1619 msbindAdd('M-LMB', 'atcur_dump_monsters');
1620 msbindAdd('RMB', 'atcur_dump_walls');
1621 msbindAdd('M-RMB', 'atcur_disable_walls');
1623 // load bindings from file
1624 try
1625 st := openDiskFileRO(GameDir+'holmes.rc');
1626 pr := TFileTextParser.Create(st);
1627 conwriteln('parsing "holmes.rc"...');
1628 while (pr.tokType <> pr.TTEOF) do
1629 begin
1630 s := pr.expectId();
1631 if (s = 'stop') then break
1632 else if (s = 'unbind_keys') then keybinds := nil
1633 else if (s = 'unbind_mouse') then msbinds := nil
1634 else if (s = 'bind') then
1635 begin
1636 if (pr.tokType = pr.TTStr) then s := pr.expectStr(false)
1637 else if (pr.tokType = pr.TTInt) then s := Format('%d', [pr.expectInt()])
1638 else s := pr.expectId();
1640 if (pr.tokType = pr.TTStr) then v := pr.expectStr(false)
1641 else if (pr.tokType = pr.TTInt) then v := Format('%d', [pr.expectInt()])
1642 else v := pr.expectId();
1644 kn := parseModKeys(s, kmods, mbuts);
1645 if (CompareText(kn, 'lmb') = 0) or (CompareText(kn, 'rmb') = 0) or (CompareText(kn, 'mmb') = 0) or (CompareText(kn, 'None') = 0) then
1646 begin
1647 msbindAdd(s, v);
1648 end
1649 else
1650 begin
1651 keybindAdd(s, v);
1652 end;
1653 end;
1654 end;
1655 except on e: Exception do // sorry
1656 if (pr <> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr.tokLine, pr.tokCol, e.message]);
1657 end;
1658 if (pr <> nil) then pr.Free() else st.Free(); // ownership
1659 end;
1660 end;
1663 procedure onMouseEvent (var ev: THMouseEvent);
1664 begin
1665 if not g_holmes_enabled then exit;
1666 g_Holmes_MouseEvent(ev);
1667 end;
1669 procedure onKeyEvent (var ev: THKeyEvent);
1670 begin
1671 if not g_holmes_enabled then exit;
1672 g_Holmes_KeyEvent(ev);
1673 end;
1676 begin
1677 evMouseCB := onMouseEvent;
1678 evKeyCB := onKeyEvent;
1680 conRegVar('hlm_ui_scale', @gh_ui_scale, 0.01, 5.0, 'Holmes UI scale', '', false);
1681 end.