DEADSOFTWARE

grid: only one debug callback left (ok, let it be there for now...)
[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 mempool, 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_OnEvent (var ev: TFUIEvent);
37 // hooks for player
38 procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer);
39 procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer);
40 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
43 var
44 g_holmes_imfunctional: Boolean = false;
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 hlmContext: TGxContext = nil;
59 //globalInited: Boolean = false;
60 msX: Integer = -666;
61 msY: Integer = -666;
62 msB: Word = 0; // button state
63 kbS: Word = 0; // keyboard modifiers state
64 showGrid: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
65 showMonsInfo: Boolean = false;
66 showMonsLOS2Plr: Boolean = false;
67 showAllMonsCells: Boolean = false;
68 showMapCurPos: Boolean = false;
69 showLayersWindow: Boolean = false;
70 showOutlineWindow: Boolean = false;
71 showTriggers: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
72 showTraceBox: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
75 // ////////////////////////////////////////////////////////////////////////// //
76 {$INCLUDE g_holmes.inc}
77 {$INCLUDE g_holmes_ol.inc} // outliner
80 // ////////////////////////////////////////////////////////////////////////// //
81 {$INCLUDE g_holmes_cmd.inc}
82 procedure holmesInitCommands (); forward;
83 procedure holmesInitBinds (); forward;
86 // ////////////////////////////////////////////////////////////////////////// //
87 var
88 g_ol_nice: Boolean = false;
89 g_ol_fill_walls: Boolean = false;
90 g_ol_rlayer_back: Boolean = false;
91 g_ol_rlayer_step: Boolean = false;
92 g_ol_rlayer_wall: Boolean = false;
93 g_ol_rlayer_door: Boolean = false;
94 g_ol_rlayer_acid1: Boolean = false;
95 g_ol_rlayer_acid2: Boolean = false;
96 g_ol_rlayer_water: Boolean = false;
97 g_ol_rlayer_fore: Boolean = false;
100 // ////////////////////////////////////////////////////////////////////////// //
101 var
102 winHelp: TUITopWindow = nil;
103 winOptions: TUITopWindow = nil;
104 winLayers: TUITopWindow = nil;
105 winOutlines: TUITopWindow = nil;
108 procedure createHelpWindow (); forward;
109 procedure createOptionsWindow (); forward;
110 procedure createLayersWindow (); forward;
111 procedure createOutlinesWindow (); forward;
114 procedure toggleLayersWindowCB (me: TUIControl);
115 begin
116 showLayersWindow := not showLayersWindow;
117 if showLayersWindow then
118 begin
119 if (winLayers = nil) then createLayersWindow();
120 uiAddWindow(winLayers);
121 end
122 else
123 begin
124 uiRemoveWindow(winLayers);
125 end;
126 end;
128 procedure toggleOutlineWindowCB (me: TUIControl);
129 begin
130 showOutlineWindow := not showOutlineWindow;
131 if showOutlineWindow then
132 begin
133 if (winOutlines = nil) then createOutlinesWindow();
134 uiAddWindow(winOutlines);
135 end
136 else
137 begin
138 uiRemoveWindow(winOutlines);
139 end;
140 end;
143 procedure createHelpWindow ();
144 procedure addHelpEmptyLine ();
145 var
146 stx: TUIStaticText;
147 begin
148 stx := TUIStaticText.Create();
149 stx.flExpand := true;
150 stx.halign := 0; // center
151 stx.text := '';
152 stx.header := false;
153 stx.line := false;
154 winHelp.appendChild(stx);
155 end;
157 procedure addHelpCaptionLine (const txt: AnsiString);
158 var
159 stx: TUIStaticText;
160 begin
161 stx := TUIStaticText.Create();
162 stx.flExpand := true;
163 stx.halign := 0; // center
164 stx.text := txt;
165 stx.header := true;
166 stx.line := true;
167 winHelp.appendChild(stx);
168 end;
170 procedure addHelpCaption (const txt: AnsiString);
171 var
172 stx: TUIStaticText;
173 begin
174 stx := TUIStaticText.Create();
175 stx.flExpand := true;
176 stx.halign := 0; // center
177 stx.text := txt;
178 stx.header := true;
179 stx.line := false;
180 winHelp.appendChild(stx);
181 end;
183 procedure addHelpKeyMouse (const key, txt, grp: AnsiString);
184 var
185 box: TUIHBox;
186 span: TUISpan;
187 stx: TUIStaticText;
188 begin
189 box := TUIHBox.Create();
190 box.flExpand := true;
191 // key
192 stx := TUIStaticText.Create();
193 stx.flExpand := true;
194 stx.halign := 1; // right
195 stx.valign := 0; // center
196 stx.text := key;
197 stx.header := true;
198 stx.line := false;
199 stx.flHGroup := grp;
200 box.appendChild(stx);
201 // span
202 span := TUISpan.Create();
203 span.flDefaultSize := TLaySize.Create(12, 1);
204 span.flExpand := true;
205 box.appendChild(span);
206 // text
207 stx := TUIStaticText.Create();
208 stx.flExpand := true;
209 stx.halign := -1; // left
210 stx.valign := 0; // center
211 stx.text := txt;
212 stx.header := false;
213 stx.line := false;
214 box.appendChild(stx);
215 winHelp.appendChild(box);
216 end;
218 procedure addHelpKey (const key, txt: AnsiString); begin addHelpKeyMouse(key, txt, 'help-keys'); end;
219 procedure addHelpMouse (const key, txt: AnsiString); begin addHelpKeyMouse(key, txt, 'help-mouse'); end;
221 var
222 slist: array of AnsiString = nil;
223 cmd: PHolmesCommand;
224 bind: THolmesBinding;
225 f: Integer;
227 llb: TUISimpleText;
228 maxkeylen: Integer;
229 s: AnsiString;
231 begin
232 winHelp := TUITopWindow.Create('Holmes Help');
233 winHelp.escClose := true;
234 winHelp.flHoriz := false;
236 // keyboard
237 for cmd in cmdlist do cmd.helpmark := false;
239 //maxkeylen := 0;
240 for bind in keybinds do
241 begin
242 if (Length(bind.key) = 0) then continue;
243 if cmdlist.get(bind.cmdName, cmd) then
244 begin
245 if (Length(cmd.help) > 0) then
246 begin
247 cmd.helpmark := true;
248 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
249 end;
250 end;
251 end;
253 for cmd in cmdlist do
254 begin
255 if not cmd.helpmark then continue;
256 if (Length(cmd.help) = 0) then begin cmd.helpmark := false; continue; end;
257 f := 0;
258 while (f < Length(slist)) and (CompareText(slist[f], cmd.section) <> 0) do Inc(f);
259 if (f = Length(slist)) then
260 begin
261 SetLength(slist, Length(slist)+1);
262 slist[High(slist)] := cmd.section;
263 end;
264 end;
266 addHelpCaptionLine('KEYBOARD');
267 //llb := TUISimpleText.Create(0, 0);
268 for f := 0 to High(slist) do
269 begin
270 //if (f > 0) then llb.appendItem('');
271 if (f > 0) then addHelpEmptyLine();
272 //llb.appendItem(slist[f], true, true);
273 addHelpCaption(slist[f]);
274 for cmd in cmdlist do
275 begin
276 if not cmd.helpmark then continue;
277 if (CompareText(cmd.section, slist[f]) <> 0) then continue;
278 for bind in keybinds do
279 begin
280 if (Length(bind.key) = 0) then continue;
281 if (cmd.name = bind.cmdName) then
282 begin
283 //s := bind.key;
284 //while (Length(s) < maxkeylen) do s += ' ';
285 //s := ' '+s+' -- '+cmd.help;
286 //llb.appendItem(s);
287 addHelpMouse(bind.key, cmd.help);
288 end;
289 end;
290 end;
291 end;
293 // mouse
294 for cmd in cmdlist do cmd.helpmark := false;
296 //maxkeylen := 0;
297 for bind in msbinds do
298 begin
299 if (Length(bind.key) = 0) then continue;
300 if cmdlist.get(bind.cmdName, cmd) then
301 begin
302 if (Length(cmd.help) > 0) then
303 begin
304 cmd.helpmark := true;
305 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
306 end;
307 end;
308 end;
310 //llb.appendItem('');
311 //llb.appendItem('mouse', true, true);
312 if (f > 0) then addHelpEmptyLine();
313 addHelpCaptionLine('MOUSE');
314 for bind in msbinds do
315 begin
316 if (Length(bind.key) = 0) then continue;
317 if cmdlist.get(bind.cmdName, cmd) then
318 begin
319 if (Length(cmd.help) > 0) then
320 begin
321 //s := bind.key;
322 //while (Length(s) < maxkeylen) do s += ' ';
323 //s := ' '+s+' -- '+cmd.help;
324 //llb.appendItem(s);
325 addHelpKey(bind.key, cmd.help);
326 end;
327 end;
328 end;
330 //winHelp.appendChild(llb);
332 uiLayoutCtl(winHelp);
333 winHelp.escClose := true;
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
492 begin
493 if (arg = 0) then exit;
494 createHelpWindow();
495 end;
496 if (arg < 0) then begin if not uiVisibleWindow(winHelp) then uiAddWindow(winHelp) else uiRemoveWindow(winHelp); end
497 else if (arg = 0) then begin if uiVisibleWindow(winHelp) then uiRemoveWindow(winHelp); end
498 else begin if (not uiVisibleWindow(winHelp)) then uiAddWindow(winHelp); end;
499 if (not uiVisibleWindow(winHelp)) then FreeAndNil(winHelp);
500 end;
502 procedure toggleOptionsWindow (arg: Integer=-1);
503 begin
504 if (winOptions = nil) then createOptionsWindow();
505 if (arg < 0) then begin if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions) else uiRemoveWindow(winOptions); end
506 else if (arg = 0) then begin if uiVisibleWindow(winOptions) then uiRemoveWindow(winOptions); end
507 else begin if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions); end
508 end;
511 // ////////////////////////////////////////////////////////////////////////// //
512 var
513 vpSet: Boolean = false;
514 vpx, vpy: Integer;
515 vpw, vph: Integer;
516 laserSet: Boolean = false;
517 laserX0, laserY0, laserX1, laserY1: Integer;
518 monMarkedUID: Integer = -1;
519 platMarkedGUID: Integer = -1;
522 procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer);
523 begin
524 vpSet := true;
525 vpx := viewPortX;
526 vpy := viewPortY;
527 end;
529 procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer);
530 begin
531 vpSet := true;
532 vpw := viewPortW;
533 vph := viewPortH;
534 end;
536 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
537 begin
538 laserSet := true;
539 laserX0 := ax0;
540 laserY0 := ay0;
541 laserX1 := ax1;
542 laserY1 := ay1;
543 laserSet := laserSet; // shut up, fpc!
544 end;
547 function pmsCurMapX (): Integer; inline; begin result := round(msX/g_dbg_scale)+vpx; end;
548 function pmsCurMapY (): Integer; inline; begin result := round(msY/g_dbg_scale)+vpy; end;
551 {$IFDEF HOLMES_OLD_OUTLINES}
552 var
553 edgeBmp: array of Byte = nil;
556 procedure drawOutlines ();
557 var
558 r, g, b: Integer;
560 procedure clearEdgeBmp ();
561 begin
562 SetLength(edgeBmp, (gWinSizeX+4)*(gWinSizeY+4));
563 FillChar(edgeBmp[0], Length(edgeBmp)*sizeof(edgeBmp[0]), 0);
564 end;
566 procedure drawPanel (pan: TPanel);
567 var
568 sx, len, y0, y1: Integer;
569 begin
570 if (pan = nil) or (pan.Width < 1) or (pan.Height < 1) then exit;
571 if (pan.X+pan.Width <= vpx-1) or (pan.Y+pan.Height <= vpy-1) then exit;
572 if (pan.X >= vpx+vpw+1) or (pan.Y >= vpy+vph+1) then exit;
573 if g_ol_nice or g_ol_fill_walls then
574 begin
575 sx := pan.X-(vpx-1);
576 len := pan.Width;
577 if (len > gWinSizeX+4) then len := gWinSizeX+4;
578 if (sx < 0) then begin len += sx; sx := 0; end;
579 if (sx+len > gWinSizeX+4) then len := gWinSizeX+4-sx;
580 if (len < 1) then exit;
581 assert(sx >= 0);
582 assert(sx+len <= gWinSizeX+4);
583 y0 := pan.Y-(vpy-1);
584 y1 := y0+pan.Height;
585 if (y0 < 0) then y0 := 0;
586 if (y1 > gWinSizeY+4) then y1 := gWinSizeY+4;
587 while (y0 < y1) do
588 begin
589 FillChar(edgeBmp[y0*(gWinSizeX+4)+sx], len*sizeof(edgeBmp[0]), 1);
590 Inc(y0);
591 end;
592 end
593 else
594 begin
595 drawRect(pan.X, pan.Y, pan.Width, pan.Height, r, g, b);
596 end;
597 end;
599 var
600 lsx: Integer = -1;
601 lex: Integer = -1;
602 lsy: Integer = -1;
604 procedure flushLine ();
605 begin
606 if (lsy > 0) and (lsx > 0) then
607 begin
608 if (lex = lsx) then
609 begin
610 glBegin(GL_POINTS);
611 glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
612 glEnd();
613 end
614 else
615 begin
616 glBegin(GL_LINES);
617 glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
618 glVertex2f(lex-0+vpx+0.37, lsy-1+vpy+0.37);
619 glEnd();
620 end;
621 end;
622 lsx := -1;
623 lex := -1;
624 end;
626 procedure startLine (y: Integer);
627 begin
628 flushLine();
629 lsy := y;
630 end;
632 procedure putPixel (x: Integer);
633 begin
634 if (x < 1) then exit;
635 if (lex+1 <> x) then flushLine();
636 if (lsx < 0) then lsx := x;
637 lex := x;
638 end;
640 procedure drawEdges ();
641 var
642 x, y: Integer;
643 a: PByte;
644 begin
645 glDisable(GL_BLEND);
646 glDisable(GL_TEXTURE_2D);
647 glLineWidth(1);
648 glPointSize(1);
649 glDisable(GL_LINE_SMOOTH);
650 glDisable(GL_POLYGON_SMOOTH);
651 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
652 for y := 1 to vph do
653 begin
654 a := @edgeBmp[y*(gWinSizeX+4)+1];
655 startLine(y);
656 for x := 1 to vpw do
657 begin
658 if (a[0] <> 0) then
659 begin
660 if (a[-1] = 0) or (a[1] = 0) or (a[-(gWinSizeX+4)] = 0) or (a[gWinSizeX+4] = 0) or
661 (a[-(gWinSizeX+4)-1] = 0) or (a[-(gWinSizeX+4)+1] = 0) or
662 (a[gWinSizeX+4-1] = 0) or (a[gWinSizeX+4+1] = 0) then
663 begin
664 putPixel(x);
665 end;
666 end;
667 Inc(a);
668 end;
669 flushLine();
670 end;
671 end;
673 procedure drawFilledWalls ();
674 var
675 x, y: Integer;
676 a: PByte;
677 begin
678 glDisable(GL_BLEND);
679 glDisable(GL_TEXTURE_2D);
680 glLineWidth(1);
681 glPointSize(1);
682 glDisable(GL_LINE_SMOOTH);
683 glDisable(GL_POLYGON_SMOOTH);
684 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
685 for y := 1 to vph do
686 begin
687 a := @edgeBmp[y*(gWinSizeX+4)+1];
688 startLine(y);
689 for x := 1 to vpw do
690 begin
691 if (a[0] <> 0) then putPixel(x);
692 Inc(a);
693 end;
694 flushLine();
695 end;
696 end;
698 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
699 var
700 f: Integer;
701 pan: TPanel;
702 begin
703 r := ar;
704 g := ag;
705 b := ab;
706 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
707 for f := 0 to High(parr) do
708 begin
709 pan := parr[f];
710 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
711 if ((pan.PanelType and ptype) = 0) then continue;
712 drawPanel(pan);
713 end;
714 if g_ol_nice then drawEdges();
715 if g_ol_fill_walls then drawFilledWalls();
716 end;
718 var
719 xptag: Word;
721 function doWallCB (pan: TPanel; tag: Integer): Boolean;
722 begin
723 result := false; // don't stop
724 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
725 if ((pan.PanelType and xptag) = 0) then exit;
726 drawPanel(pan);
727 end;
729 procedure doWalls (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
730 begin
731 r := ar;
732 g := ag;
733 b := ab;
734 xptag := ptype;
735 if ((ptype and (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR)) <> 0) then ptype := GridTagWall or GridTagDoor
736 else panelTypeToTag(ptype);
737 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
738 mapGrid.forEachInAABB(vpx-1, vpy-1, vpw+2, vph+2, doWallCB, ptype);
739 if g_ol_nice then drawEdges();
740 if g_ol_fill_walls then drawFilledWalls();
741 end;
743 begin
744 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
745 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
746 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
747 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
748 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
749 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
750 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
751 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
752 end;
754 {$ELSE}
755 var
756 oliner: TOutliner = nil;
758 procedure drawOutlines ();
759 var
760 r, g, b: Integer;
762 procedure clearOliner ();
763 begin
764 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
765 if (oliner = nil) then oliner := TOutliner.Create(vpw+2, vph+2) else oliner.setup(vpw+2, vph+2);
766 end;
768 procedure drawOutline (ol: TOutliner; sx, sy: Integer);
769 procedure xline (x0, x1, y: Integer);
770 var
771 x: Integer;
772 begin
773 if (g_dbg_scale < 1.0) then
774 begin
775 glBegin(GL_POINTS);
776 for x := x0 to x1 do glVertex2f(sx+x+0.375, sy+y+0.375);
777 glEnd();
778 end
779 else
780 begin
781 glBegin(GL_QUADS);
782 glVertex2f(sx+x0+0, sy+y+0);
783 glVertex2f(sx+x1+1, sy+y+0);
784 glVertex2f(sx+x1+1, sy+y+1);
785 glVertex2f(sx+x0+0, sy+y+1);
786 glEnd();
787 end;
788 end;
789 var
790 y: Integer;
791 sp: TOutliner.TSpanX;
792 begin
793 if (ol = nil) then exit;
794 glPointSize(1);
795 glDisable(GL_POINT_SMOOTH);
796 for y := 0 to ol.height-1 do
797 begin
798 for sp in ol.eachSpanAtY(y) do
799 begin
800 if (g_dbg_scale <= 1.0) then
801 begin
802 glBegin(GL_POINTS);
803 glVertex2f(sx+sp.x0+0.375, sy+y+0.375);
804 glVertex2f(sx+sp.x1+0.375, sy+y+0.375);
805 glEnd();
806 end
807 else
808 begin
809 glBegin(GL_QUADS);
810 glVertex2f(sx+sp.x0+0, sy+y+0);
811 glVertex2f(sx+sp.x0+1, sy+y+0);
812 glVertex2f(sx+sp.x0+1, sy+y+1);
813 glVertex2f(sx+sp.x0+0, sy+y+1);
815 glVertex2f(sx+sp.x1+0, sy+y+0);
816 glVertex2f(sx+sp.x1+1, sy+y+0);
817 glVertex2f(sx+sp.x1+1, sy+y+1);
818 glVertex2f(sx+sp.x1+0, sy+y+1);
819 glEnd();
820 end;
821 end;
822 for sp in ol.eachSpanEdgeAtY(y, -1) do
823 begin
824 xline(sp.x0, sp.x1, y);
826 glBegin(GL_QUADS);
827 glVertex2f(sx+sp.x0+0, sy+y+0);
828 glVertex2f(sx+sp.x1+1, sy+y+0);
829 glVertex2f(sx+sp.x1+1, sy+y+1);
830 glVertex2f(sx+sp.x0+0, sy+y+1);
831 glEnd();
833 end;
834 for sp in ol.eachSpanEdgeAtY(y, +1) do
835 begin
836 xline(sp.x0, sp.x1, y);
838 glBegin(GL_QUADS);
839 glVertex2f(sx+sp.x0+0, sy+y+0);
840 glVertex2f(sx+sp.x1+1, sy+y+0);
841 glVertex2f(sx+sp.x1+1, sy+y+1);
842 glVertex2f(sx+sp.x0+0, sy+y+1);
843 glEnd();
845 end;
846 end;
847 end;
849 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
850 var
851 f: Integer;
852 pan: TPanel;
853 begin
854 r := ar;
855 g := ag;
856 b := ab;
857 if g_ol_nice then clearOliner();
858 hlmContext.color := TGxRGBA.Create(r, g, b);
859 for f := 0 to High(parr) do
860 begin
861 pan := parr[f];
862 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
863 if ((pan.PanelType and ptype) = 0) then continue;
864 if (pan.X > vpx+vpw+41) or (pan.Y > vpy+vph+41) then continue;
865 if (pan.X+pan.Width < vpx-41) then continue;
866 if (pan.Y+pan.Height < vpy-41) then continue;
867 if g_ol_nice then
868 begin
869 oliner.addRect(pan.X-(vpx+1), pan.Y-(vpy+1), pan.Width, pan.Height);
870 end;
871 if g_ol_fill_walls then
872 begin
873 hlmContext.fillRect(pan.X, pan.Y, pan.Width, pan.Height);
874 end
875 else if not g_ol_nice then
876 begin
877 hlmContext.rect(pan.X, pan.Y, pan.Width, pan.Height);
878 end;
879 end;
880 if g_ol_nice then
881 begin
882 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
883 drawOutline(oliner, vpx+1, vpy+1);
884 end;
885 end;
887 begin
888 if (vpw < 2) or (vph < 2) then exit;
889 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
890 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
891 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
892 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
893 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
894 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
895 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
896 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
897 end;
898 {$ENDIF}
901 procedure plrDebugDraw ();
902 procedure drawTileGrid ();
903 var
904 x, y: Integer;
905 begin
906 hlmContext.color := TGxRGBA.Create(96, 96, 96);
907 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
908 begin
909 hlmContext.line(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize);
910 end;
912 hlmContext.color := TGxRGBA.Create(96, 96, 96);
913 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
914 begin
915 hlmContext.line(mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0, mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0+y*mapGrid.gridHeight);
916 end;
917 end;
919 procedure drawAwakeCells ();
920 var
921 x, y: Integer;
922 begin
923 hlmContext.color := TGxRGBA.Create(128, 0, 128, 64);
924 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
925 begin
926 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
927 begin
928 if awmIsSetHolmes(x*mapGrid.tileSize+mapGrid.gridX0+1, y*mapGrid.tileSize++mapGrid.gridY0+1) then
929 begin
930 hlmContext.fillRect(x*mapGrid.tileSize++mapGrid.gridX0, y*mapGrid.tileSize++mapGrid.gridY0, monsGrid.tileSize, monsGrid.tileSize);
931 end;
932 end;
933 end;
934 end;
936 procedure drawTraceBox ();
937 var
938 plr: TPlayer;
939 px, py, pw, ph: Integer;
940 pdx, pdy: Integer;
941 ex, ey: Integer;
942 pan: TPanel;
943 begin
944 if (Length(gPlayers) < 1) then exit;
945 plr := gPlayers[0];
946 if (plr = nil) then exit;
947 plr.getMapBox(px, py, pw, ph);
948 hlmContext.color := TGxRGBA.Create(255, 0, 255, 200);
949 hlmContext.rect(px, py, pw, ph);
950 pdx := pmsCurMapX-(px+pw div 2);
951 pdy := pmsCurMapY-(py+ph div 2);
952 hlmContext.color := TGxRGBA.Create(255, 0, 255, 200);
953 hlmContext.line(px+pw div 2, py+ph div 2, px+pw div 2+pdx, py+ph div 2+pdy);
954 pan := mapGrid.traceBox(ex, ey, px, py, pw, ph, pdx, pdy, GridTagObstacle);
955 if (pan = nil) then
956 begin
957 hlmContext.color := TGxRGBA.Create(255, 255, 255, 180);
958 hlmContext.rect(px+pdx, py+pdy, pw, ph);
959 end
960 else
961 begin
962 hlmContext.color := TGxRGBA.Create(255, 255, 0, 180);
963 hlmContext.rect(px+pdx, py+pdy, pw, ph);
964 end;
965 hlmContext.color := TGxRGBA.Create(255, 127, 0, 180);
966 hlmContext.rect(ex, ey, pw, ph);
967 end;
969 procedure hilightCell (cx, cy: Integer);
970 begin
971 hlmContext.color := TGxRGBA.Create(0, 128, 0, 64);
972 hlmContext.fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize);
973 end;
975 procedure hilightBodyCells (proxyId: Integer);
976 var
977 pmark: PoolMark;
978 hitcount: Integer;
979 pcellxy: PGridCellCoord;
980 begin
981 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
982 pmark := framePool.mark();
983 hitcount := monsGrid.forEachBodyCell(proxyId);
984 pcellxy := PGridCellCoord(framePool.getPtr(pmark));
985 while (hitcount > 0) do
986 begin
987 hilightCell(pcellxy^.x, pcellxy^.y);
988 Inc(pcellxy);
989 Dec(hitcount);
990 end;
991 framePool.release(pmark);
992 end;
994 procedure hilightCell1 (cx, cy: Integer);
995 begin
996 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
997 cx := cx and (not (monsGrid.tileSize-1));
998 cy := cy and (not (monsGrid.tileSize-1));
999 hlmContext.color := TGxRGBA.Create(255, 255, 0, 92);
1000 hlmContext.fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize);
1001 end;
1003 function hilightWallTrc (pan: TPanel; tag: Integer; x, y, prevx, prevy: Integer): Boolean;
1004 begin
1005 result := false; // don't stop
1006 if (pan = nil) then exit; // cell completion, ignore
1007 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
1008 hlmContext.color := TGxRGBA.Create(0, 128, 128, 64);
1009 hlmContext.fillRect(pan.X, pan.Y, pan.Width, pan.Height);
1010 end;
1012 procedure monsCollector (mon: TMonster);
1013 var
1014 ex, ey: Integer;
1015 mx, my, mw, mh: Integer;
1016 begin
1017 mon.getMapBox(mx, my, mw, mh);
1018 hlmContext.color := TGxRGBA.Create(255, 255, 0, 160);
1019 hlmContext.rect(mx, my, mw, mh);
1020 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
1021 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
1022 begin
1023 //e_DrawPoint(8, ex, ey, 0, 255, 0);
1024 hlmContext.color := TGxRGBA.Create(0, 255, 0, 220);
1025 hlmContext.fillRect(ex-2, ey-2, 7, 7);
1026 end;
1027 end;
1029 procedure drawMonsterInfo (mon: TMonster);
1030 var
1031 mx, my, mw, mh: Integer;
1033 procedure drawMonsterTargetLine ();
1034 var
1035 emx, emy, emw, emh: Integer;
1036 enemy: TMonster;
1037 eplr: TPlayer;
1038 ex, ey: Integer;
1039 begin
1040 if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
1041 begin
1042 eplr := g_Player_Get(mon.MonsterTargetUID);
1043 if (eplr <> nil) then eplr.getMapBox(emx, emy, emw, emh) else exit;
1044 end
1045 else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then
1046 begin
1047 enemy := g_Monsters_ByUID(mon.MonsterTargetUID);
1048 if (enemy <> nil) then enemy.getMapBox(emx, emy, emw, emh) else exit;
1049 end
1050 else
1051 begin
1052 exit;
1053 end;
1054 mon.getMapBox(mx, my, mw, mh);
1055 hlmContext.color := TGxRGBA.Create(255, 0, 0);
1056 hlmContext.line(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2);
1057 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
1058 begin
1059 hlmContext.color := TGxRGBA.Create(0, 255, 0);
1060 hlmContext.line(mx+mw div 2, my+mh div 2, ex, ey);
1061 end;
1062 end;
1064 procedure drawLOS2Plr ();
1065 var
1066 emx, emy, emw, emh: Integer;
1067 eplr: TPlayer;
1068 ex, ey: Integer;
1069 begin
1070 eplr := gPlayers[0];
1071 if (eplr = nil) then exit;
1072 eplr.getMapBox(emx, emy, emw, emh);
1073 mon.getMapBox(mx, my, mw, mh);
1074 hlmContext.color := TGxRGBA.Create(255, 0, 0);
1075 hlmContext.line(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2);
1076 {$IF DEFINED(D2F_DEBUG)}
1077 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1078 {$ENDIF}
1079 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
1080 //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
1081 begin
1082 hlmContext.color := TGxRGBA.Create(0, 255, 0);
1083 hlmContext.line(mx+mw div 2, my+mh div 2, ex, ey);
1084 end;
1085 {$IF DEFINED(D2F_DEBUG)}
1086 mapGrid.dbgRayTraceTileHitCB := nil;
1087 {$ENDIF}
1088 end;
1090 begin
1091 if (mon = nil) then exit;
1092 mon.getMapBox(mx, my, mw, mh);
1093 //mx += mw div 2;
1095 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1096 hilightBodyCells(mon.proxyId);
1098 if showMonsInfo then
1099 begin
1100 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1101 hlmContext.font := 'msx6';
1102 hlmContext.color := TGxRGBA.Create(255, 127, 0);
1104 hlmContext.darkenRect(mx-4, my-7*hlmContext.charWidth(' ')-6, 110, 7*hlmContext.charWidth(' ')+6, 128);
1105 my -= 8;
1106 my -= 2;
1108 // type
1109 hlmContext.drawText(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID])); my -= hlmContext.charWidth(' ');
1110 // beh
1111 hlmContext.drawText(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)])); my -= hlmContext.charWidth(' ');
1112 // state
1113 hlmContext.drawText(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep])); my -= hlmContext.charWidth(' ');
1114 // health
1115 hlmContext.drawText(mx, my, Format('Health:%d', [mon.MonsterHealth])); my -= hlmContext.charWidth(' ');
1116 // ammo
1117 hlmContext.drawText(mx, my, Format('Ammo:%d', [mon.MonsterAmmo])); my -= hlmContext.charWidth(' ');
1118 // target
1119 hlmContext.drawText(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID])); my -= hlmContext.charWidth(' ');
1120 hlmContext.drawText(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime])); my -= hlmContext.charWidth(' ');
1121 end;
1123 drawMonsterTargetLine();
1124 if showMonsLOS2Plr then drawLOS2Plr();
1126 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1127 property MonsterPain: Integer read FPain write FPain;
1128 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1130 end;
1132 function highlightAllMonsterCells (mon: TMonster): Boolean;
1133 begin
1134 result := false; // don't stop
1135 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1136 hilightBodyCells(mon.proxyId);
1137 end;
1139 procedure drawSelectedPlatformCells ();
1140 var
1141 pan: TPanel;
1142 begin
1143 if not showGrid then exit;
1144 pan := g_Map_PanelByGUID(platMarkedGUID);
1145 if (pan = nil) then exit;
1146 //mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
1147 hilightBodyCells(pan.proxyId);
1148 hlmContext.color := TGxRGBA.Create(0, 200, 0, 200);
1149 hlmContext.rect(pan.x, pan.y, pan.width, pan.height);
1150 end;
1152 procedure drawTrigger (var trig: TTrigger);
1154 procedure drawPanelDest (pguid: Integer);
1155 var
1156 pan: TPanel;
1157 begin
1158 pan := g_Map_PanelByGUID(pguid);
1159 if (pan = nil) then exit;
1160 hlmContext.color := TGxRGBA.Create(255, 0, 255, 220);
1161 hlmContext.line(trig.trigCenter.x, trig.trigCenter.y, pan.x+pan.width div 2, pan.y+pan.height div 2);
1162 end;
1164 var
1165 tts: AnsiString;
1166 tx: Integer;
1167 begin
1168 hlmContext.font := 'msx6';
1169 hlmContext.color := TGxRGBA.Create(255, 0, 255, 96);
1170 hlmContext.fillRect(trig.x, trig.y, trig.width, trig.height);
1171 tts := trigType2Str(trig.TriggerType);
1172 tx := trig.x+(trig.width-Length(tts)*6) div 2;
1173 hlmContext.darkenRect(tx-2, trig.y-10, Length(tts)*6+4, 10, 64);
1174 hlmContext.color := TGxRGBA.Create(255, 127, 0);
1175 hlmContext.drawText(tx, trig.y-9, tts);
1176 tx := trig.x+(trig.width-Length(trig.mapId)*6) div 2;
1177 hlmContext.darkenRect(tx-2, trig.y-20, Length(trig.mapId)*6+4, 10, 64);
1178 hlmContext.color := TGxRGBA.Create(255, 255, 0);
1179 hlmContext.drawText(tx, trig.y-19, trig.mapId);
1180 drawPanelDest(trig.trigPanelGUID);
1181 case trig.TriggerType of
1182 TRIGGER_NONE: begin end;
1183 TRIGGER_EXIT: begin end;
1184 TRIGGER_TELEPORT: begin end;
1185 TRIGGER_OPENDOOR: begin end;
1186 TRIGGER_CLOSEDOOR: begin end;
1187 TRIGGER_DOOR: begin end;
1188 TRIGGER_DOOR5: begin end;
1189 TRIGGER_CLOSETRAP: begin end;
1190 TRIGGER_TRAP: begin end;
1191 TRIGGER_SECRET: begin end;
1192 TRIGGER_LIFTUP: begin end;
1193 TRIGGER_LIFTDOWN: begin end;
1194 TRIGGER_LIFT: begin end;
1195 TRIGGER_TEXTURE: begin end;
1196 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF, TRIGGER_PRESS:
1197 begin
1198 if (trig.trigDataRec.trigTWidth > 0) and (trig.trigDataRec.trigTHeight > 0) then
1199 begin
1200 hlmContext.color := TGxRGBA.Create(0, 255, 255, 42);
1201 hlmContext.fillRect(
1202 trig.trigDataRec.trigTX, trig.trigDataRec.trigTY,
1203 trig.trigDataRec.trigTWidth, trig.trigDataRec.trigTHeight);
1204 hlmContext.color := TGxRGBA.Create(255, 0, 255, 220);
1205 hlmContext.line(
1206 trig.trigCenter.x, trig.trigCenter.y,
1207 trig.trigDataRec.trigTX+trig.trigDataRec.trigTWidth div 2,
1208 trig.trigDataRec.trigTY+trig.trigDataRec.trigTHeight div 2);
1209 end;
1210 end;
1211 TRIGGER_SOUND: begin end;
1212 TRIGGER_SPAWNMONSTER: begin end;
1213 TRIGGER_SPAWNITEM: begin end;
1214 TRIGGER_MUSIC: begin end;
1215 TRIGGER_PUSH: begin end;
1216 TRIGGER_SCORE: begin end;
1217 TRIGGER_MESSAGE: begin end;
1218 TRIGGER_DAMAGE: begin end;
1219 TRIGGER_HEALTH: begin end;
1220 TRIGGER_SHOT: begin end;
1221 TRIGGER_EFFECT: begin end;
1222 TRIGGER_SCRIPT: begin end;
1223 end;
1224 //trigType2Str
1225 //trigPanelId: Integer;
1226 end;
1228 procedure drawTriggers ();
1229 var
1230 f: Integer;
1231 begin
1232 for f := 0 to High(gTriggers) do drawTrigger(gTriggers[f]);
1233 end;
1235 procedure drawGibsBoxes ();
1236 var
1237 f: Integer;
1238 px, py, pw, ph: Integer;
1239 gib: PGib;
1240 begin
1241 for f := 0 to High(gGibs) do
1242 begin
1243 gib := @gGibs[f];
1244 if gib.alive then
1245 begin
1246 gib.getMapBox(px, py, pw, ph);
1247 hlmContext.color := TGxRGBA.Create(255, 0, 255);
1248 hlmContext.rect(px, py, pw, ph);
1249 end;
1250 end;
1251 end;
1253 var
1254 mon: TMonster;
1255 mx, my, mw, mh: Integer;
1256 //pan: TPanel;
1257 //ex, ey: Integer;
1258 pmark: PoolMark;
1259 hitcount: Integer;
1260 pmon: PMonster;
1261 begin
1262 if (gPlayer1 = nil) then exit;
1264 if (hlmContext = nil) then hlmContext := TGxContext.Create();
1266 gxSetContext(hlmContext);
1267 try
1268 //glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
1269 //hlmContext.clip := TGxRect.Create(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1272 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
1273 glTranslatef(-vpx, -vpy, 0);
1275 hlmContext.glSetScaleTrans(g_dbg_scale, -vpx, -vpy);
1276 glEnable(GL_SCISSOR_TEST);
1277 glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1279 if (showGrid) then drawTileGrid();
1280 drawOutlines();
1282 if (laserSet) then
1283 begin
1284 //g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
1285 pmark := framePool.mark();
1286 hitcount := monsGrid.forEachAlongLine(laserX0, laserY0, laserX1, laserY1, -1, true);
1287 pmon := PMonster(framePool.getPtr(pmark));
1288 while (hitcount > 0) do
1289 begin
1290 monsCollector(pmon^);
1291 Inc(pmon);
1292 Dec(hitcount);
1293 end;
1294 framePool.release(pmark);
1295 end;
1297 if (monMarkedUID <> -1) then
1298 begin
1299 mon := g_Monsters_ByUID(monMarkedUID);
1300 if (mon <> nil) then
1301 begin
1302 mon.getMapBox(mx, my, mw, mh);
1303 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
1304 hlmContext.color := TGxRGBA.Create(255, 0, 0, 220);
1305 hlmContext.rect(mx, my, mw, mh);
1306 drawMonsterInfo(mon);
1307 end;
1308 end;
1310 if showAllMonsCells and showGrid then g_Mons_ForEach(highlightAllMonsterCells);
1311 if showTriggers then drawTriggers();
1312 if showGrid then drawSelectedPlatformCells();
1314 //drawAwakeCells();
1316 if showTraceBox then drawTraceBox();
1318 //drawGibsBoxes();
1321 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1322 (*
1323 {$IF DEFINED(D2F_DEBUG)}
1324 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1325 {$ENDIF}
1326 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1327 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1328 {$IF DEFINED(D2F_DEBUG)}
1329 mapGrid.dbgRayTraceTileHitCB := nil;
1330 {$ENDIF}
1332 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1333 if (pan <> nil) then writeln('hit!');
1334 *)
1336 finally
1337 gxSetContext(nil);
1338 end;
1340 if showMapCurPos then
1341 begin
1342 gxSetContext(hlmContext);
1343 hlmContext.font := 'win8';
1344 hlmContext.color := TGxRGBA.Create(255, 255, 0);
1345 hlmContext.drawText(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]));
1346 gxSetContext(nil);
1347 end;
1348 end;
1351 // ////////////////////////////////////////////////////////////////////////// //
1352 procedure onKeyEvent (var ev: TFUIEvent);
1353 {$IF DEFINED(D2F_DEBUG)}
1354 var
1355 pan: TPanel;
1356 ex, ey: Integer;
1357 dx, dy: Integer;
1358 {$ENDIF}
1360 procedure dummyWallTrc (cx, cy: Integer);
1361 begin
1362 end;
1364 begin
1365 // press
1366 if (ev.press) then
1367 begin
1368 {$IF DEFINED(D2F_DEBUG)}
1369 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1370 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
1371 ((ev.kstate and TFUIEvent.ModCtrl) <> 0) then
1372 begin
1373 ev.eat();
1374 dx := pmsCurMapX;
1375 dy := pmsCurMapY;
1376 case ev.scan of
1377 SDL_SCANCODE_UP: dy -= 120;
1378 SDL_SCANCODE_DOWN: dy += 120;
1379 SDL_SCANCODE_LEFT: dx -= 120;
1380 SDL_SCANCODE_RIGHT: dx += 120;
1381 end;
1382 {$IF DEFINED(D2F_DEBUG)}
1383 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1384 mapGrid.dbgShowTraceLog := true;
1385 {$ENDIF}
1386 pan := g_Map_traceToNearest(pmsCurMapX, pmsCurMapY, dx, dy, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
1387 {$IF DEFINED(D2F_DEBUG)}
1388 //mapGrid.dbgRayTraceTileHitCB := nil;
1389 mapGrid.dbgShowTraceLog := false;
1390 {$ENDIF}
1391 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, dx, dy, ex, ey, (pan <> nil)]);
1392 exit;
1393 end;
1394 {$ENDIF}
1395 end;
1396 end;
1399 // ////////////////////////////////////////////////////////////////////////// //
1400 procedure g_Holmes_OnEvent (var ev: TFUIEvent);
1401 {$IF not DEFINED(HEADLESS)}
1402 var
1403 doeat: Boolean = false;
1404 {$ENDIF}
1405 begin
1406 {$IF not DEFINED(HEADLESS)}
1407 if g_Game_IsNet then exit;
1408 if not g_holmes_enabled then exit;
1409 if g_holmes_imfunctional then exit;
1411 holmesInitCommands();
1412 holmesInitBinds();
1414 msB := ev.bstate;
1415 kbS := ev.kstate;
1417 if (ev.key) then
1418 begin
1419 case ev.scan of
1420 SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL,
1421 SDL_SCANCODE_LALT, SDL_SCANCODE_RALT,
1422 SDL_SCANCODE_LSHIFT, SDL_SCANCODE_RSHIFT:
1423 doeat := true;
1424 end;
1425 end
1426 else if (ev.mouse) then
1427 begin
1428 msX := ev.x;
1429 msY := ev.y;
1430 msB := ev.bstate;
1431 kbS := ev.kstate;
1432 msB := msB;
1433 end;
1435 uiDispatchEvent(ev);
1436 if (not ev.alive) then exit;
1438 if (ev.mouse) then
1439 begin
1440 if (gPlayer1 <> nil) and (vpSet) then msbindExecute(ev);
1441 ev.eat();
1442 end
1443 else
1444 begin
1445 if keybindExecute(ev) then ev.eat();
1446 if (ev.alive) then onKeyEvent(ev);
1447 end;
1449 if (doeat) then ev.eat();
1450 {$ENDIF}
1451 end;
1454 // ////////////////////////////////////////////////////////////////////////// //
1455 procedure g_Holmes_Draw ();
1456 begin
1457 if g_Game_IsNet then exit;
1458 if not g_holmes_enabled then exit;
1459 if g_holmes_imfunctional then exit;
1461 {$IF not DEFINED(HEADLESS)}
1462 holmesInitCommands();
1463 holmesInitBinds();
1465 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
1466 glDisable(GL_STENCIL_TEST);
1467 glDisable(GL_BLEND);
1468 glDisable(GL_SCISSOR_TEST);
1469 glDisable(GL_TEXTURE_2D);
1471 if gGameOn then plrDebugDraw();
1472 {$ENDIF}
1474 laserSet := false;
1475 end;
1478 procedure g_Holmes_DrawUI ();
1479 begin
1480 if g_Game_IsNet then exit;
1481 if not g_holmes_enabled then exit;
1482 if g_holmes_imfunctional then exit;
1484 {$IF not DEFINED(HEADLESS)}
1485 gGfxDoClear := false;
1486 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1487 uiDraw();
1488 glMatrixMode(GL_MODELVIEW);
1489 glPushMatrix();
1490 try
1491 //glLoadIdentity();
1492 if assigned(postrenderFrameCB) then postrenderFrameCB();
1493 finally
1494 glPopMatrix();
1495 end;
1496 {$ENDIF}
1497 end;
1500 // ////////////////////////////////////////////////////////////////////////// //
1501 procedure bcOneMonsterThinkStep (); begin gmon_debug_think := false; gmon_debug_one_think_step := true; end;
1502 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active := false; g_dbgpan_mplat_step := true; end;
1503 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active := not g_dbgpan_mplat_active; end;
1505 procedure bcToggleMonsterInfo (arg: Integer=-1); begin if (arg < 0) then showMonsInfo := not showMonsInfo else showMonsInfo := (arg > 0); end;
1506 procedure bcToggleMonsterLOSPlr (arg: Integer=-1); begin if (arg < 0) then showMonsLOS2Plr := not showMonsLOS2Plr else showMonsLOS2Plr := (arg > 0); end;
1507 procedure bcToggleMonsterCells (arg: Integer=-1); begin if (arg < 0) then showAllMonsCells := not showAllMonsCells else showAllMonsCells := (arg > 0); end;
1508 procedure bcToggleDrawTriggers (arg: Integer=-1); begin if (arg < 0) then showTriggers := not showTriggers else showTriggers := (arg > 0); end;
1510 procedure bcToggleCurPos (arg: Integer=-1); begin if (arg < 0) then showMapCurPos := not showMapCurPos else showMapCurPos := (arg > 0); end;
1511 procedure bcToggleGrid (arg: Integer=-1); begin if (arg < 0) then showGrid := not showGrid else showGrid := (arg > 0); end;
1513 procedure bcMonsterSpawn (s: AnsiString);
1514 var
1515 mon: TMonster;
1516 begin
1517 if not gGameOn or g_Game_IsClient then
1518 begin
1519 conwriteln('cannot spawn monster in this mode');
1520 exit;
1521 end;
1522 mon := g_Mons_SpawnAt(s, pmsCurMapX, pmsCurMapY);
1523 if (mon = nil) then begin conwritefln('unknown monster id: ''%s''', [s]); exit; end;
1524 monMarkedUID := mon.UID;
1525 end;
1527 procedure bcMonsterWakeup ();
1528 var
1529 mon: TMonster;
1530 begin
1531 if (monMarkedUID <> -1) then
1532 begin
1533 mon := g_Monsters_ByUID(monMarkedUID);
1534 if (mon <> nil) then mon.WakeUp();
1535 end;
1536 end;
1538 procedure bcPlayerTeleport ();
1539 var
1540 x, y, w, h: Integer;
1541 begin
1542 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1543 if (gPlayers[0] <> nil) then
1544 begin
1545 gPlayers[0].getMapBox(x, y, w, h);
1546 gPlayers[0].TeleportTo(pmsCurMapX-w div 2, pmsCurMapY-h div 2, true, 69); // 69: don't change dir
1547 end;
1548 end;
1550 procedure dbgToggleTraceBox (arg: Integer=-1); begin if (arg < 0) then showTraceBox := not showTraceBox else showTraceBox := (arg > 0); end;
1552 procedure dbgToggleHolmesPause (arg: Integer=-1); begin if (arg < 0) then g_Game_HolmesPause(not gPauseHolmes) else g_Game_HolmesPause(arg > 0); end;
1554 procedure cbAtcurSelectMonster ();
1555 function monsAtDump (mon: TMonster{; tag: Integer}): Boolean;
1556 begin
1557 result := true; // stop
1558 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), TMsgType.Notify);
1559 monMarkedUID := mon.UID;
1560 dumpPublishedProperties(mon);
1561 end;
1562 var
1563 plr: TPlayer;
1564 x, y, w, h: Integer;
1565 pmark: PoolMark;
1566 hitcount: Integer;
1567 pmon: PMonster;
1568 begin
1569 monMarkedUID := -1;
1570 if (Length(gPlayers) > 0) then
1571 begin
1572 plr := gPlayers[0];
1573 if (plr <> nil) then
1574 begin
1575 plr.getMapBox(x, y, w, h);
1576 if (pmsCurMapX >= x) and (pmsCurMapY >= y) and (pmsCurMapX < x+w) and (pmsCurMapY < y+h) then
1577 begin
1578 dumpPublishedProperties(plr);
1579 end;
1580 end;
1581 end;
1582 //e_WriteLog('===========================', MSG_NOTIFY);
1583 pmark := framePool.mark();
1584 hitcount := monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY);
1585 pmon := PMonster(framePool.getPtr(pmark));
1586 while (hitcount > 0) do
1587 begin
1588 monsAtDump(pmon^);
1589 Inc(pmon);
1590 Dec(hitcount);
1591 end;
1592 framePool.release(pmark);
1593 //e_WriteLog('---------------------------', MSG_NOTIFY);
1594 end;
1596 procedure cbAtcurDumpMonsters ();
1597 function monsAtDump (mon: TMonster{; tag: Integer}): Boolean;
1598 begin
1599 result := false; // don't stop
1600 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), TMsgType.Notify);
1601 end;
1602 var
1603 pmark: PoolMark;
1604 hitcount: Integer;
1605 pmon: PMonster;
1606 begin
1607 pmark := framePool.mark();
1608 hitcount := monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY);
1609 if (hitcount > 0) then
1610 begin
1611 e_WriteLog('===========================', TMsgType.Notify);
1612 pmon := PMonster(framePool.getPtr(pmark));
1613 while (hitcount > 0) do
1614 begin
1615 monsAtDump(pmon^);
1616 Inc(pmon);
1617 Dec(hitcount);
1618 end;
1619 e_WriteLog('---------------------------', TMsgType.Notify);
1620 end;
1621 framePool.release(pmark);
1622 end;
1624 procedure cbAtcurDumpWalls ();
1625 function wallToggle (pan: TPanel{; tag: Integer}): Boolean;
1626 begin
1627 result := false; // don't stop
1628 if (platMarkedGUID = -1) then platMarkedGUID := pan.guid;
1629 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]);
1630 dumpPublishedProperties(pan);
1631 end;
1632 var
1633 hasTrigs: Boolean = false;
1634 f: Integer;
1635 trig: PTrigger;
1636 pmark: PoolMark;
1637 hitcount: Integer;
1638 ppan: PPanel;
1639 begin
1640 platMarkedGUID := -1;
1641 pmark := framePool.mark();
1642 hitcount := mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, (GridTagWall or GridTagDoor));
1643 if (hitcount > 0) then
1644 begin
1645 e_WriteLog('=== TOGGLE WALL ===', TMsgType.Notify);
1646 ppan := PPanel(framePool.getPtr(pmark));
1647 while (hitcount > 0) do
1648 begin
1649 wallToggle(ppan^);
1650 Inc(ppan);
1651 Dec(hitcount);
1652 end;
1653 e_WriteLog('--- toggle wall ---', TMsgType.Notify);
1654 end;
1655 framePool.release(pmark);
1656 if showTriggers then
1657 begin
1658 for f := 0 to High(gTriggers) do
1659 begin
1660 trig := @gTriggers[f];
1661 if (pmsCurMapX >= trig.x) and (pmsCurMapY >= trig.y) and (pmsCurMapX < trig.x+trig.width) and (pmsCurMapY < trig.y+trig.height) then
1662 begin
1663 if not hasTrigs then begin writeln('=== TRIGGERS ==='); hasTrigs := true; end;
1664 writeln('trigger ''', trig.mapId, ''' of type ''', trigType2Str(trig.TriggerType), '''');
1665 end;
1666 end;
1667 if hasTrigs then writeln('--- triggers ---');
1668 end;
1669 end;
1671 procedure cbAtcurToggleWalls ();
1672 function wallToggle (pan: TPanel{; tag: Integer}): Boolean;
1673 begin
1674 result := false; // don't stop
1675 //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);
1676 if pan.Enabled then g_Map_DisableWallGUID(pan.guid) else g_Map_EnableWallGUID(pan.guid);
1677 end;
1678 var
1679 pmark: PoolMark;
1680 hitcount: Integer;
1681 ppan: PPanel;
1682 begin
1683 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1684 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1685 pmark := framePool.mark();
1686 hitcount := mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, (GridTagWall or GridTagDoor));
1687 ppan := PPanel(framePool.getPtr(pmark));
1688 while (hitcount > 0) do
1689 begin
1690 wallToggle(ppan^);
1691 Inc(ppan);
1692 Dec(hitcount);
1693 end;
1694 framePool.release(pmark);
1695 end;
1698 // ////////////////////////////////////////////////////////////////////////// //
1699 procedure holmesInitCommands ();
1700 begin
1701 if (cmdlist <> nil) then exit;
1702 cmdAdd('win_layers', toggleLayersWindow, 'toggle layers window', 'window control');
1703 cmdAdd('win_outline', toggleOutlineWindow, 'toggle outline window', 'window control');
1704 cmdAdd('win_help', toggleHelpWindow, 'toggle help window', 'window control');
1705 cmdAdd('win_options', toggleOptionsWindow, 'toggle options window', 'window control');
1707 cmdAdd('mon_think_step', bcOneMonsterThinkStep, 'one monster think step', 'monster control');
1708 cmdAdd('mon_info', bcToggleMonsterInfo, 'toggle monster info', 'monster control');
1709 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr, 'toggle monster LOS to player', 'monster control');
1710 cmdAdd('mon_cells', bcToggleMonsterCells, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1711 cmdAdd('mon_wakeup', bcMonsterWakeup, 'wake up selected monster', 'monster control');
1713 cmdAdd('mon_spawn', bcMonsterSpawn, 'spawn monster', 'monster control');
1715 cmdAdd('mplat_step', bcOneMPlatThinkStep, 'one mplat think step', 'mplat control');
1716 cmdAdd('mplat_toggle', bcMPlatToggle, 'activate/deactivate moving platforms', 'mplat control');
1718 cmdAdd('plr_teleport', bcPlayerTeleport, 'teleport player', 'player control');
1720 cmdAdd('dbg_curpos', bcToggleCurPos, 'toggle "show cursor position on the map"', 'various');
1721 cmdAdd('dbg_grid', bcToggleGrid, 'toggle grid', 'various');
1722 cmdAdd('dbg_triggers', bcToggleDrawTriggers, 'show/hide triggers (SLOW!)', 'various');
1724 cmdAdd('atcur_select_monster', cbAtcurSelectMonster, 'select monster to operate', 'monster control');
1725 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters, 'dump monsters in cell', 'monster control');
1726 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls, 'dump walls in cell', 'wall control');
1727 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls, 'disable walls', 'wall control');
1729 cmdAdd('dbg_tracebox', dbgToggleTraceBox, 'test traceBox()', 'player control');
1731 cmdAdd('hlm_pause', dbgToggleHolmesPause, '"Holmes" pause mode', 'game control');
1732 end;
1735 procedure holmesInitBinds ();
1736 var
1737 st: TStream = nil;
1738 pr: TTextParser = nil;
1739 s, kn, v: AnsiString;
1740 kmods: Byte;
1741 mbuts: Byte;
1742 begin
1743 kbS := kbS;
1744 if not keybindsInited then
1745 begin
1746 // keyboard
1747 keybindAdd('F1', 'win_help');
1748 keybindAdd('M-F1', 'win_options');
1749 keybindAdd('C-O', 'win_outline');
1750 keybindAdd('C-L', 'win_layers');
1752 keybindAdd('M-M', 'mon_think_step');
1753 keybindAdd('M-I', 'mon_info');
1754 keybindAdd('M-L', 'mon_los_plr');
1755 keybindAdd('M-G', 'mon_cells');
1756 keybindAdd('M-A', 'mon_wakeup');
1758 keybindAdd('M-P', 'mplat_step');
1759 keybindAdd('M-O', 'mplat_toggle');
1761 keybindAdd('C-T', 'plr_teleport');
1762 keybindAdd('M-T', 'dbg_tracebox');
1764 keybindAdd('C-P', 'dbg_curpos');
1765 keybindAdd('C-G', 'dbg_grid');
1766 keybindAdd('C-X', 'dbg_triggers');
1768 keybindAdd('C-1', 'mon_spawn zombie');
1770 keybindAdd('C-S-P', 'hlm_pause');
1772 // mouse
1773 msbindAdd('LMB', 'atcur_select_monster');
1774 msbindAdd('M-LMB', 'atcur_dump_monsters');
1775 msbindAdd('RMB', 'atcur_dump_walls');
1776 msbindAdd('M-RMB', 'atcur_disable_walls');
1778 // load bindings from file
1779 try
1780 st := openDiskFileRO(GameDir+'holmes.rc');
1781 pr := TFileTextParser.Create(st);
1782 conwriteln('parsing "holmes.rc"...');
1783 while (pr.tokType <> pr.TTEOF) do
1784 begin
1785 s := pr.expectId();
1786 if (s = 'stop') then break
1787 else if (s = 'unbind_keys') then keybinds := nil
1788 else if (s = 'unbind_mouse') then msbinds := nil
1789 else if (s = 'bind') then
1790 begin
1791 if (pr.tokType = pr.TTStr) then s := pr.expectStr(false)
1792 else if (pr.tokType = pr.TTInt) then s := Format('%d', [pr.expectInt()])
1793 else s := pr.expectId();
1795 if (pr.tokType = pr.TTStr) then v := pr.expectStr(false)
1796 else if (pr.tokType = pr.TTInt) then v := Format('%d', [pr.expectInt()])
1797 else v := pr.expectId();
1799 kn := parseModKeys(s, kmods, mbuts);
1800 if (CompareText(kn, 'lmb') = 0) or (CompareText(kn, 'rmb') = 0) or (CompareText(kn, 'mmb') = 0) or (CompareText(kn, 'None') = 0) then
1801 begin
1802 msbindAdd(s, v);
1803 end
1804 else
1805 begin
1806 keybindAdd(s, v);
1807 end;
1808 end;
1809 end;
1810 except on e: Exception do // sorry
1811 if (pr <> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr.tokLine, pr.tokCol, e.message]);
1812 end;
1813 if (pr <> nil) then pr.Free() else st.Free(); // ownership
1814 end;
1815 end;
1818 begin
1819 // shut up, fpc!
1820 msB := msB;
1821 vpSet := vpSet;
1823 fuiEventCB := g_Holmes_OnEvent;
1824 //uiContext.font := 'win14';
1826 conRegVar('hlm_ui_scale', @fuiRenderScale, 0.01, 5.0, 'Holmes UI scale', '', false);
1827 end.