DEADSOFTWARE

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