DEADSOFTWARE

Holmes' outline fixes; outlines are colored 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 e_log,
23 g_textures, g_basic, e_graphics, g_phys, g_grid, g_player, g_monsters,
24 g_window, g_map, g_triggers, g_items, g_game, g_panel, g_console,
25 xprofiler;
28 type
29 THMouseEvent = record
30 public
31 const
32 // both for but and for bstate
33 Left = $0001;
34 Right = $0002;
35 Middle = $0004;
36 WheelUp = $0008;
37 WheelDown = $0010;
39 // event types
40 Release = 0;
41 Press = 1;
42 Motion = 2;
44 public
45 kind: Byte; // motion, press, release
46 x, y: Integer;
47 dx, dy: Integer; // for wheel this is wheel motion, otherwise this is relative mouse motion
48 but: Word; // current pressed/released button, or 0 for motion
49 bstate: Word; // button state
50 kstate: Word; // keyboard state (see THKeyEvent);
51 end;
53 THKeyEvent = record
54 public
55 const
56 // modifiers
57 ModCtrl = $0001;
58 ModAlt = $0002;
59 ModShift = $0004;
61 // event types
62 Release = 0;
63 Press = 1;
65 public
66 kind: Byte;
67 scan: Word; // SDL_SCANCODE_XXX
68 sym: Word; // SDLK_XXX
69 bstate: Word; // button state
70 kstate: Word; // keyboard state
71 end;
74 procedure g_Holmes_VidModeChanged ();
75 procedure g_Holmes_WindowFocused ();
76 procedure g_Holmes_WindowBlured ();
78 procedure g_Holmes_Draw ();
79 procedure g_Holmes_DrawUI ();
81 function g_Holmes_MouseEvent (var ev: THMouseEvent): Boolean; // returns `true` if event was eaten
82 function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean; // returns `true` if event was eaten
84 // hooks for player
85 procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer);
86 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
89 var
90 g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
93 implementation
95 uses
96 SysUtils, GL, SDL2,
97 MAPDEF, g_options;
100 var
101 //globalInited: Boolean = false;
102 msX: Integer = -666;
103 msY: Integer = -666;
104 msB: Word = 0; // button state
105 kbS: Word = 0; // keyboard modifiers state
106 showGrid: Boolean = true;
107 showMonsInfo: Boolean = false;
108 showMonsLOS2Plr: Boolean = false;
109 showAllMonsCells: Boolean = false;
110 showMapCurPos: Boolean = false;
111 showLayersWindow: Boolean = false;
112 showOutlineWindow: Boolean = false;
113 oldShowLayersWindow: Boolean = false;
114 oldShowOutlineWindow: Boolean = false;
116 // ////////////////////////////////////////////////////////////////////////// //
117 {$INCLUDE g_holmes.inc}
118 {$INCLUDE g_holmes_ui.inc}
121 // ////////////////////////////////////////////////////////////////////////// //
122 var
123 g_ol_nice: Boolean = false;
124 g_ol_fill_walls: Boolean = false;
125 g_ol_rlayer_back: Boolean = false;
126 g_ol_rlayer_step: Boolean = false;
127 g_ol_rlayer_wall: Boolean = false;
128 g_ol_rlayer_door: Boolean = false;
129 g_ol_rlayer_acid1: Boolean = false;
130 g_ol_rlayer_acid2: Boolean = false;
131 g_ol_rlayer_water: Boolean = false;
132 g_ol_rlayer_fore: Boolean = false;
135 // ////////////////////////////////////////////////////////////////////////// //
136 var
137 winOptions: THTopWindow = nil;
138 winLayers: THTopWindow = nil;
139 winOutlines: THTopWindow = nil;
142 procedure createOptionsWindow ();
143 var
144 llb: THCtlCBListBox;
145 begin
146 llb := THCtlCBListBox.Create(0, 0);
147 llb.appendItem('map grid', @showGrid);
148 llb.appendItem('cursor position on map', @showMapCurPos);
149 llb.appendItem('monster info', @showMonsInfo);
150 llb.appendItem('monster LOS to player', @showMonsLOS2Plr);
151 llb.appendItem('monster cells (SLOW!)', @showAllMonsCells);
152 llb.appendItem('', nil);
153 llb.appendItem('layers window', @showLayersWindow);
154 llb.appendItem('outline window', @showOutlineWindow);
155 winOptions := THTopWindow.Create('Holmes Options', 100, 100);
156 winOptions.escClose := true;
157 winOptions.appendChild(llb);
158 end;
161 procedure createLayersWindow ();
162 var
163 llb: THCtlCBListBox;
164 begin
165 llb := THCtlCBListBox.Create(0, 0);
166 llb.appendItem('background', @g_rlayer_back);
167 llb.appendItem('steps', @g_rlayer_step);
168 llb.appendItem('walls', @g_rlayer_wall);
169 llb.appendItem('doors', @g_rlayer_door);
170 llb.appendItem('acid1', @g_rlayer_acid1);
171 llb.appendItem('acid2', @g_rlayer_acid2);
172 llb.appendItem('water', @g_rlayer_water);
173 llb.appendItem('foreground', @g_rlayer_fore);
174 winLayers := THTopWindow.Create('visible', 10, 10);
175 winLayers.escClose := true;
176 winLayers.appendChild(llb);
177 end;
180 procedure createOutlinesWindow ();
181 var
182 llb: THCtlCBListBox;
183 begin
184 llb := THCtlCBListBox.Create(0, 0);
185 llb.appendItem('background', @g_ol_rlayer_back);
186 llb.appendItem('steps', @g_ol_rlayer_step);
187 llb.appendItem('walls', @g_ol_rlayer_wall);
188 llb.appendItem('doors', @g_ol_rlayer_door);
189 llb.appendItem('acid1', @g_ol_rlayer_acid1);
190 llb.appendItem('acid2', @g_ol_rlayer_acid2);
191 llb.appendItem('water', @g_ol_rlayer_water);
192 llb.appendItem('foreground', @g_ol_rlayer_fore);
193 llb.appendItem('', nil);
194 llb.appendItem('fill walls', @g_ol_fill_walls);
195 llb.appendItem('', nil);
196 llb.appendItem('slow''n''nice', @g_ol_nice);
197 winOutlines := THTopWindow.Create('outlines', 100, 10);
198 winOutlines.escClose := true;
199 winOutlines.appendChild(llb);
200 end;
203 // ////////////////////////////////////////////////////////////////////////// //
204 procedure g_Holmes_VidModeChanged ();
205 begin
206 e_WriteLog(Format('Holmes: videomode changed: %dx%d', [gScreenWidth, gScreenHeight]), MSG_NOTIFY);
207 // texture space is possibly lost here, idc
208 curtexid := 0;
209 font6texid := 0;
210 font8texid := 0;
211 prfont6texid := 0;
212 prfont8texid := 0;
213 //createCursorTexture();
214 end;
216 procedure g_Holmes_WindowFocused ();
217 begin
218 msB := 0;
219 kbS := 0;
220 end;
222 procedure g_Holmes_WindowBlured ();
223 begin
224 end;
227 // ////////////////////////////////////////////////////////////////////////// //
228 var
229 vpSet: Boolean = false;
230 vpx, vpy: Integer;
231 vpw, vph: Integer;
232 laserSet: Boolean = false;
233 laserX0, laserY0, laserX1, laserY1: Integer;
234 monMarkedUID: Integer = -1;
237 procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer);
238 begin
239 vpSet := true;
240 vpx := viewPortX;
241 vpy := viewPortY;
242 vpw := viewPortW;
243 vph := viewPortH;
244 end;
246 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
247 begin
248 laserSet := true;
249 laserX0 := ax0;
250 laserY0 := ay0;
251 laserX1 := ax1;
252 laserY1 := ay1;
253 laserSet := laserSet; // shut up, fpc!
254 end;
257 function pmsCurMapX (): Integer; inline; begin result := msX+vpx; end;
258 function pmsCurMapY (): Integer; inline; begin result := msY+vpy; end;
261 procedure plrDebugMouse (var ev: THMouseEvent);
263 function wallToggle (pan: TPanel; tag: Integer): Boolean;
264 begin
265 result := false; // don't stop
266 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);
267 if ((kbS and THKeyEvent.ModAlt) <> 0) then
268 begin
269 if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
270 end;
271 end;
273 function monsAtDump (mon: TMonster; tag: Integer): Boolean;
274 begin
275 result := false; // don't stop
276 e_WriteLog(Format('monster #%d; UID=%d', [mon.arrIdx, mon.UID]), MSG_NOTIFY);
277 monMarkedUID := mon.UID;
278 //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
279 end;
281 function monsInCell (mon: TMonster; tag: Integer): Boolean;
282 begin
283 result := false; // don't stop
284 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), MSG_NOTIFY);
285 end;
287 begin
288 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
289 if (gPlayer1 = nil) or not vpSet then exit;
290 if (ev.kind <> THMouseEvent.Press) then exit;
292 e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
294 if (ev.but = THMouseEvent.Left) then
295 begin
296 if ((kbS and THKeyEvent.ModShift) <> 0) then
297 begin
298 // dump monsters in cell
299 e_WriteLog('===========================', MSG_NOTIFY);
300 monsGrid.forEachInCell(pmsCurMapX, pmsCurMapY, monsInCell);
301 e_WriteLog('---------------------------', MSG_NOTIFY);
302 end
303 else
304 begin
305 // toggle wall
306 e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
307 mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
308 e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
309 end;
310 exit;
311 end;
313 if (ev.but = THMouseEvent.Right) then
314 begin
315 monMarkedUID := -1;
316 e_WriteLog('===========================', MSG_NOTIFY);
317 monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
318 e_WriteLog('---------------------------', MSG_NOTIFY);
319 exit;
320 end;
321 end;
324 var
325 edgeBmp: array of Byte = nil;
328 procedure drawOutlines ();
329 var
330 r, g, b: Integer;
332 procedure clearEdgeBmp ();
333 begin
334 SetLength(edgeBmp, (gWinSizeX+4)*(gWinSizeY+4));
335 FillChar(edgeBmp[0], Length(edgeBmp)*sizeof(edgeBmp[0]), 0);
336 end;
338 procedure drawPanel (pan: TPanel);
339 var
340 sx, len, y0, y1: Integer;
341 begin
342 if (pan = nil) or (pan.Width < 1) or (pan.Height < 1) then exit;
343 if (pan.X+pan.Width <= vpx-1) or (pan.Y+pan.Height <= vpy-1) then exit;
344 if (pan.X >= vpx+vpw+1) or (pan.Y >= vpy+vph+1) then exit;
345 if g_ol_nice or g_ol_fill_walls then
346 begin
347 sx := pan.X-(vpx-1);
348 len := pan.Width;
349 if (len > gWinSizeX+4) then len := gWinSizeX+4;
350 if (sx < 0) then begin len += sx; sx := 0; end;
351 if (sx+len > gWinSizeX+4) then len := gWinSizeX+4-sx;
352 if (len < 1) then exit;
353 assert(sx >= 0);
354 assert(sx+len <= gWinSizeX+4);
355 y0 := pan.Y-(vpy-1);
356 y1 := y0+pan.Height;
357 if (y0 < 0) then y0 := 0;
358 if (y1 > gWinSizeY+4) then y1 := gWinSizeY+4;
359 while (y0 < y1) do
360 begin
361 FillChar(edgeBmp[y0*(gWinSizeX+4)+sx], len*sizeof(edgeBmp[0]), 1);
362 Inc(y0);
363 end;
364 end
365 else
366 begin
367 drawRect(pan.X, pan.Y, pan.Width, pan.Height, r, g, b);
368 end;
369 end;
371 procedure drawEdges ();
372 var
373 x, y: Integer;
374 a: PByte;
375 begin
376 glDisable(GL_BLEND);
377 glDisable(GL_TEXTURE_2D);
378 glLineWidth(1);
379 glPointSize(1);
380 glDisable(GL_LINE_SMOOTH);
381 glDisable(GL_POLYGON_SMOOTH);
382 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
383 glBegin(GL_POINTS);
384 for y := 1 to vph do
385 begin
386 a := @edgeBmp[y*(gWinSizeX+4)+1];
387 for x := 1 to vpw do
388 begin
389 if (a[0] <> 0) then
390 begin
391 if (a[-1] = 0) or (a[1] = 0) or (a[-(gWinSizeX+4)] = 0) or (a[gWinSizeX+4] = 0) or
392 (a[-(gWinSizeX+4)-1] = 0) or (a[-(gWinSizeX+4)+1] = 0) or
393 (a[gWinSizeX+4-1] = 0) or (a[gWinSizeX+4+1] = 0) then
394 begin
395 glVertex2f(x-1+vpx+0.37, y-1+vpy+0.37);
396 end;
397 end;
398 Inc(a);
399 end;
400 end;
401 glEnd();
402 end;
404 procedure drawFilledWalls ();
405 var
406 x, y, sx, ex: Integer;
407 a: PByte;
408 procedure drawLine ();
409 begin
410 if (sx >= 0) then
411 begin
412 glVertex2f(sx-1+vpx+0.37, y-1+vpy+0.37);
413 glVertex2f(ex+vpx+0.37, y-1+vpy+0.37);
414 end;
415 sx := -1;
416 ex := -1;
417 end;
418 begin
419 glDisable(GL_BLEND);
420 glDisable(GL_TEXTURE_2D);
421 glLineWidth(1);
422 glPointSize(1);
423 glDisable(GL_LINE_SMOOTH);
424 glDisable(GL_POLYGON_SMOOTH);
425 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
426 glBegin(GL_LINES);
427 for y := 1 to vph do
428 begin
429 a := @edgeBmp[y*(gWinSizeX+4)+1];
430 sx := -1;
431 ex := -1;
432 for x := 1 to vpw do
433 begin
434 if (a[0] <> 0) then
435 begin
436 if (ex+1 <> x) then drawLine();
437 if (sx < 0) then
438 begin
439 sx := x;
440 ex := x;
441 end
442 else
443 begin
444 ex := x;
445 end;
446 end;
447 Inc(a);
448 end;
449 drawLine();
450 end;
451 glEnd();
452 end;
454 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
455 var
456 f: Integer;
457 pan: TPanel;
458 begin
459 r := ar;
460 g := ag;
461 b := ab;
462 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
463 for f := 0 to High(parr) do
464 begin
465 pan := parr[f];
466 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
467 if ((pan.PanelType and ptype) = 0) then continue;
468 drawPanel(pan);
469 end;
470 if g_ol_nice then drawEdges();
471 if g_ol_fill_walls then drawFilledWalls();
472 end;
474 var
475 xptag: Word;
477 function doWallCB (pan: TPanel; tag: Integer): Boolean;
478 begin
479 result := false; // don't stop
480 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
481 if ((pan.PanelType and xptag) = 0) then exit;
482 drawPanel(pan);
483 end;
485 procedure doWalls (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
486 begin
487 r := ar;
488 g := ag;
489 b := ab;
490 xptag := ptype;
491 if ((ptype and (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR)) <> 0) then ptype := GridTagWall or GridTagDoor
492 else panelTypeToTag(ptype);
493 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
494 mapGrid.forEachInAABB(vpx-1, vpy-1, vpw+2, vph+2, doWallCB, ptype);
495 if g_ol_nice then drawEdges();
496 if g_ol_fill_walls then drawFilledWalls();
497 end;
499 begin
500 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
501 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
502 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
503 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
504 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
505 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
506 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
507 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
508 end;
511 procedure plrDebugDraw ();
513 procedure drawTileGrid ();
514 var
515 x, y: Integer;
516 begin
517 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
518 begin
519 drawLine(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize, 96, 96, 96, 255);
520 end;
522 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
523 begin
524 drawLine(mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0, mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0+y*mapGrid.gridHeight, 96, 96, 96, 255);
525 end;
526 end;
528 procedure hilightCell (cx, cy: Integer);
529 begin
530 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 0, 128, 0, 64);
531 end;
533 procedure hilightCell1 (cx, cy: Integer);
534 begin
535 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
536 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 255, 255, 0, 92);
537 end;
539 function hilightWallTrc (pan: TPanel; tag: Integer; x, y, prevx, prevy: Integer): Boolean;
540 begin
541 result := false; // don't stop
542 if (pan = nil) then exit; // cell completion, ignore
543 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
544 fillRect(pan.X, pan.Y, pan.Width, pan.Height, 0, 128, 128, 64);
545 end;
547 function monsCollector (mon: TMonster; tag: Integer): Boolean;
548 var
549 ex, ey: Integer;
550 mx, my, mw, mh: Integer;
551 begin
552 result := false;
553 mon.getMapBox(mx, my, mw, mh);
554 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
555 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
556 begin
557 e_DrawPoint(8, ex, ey, 0, 255, 0);
558 end;
559 end;
561 procedure drawMonsterInfo (mon: TMonster);
562 var
563 mx, my, mw, mh: Integer;
565 procedure drawMonsterTargetLine ();
566 var
567 emx, emy, emw, emh: Integer;
568 enemy: TMonster;
569 eplr: TPlayer;
570 ex, ey: Integer;
571 begin
572 if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
573 begin
574 eplr := g_Player_Get(mon.MonsterTargetUID);
575 if (eplr <> nil) then eplr.getMapBox(emx, emy, emw, emh) else exit;
576 end
577 else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then
578 begin
579 enemy := g_Monsters_ByUID(mon.MonsterTargetUID);
580 if (enemy <> nil) then enemy.getMapBox(emx, emy, emw, emh) else exit;
581 end
582 else
583 begin
584 exit;
585 end;
586 mon.getMapBox(mx, my, mw, mh);
587 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 255);
588 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
589 begin
590 drawLine(mx+mw div 2, my+mh div 2, ex, ey, 0, 255, 0, 255);
591 end;
592 end;
594 procedure drawLOS2Plr ();
595 var
596 emx, emy, emw, emh: Integer;
597 eplr: TPlayer;
598 ex, ey: Integer;
599 begin
600 eplr := gPlayers[0];
601 if (eplr = nil) then exit;
602 eplr.getMapBox(emx, emy, emw, emh);
603 mon.getMapBox(mx, my, mw, mh);
604 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 255);
605 {$IF DEFINED(D2F_DEBUG)}
606 //mapGrid.dbgRayTraceTileHitCB := hilightCell1;
607 {$ENDIF}
608 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
609 //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
610 begin
611 drawLine(mx+mw div 2, my+mh div 2, ex, ey, 0, 255, 0, 255);
612 end;
613 {$IF DEFINED(D2F_DEBUG)}
614 //mapGrid.dbgRayTraceTileHitCB := nil;
615 {$ENDIF}
616 end;
618 begin
619 if (mon = nil) then exit;
620 mon.getMapBox(mx, my, mw, mh);
621 //mx += mw div 2;
623 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
625 if showMonsInfo then
626 begin
627 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
628 darkenRect(mx-4, my-7*8-6, 110, 7*8+6, 128);
629 my -= 8;
630 my -= 2;
632 // type
633 drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), 255, 127, 0); my -= 8;
634 // beh
635 drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), 255, 127, 0); my -= 8;
636 // state
637 drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), 255, 127, 0); my -= 8;
638 // health
639 drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), 255, 127, 0); my -= 8;
640 // ammo
641 drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), 255, 127, 0); my -= 8;
642 // target
643 drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8;
644 drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8;
645 end;
647 drawMonsterTargetLine();
648 if showMonsLOS2Plr then drawLOS2Plr();
650 property MonsterRemoved: Boolean read FRemoved write FRemoved;
651 property MonsterPain: Integer read FPain write FPain;
652 property MonsterAnim: Byte read FCurAnim write FCurAnim;
654 end;
656 function highlightAllMonsterCells (mon: TMonster): Boolean;
657 begin
658 result := false; // don't stop
659 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
660 end;
662 var
663 mon: TMonster;
664 mx, my, mw, mh: Integer;
665 begin
666 if (gPlayer1 = nil) then exit;
668 glEnable(GL_SCISSOR_TEST);
669 glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
671 glPushMatrix();
672 glTranslatef(-vpx, -vpy, 0);
674 if (showGrid) then drawTileGrid();
675 drawOutlines();
677 if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
679 if (monMarkedUID <> -1) then
680 begin
681 mon := g_Monsters_ByUID(monMarkedUID);
682 if (mon <> nil) then
683 begin
684 mon.getMapBox(mx, my, mw, mh);
685 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
686 drawMonsterInfo(mon);
687 end;
688 end;
690 if showAllMonsCells then g_Mons_ForEach(highlightAllMonsterCells);
692 glPopMatrix();
694 glDisable(GL_SCISSOR_TEST);
696 if showMapCurPos then drawText8(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]), 255, 255, 0);
697 end;
700 // ////////////////////////////////////////////////////////////////////////// //
701 function g_Holmes_MouseEvent (var ev: THMouseEvent): Boolean;
702 begin
703 result := true;
704 msX := ev.x;
705 msY := ev.y;
706 msB := ev.bstate;
707 kbS := ev.kstate;
708 msB := msB;
709 if not uiMouseEvent(ev) then plrDebugMouse(ev);
710 end;
713 function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean;
714 var
715 mon: TMonster;
716 pan: TPanel;
717 x, y, w, h: Integer;
718 ex, ey: Integer;
719 dx, dy: Integer;
721 procedure dummyWallTrc (cx, cy: Integer);
722 begin
723 end;
725 begin
726 result := false;
727 msB := ev.bstate;
728 kbS := ev.kstate;
729 case ev.scan of
730 SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL,
731 SDL_SCANCODE_LALT, SDL_SCANCODE_RALT,
732 SDL_SCANCODE_LSHIFT, SDL_SCANCODE_RSHIFT:
733 result := true;
734 end;
735 if uiKeyEvent(ev) then begin result := true; exit; end;
736 // press
737 if (ev.kind = THKeyEvent.Press) then
738 begin
739 // M-M: one monster think step
740 if (ev.scan = SDL_SCANCODE_M) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
741 begin
742 result := true;
743 gmon_debug_think := false;
744 gmon_debug_one_think_step := true; // do one step
745 exit;
746 end;
747 // M-I: toggle monster info
748 if (ev.scan = SDL_SCANCODE_I) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
749 begin
750 result := true;
751 showMonsInfo := not showMonsInfo;
752 exit;
753 end;
754 // M-L: toggle monster LOS to player
755 if (ev.scan = SDL_SCANCODE_L) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
756 begin
757 result := true;
758 showMonsLOS2Plr := not showMonsLOS2Plr;
759 exit;
760 end;
761 // M-G: toggle "show all cells occupied by monsters"
762 if (ev.scan = SDL_SCANCODE_G) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
763 begin
764 result := true;
765 showAllMonsCells := not showAllMonsCells;
766 exit;
767 end;
768 // M-A: wake up monster
769 if (ev.scan = SDL_SCANCODE_A) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
770 begin
771 result := true;
772 if (monMarkedUID <> -1) then
773 begin
774 mon := g_Monsters_ByUID(monMarkedUID);
775 if (mon <> nil) then mon.WakeUp();
776 end;
777 exit;
778 end;
779 // C-T: teleport player
780 if (ev.scan = SDL_SCANCODE_T) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
781 begin
782 result := true;
783 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
784 if (gPlayers[0] <> nil) then
785 begin
786 gPlayers[0].getMapBox(x, y, w, h);
787 gPlayers[0].TeleportTo(pmsCurMapX-w div 2, pmsCurMapY-h div 2, true, 69); // 69: don't change dir
788 end;
789 exit;
790 end;
791 // C-P: show cursor position on the map
792 if (ev.scan = SDL_SCANCODE_P) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
793 begin
794 result := true;
795 showMapCurPos := not showMapCurPos;
796 exit;
797 end;
798 // C-G: toggle grid
799 if (ev.scan = SDL_SCANCODE_G) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
800 begin
801 result := true;
802 showGrid := not showGrid;
803 exit;
804 end;
805 // C-L: toggle layers window
806 if (ev.scan = SDL_SCANCODE_L) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
807 begin
808 result := true;
809 showLayersWindow := not showLayersWindow;
810 exit;
811 end;
812 // C-O: toggle outlines window
813 if (ev.scan = SDL_SCANCODE_O) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
814 begin
815 result := true;
816 showOutlineWindow := not showOutlineWindow;
817 exit;
818 end;
819 // F1: toggle options window
820 if (ev.scan = SDL_SCANCODE_F1) and (ev.kstate = 0) then
821 begin
822 result := true;
823 if (winOptions = nil) then createOptionsWindow();
824 if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions) else uiRemoveWindow(winOptions);
825 exit;
826 end;
827 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
828 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
829 ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
830 begin
831 result := true;
832 dx := pmsCurMapX;
833 dy := pmsCurMapY;
834 case ev.scan of
835 SDL_SCANCODE_UP: dy -= 120;
836 SDL_SCANCODE_DOWN: dy += 120;
837 SDL_SCANCODE_LEFT: dx -= 120;
838 SDL_SCANCODE_RIGHT: dx += 120;
839 end;
840 {$IF DEFINED(D2F_DEBUG)}
841 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
842 mapGrid.dbgShowTraceLog := true;
843 {$ENDIF}
844 pan := g_Map_traceToNearest(pmsCurMapX, pmsCurMapY, dx, dy, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
845 {$IF DEFINED(D2F_DEBUG)}
846 //mapGrid.dbgRayTraceTileHitCB := nil;
847 mapGrid.dbgShowTraceLog := false;
848 {$ENDIF}
849 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, dx, dy, ex, ey, (pan <> nil)]);
850 exit;
851 end;
852 end;
853 end;
856 // ////////////////////////////////////////////////////////////////////////// //
857 procedure g_Holmes_Draw ();
858 begin
859 if (oldShowLayersWindow <> showLayersWindow) then
860 begin
861 oldShowLayersWindow := showLayersWindow;
862 if showLayersWindow then
863 begin
864 if (winLayers = nil) then createLayersWindow();
865 uiAddWindow(winLayers);
866 end
867 else
868 begin
869 uiRemoveWindow(winLayers);
870 end;
871 end
872 else
873 begin
874 showLayersWindow := uiVisibleWindow(winLayers);
875 oldShowLayersWindow := showLayersWindow;
876 end;
878 if (oldShowOutlineWindow <> showOutlineWindow) then
879 begin
880 oldShowOutlineWindow := showOutlineWindow;
881 if showOutlineWindow then
882 begin
883 if (winOutlines = nil) then createOutlinesWindow();
884 uiAddWindow(winOutlines);
885 end
886 else
887 begin
888 uiRemoveWindow(winOutlines);
889 end;
890 end
891 else
892 begin
893 showOutlineWindow := uiVisibleWindow(winOutlines);
894 oldShowOutlineWindow := showOutlineWindow;
895 end;
897 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
898 glDisable(GL_STENCIL_TEST);
899 glDisable(GL_BLEND);
900 glDisable(GL_SCISSOR_TEST);
901 glDisable(GL_TEXTURE_2D);
903 if gGameOn then
904 begin
905 plrDebugDraw();
906 end;
908 laserSet := false;
909 end;
912 procedure g_Holmes_DrawUI ();
913 begin
914 uiDraw();
915 drawCursor();
916 end;
919 end.