DEADSOFTWARE

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