DEADSOFTWARE

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