1 (* Copyright (C) DooM 2D:Forever Developers
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.
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.
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/>.
16 {$INCLUDE ../shared/a_modes.inc}
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
,
32 // both for but and for bstate
45 kind
: Byte; // motion, press, release
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);
67 scan
: Word; // SDL_SCANCODE_XXX
68 sym
: Word; // SDLK_XXX
69 bstate
: Word; // button state
70 kstate
: Word; // keyboard state
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
85 procedure g_Holmes_plrView (viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer);
86 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
90 g_holmes_enabled
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
101 //globalInited: Boolean = false;
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;
114 // ////////////////////////////////////////////////////////////////////////// //
115 {$INCLUDE g_holmes.inc}
116 {$INCLUDE g_holmes_ui.inc}
119 // ////////////////////////////////////////////////////////////////////////// //
121 g_ol_nice
: Boolean = false;
122 g_ol_fill_walls
: Boolean = false;
123 g_ol_rlayer_back
: Boolean = false;
124 g_ol_rlayer_step
: Boolean = false;
125 g_ol_rlayer_wall
: Boolean = false;
126 g_ol_rlayer_door
: Boolean = false;
127 g_ol_rlayer_acid1
: Boolean = false;
128 g_ol_rlayer_acid2
: Boolean = false;
129 g_ol_rlayer_water
: Boolean = false;
130 g_ol_rlayer_fore
: Boolean = false;
133 // ////////////////////////////////////////////////////////////////////////// //
135 winOptions
: THTopWindow
= nil;
136 winLayers
: THTopWindow
= nil;
137 winOutlines
: THTopWindow
= nil;
140 procedure winLayersClosed (me
: THControl
; dummy
: Integer); begin showLayersWindow
:= false; end;
141 procedure winOutlinesClosed (me
: THControl
; dummy
: Integer); begin showOutlineWindow
:= false; end;
143 procedure createLayersWindow ();
147 llb
:= THCtlCBListBox
.Create(0, 0);
148 llb
.appendItem('background', @g_rlayer_back
);
149 llb
.appendItem('steps', @g_rlayer_step
);
150 llb
.appendItem('walls', @g_rlayer_wall
);
151 llb
.appendItem('doors', @g_rlayer_door
);
152 llb
.appendItem('acid1', @g_rlayer_acid1
);
153 llb
.appendItem('acid2', @g_rlayer_acid2
);
154 llb
.appendItem('water', @g_rlayer_water
);
155 llb
.appendItem('foreground', @g_rlayer_fore
);
156 winLayers
:= THTopWindow
.Create('visible', 10, 10);
157 winLayers
.escClose
:= true;
158 winLayers
.appendChild(llb
);
159 winLayers
.closeCB
:= winLayersClosed
;
163 procedure createOutlinesWindow ();
167 llb
:= THCtlCBListBox
.Create(0, 0);
168 llb
.appendItem('background', @g_ol_rlayer_back
);
169 llb
.appendItem('steps', @g_ol_rlayer_step
);
170 llb
.appendItem('walls', @g_ol_rlayer_wall
);
171 llb
.appendItem('doors', @g_ol_rlayer_door
);
172 llb
.appendItem('acid1', @g_ol_rlayer_acid1
);
173 llb
.appendItem('acid2', @g_ol_rlayer_acid2
);
174 llb
.appendItem('water', @g_ol_rlayer_water
);
175 llb
.appendItem('foreground', @g_ol_rlayer_fore
);
176 llb
.appendItem('OPTIONS', nil);
177 llb
.appendItem('fill walls', @g_ol_fill_walls
);
178 llb
.appendItem('contours', @g_ol_nice
);
179 winOutlines
:= THTopWindow
.Create('outlines', 100, 10);
180 winOutlines
.escClose
:= true;
181 winOutlines
.appendChild(llb
);
182 winOutlines
.closeCB
:= winOutlinesClosed
;
186 procedure toggleLayersWindow (me
: THControl
; checked
: Integer);
188 if showLayersWindow
then
190 if (winLayers
= nil) then createLayersWindow();
191 uiAddWindow(winLayers
);
195 uiRemoveWindow(winLayers
);
200 procedure toggleOutlineWindow (me
: THControl
; checked
: Integer);
202 if showOutlineWindow
then
204 if (winOutlines
= nil) then createOutlinesWindow();
205 uiAddWindow(winOutlines
);
209 uiRemoveWindow(winOutlines
);
214 procedure createOptionsWindow ();
218 llb
:= THCtlCBListBox
.Create(0, 0);
219 llb
.appendItem('map grid', @showGrid
);
220 llb
.appendItem('cursor position on map', @showMapCurPos
);
221 llb
.appendItem('monster info', @showMonsInfo
);
222 llb
.appendItem('monster LOS to player', @showMonsLOS2Plr
);
223 llb
.appendItem('monster cells (SLOW!)', @showAllMonsCells
);
224 llb
.appendItem('WINDOWS', nil);
225 llb
.appendItem('layers window', @showLayersWindow
, toggleLayersWindow
);
226 llb
.appendItem('outline window', @showOutlineWindow
, toggleOutlineWindow
);
227 winOptions
:= THTopWindow
.Create('Holmes Options', 100, 100);
228 winOptions
.escClose
:= true;
229 winOptions
.appendChild(llb
);
233 // ////////////////////////////////////////////////////////////////////////// //
234 procedure g_Holmes_VidModeChanged ();
236 e_WriteLog(Format('Holmes: videomode changed: %dx%d', [gScreenWidth
, gScreenHeight
]), MSG_NOTIFY
);
237 // texture space is possibly lost here, idc
243 //createCursorTexture();
246 procedure g_Holmes_WindowFocused ();
252 procedure g_Holmes_WindowBlured ();
257 // ////////////////////////////////////////////////////////////////////////// //
259 vpSet
: Boolean = false;
262 laserSet
: Boolean = false;
263 laserX0
, laserY0
, laserX1
, laserY1
: Integer;
264 monMarkedUID
: Integer = -1;
267 procedure g_Holmes_plrView (viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer);
276 procedure g_Holmes_plrLaser (ax0
, ay0
, ax1
, ay1
: Integer);
283 laserSet
:= laserSet
; // shut up, fpc!
287 function pmsCurMapX (): Integer; inline; begin result
:= msX
+vpx
; end;
288 function pmsCurMapY (): Integer; inline; begin result
:= msY
+vpy
; end;
291 procedure plrDebugMouse (var ev
: THMouseEvent
);
293 function wallToggle (pan
: TPanel
; tag
: Integer): Boolean;
295 result
:= false; // don't stop
296 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
);
297 if ((kbS
and THKeyEvent
.ModAlt
) <> 0) then
299 if pan
.Enabled
then g_Map_DisableWall(pan
.arrIdx
) else g_Map_EnableWall(pan
.arrIdx
);
303 function monsAtDump (mon
: TMonster
; tag
: Integer): Boolean;
305 result
:= false; // don't stop
306 e_WriteLog(Format('monster #%d; UID=%d', [mon
.arrIdx
, mon
.UID
]), MSG_NOTIFY
);
307 monMarkedUID
:= mon
.UID
;
308 //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
311 function monsInCell (mon
: TMonster
; tag
: Integer): Boolean;
313 result
:= false; // don't stop
314 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon
.arrIdx
, mon
.UID
, mon
.proxyId
]), MSG_NOTIFY
);
318 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
319 if (gPlayer1
= nil) or not vpSet
then exit
;
320 if (ev
.kind
<> THMouseEvent
.Press
) then exit
;
322 e_WriteLog(Format('mev: %d', [Integer(ev
.kind
)]), MSG_NOTIFY
);
324 if (ev
.but
= THMouseEvent
.Left
) then
326 if ((kbS
and THKeyEvent
.ModShift
) <> 0) then
328 // dump monsters in cell
329 e_WriteLog('===========================', MSG_NOTIFY
);
330 monsGrid
.forEachInCell(pmsCurMapX
, pmsCurMapY
, monsInCell
);
331 e_WriteLog('---------------------------', MSG_NOTIFY
);
336 e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY
);
337 mapGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, wallToggle
, (GridTagWall
or GridTagDoor
));
338 e_WriteLog('--- toggle wall ---', MSG_NOTIFY
);
343 if (ev
.but
= THMouseEvent
.Right
) then
346 e_WriteLog('===========================', MSG_NOTIFY
);
347 monsGrid
.forEachAtPoint(pmsCurMapX
, pmsCurMapY
, monsAtDump
);
348 e_WriteLog('---------------------------', MSG_NOTIFY
);
355 edgeBmp
: array of Byte = nil;
358 procedure drawOutlines ();
362 procedure clearEdgeBmp ();
364 SetLength(edgeBmp
, (gWinSizeX
+4)*(gWinSizeY
+4));
365 FillChar(edgeBmp
[0], Length(edgeBmp
)*sizeof(edgeBmp
[0]), 0);
368 procedure drawPanel (pan
: TPanel
);
370 sx
, len
, y0
, y1
: Integer;
372 if (pan
= nil) or (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
373 if (pan
.X
+pan
.Width
<= vpx
-1) or (pan
.Y
+pan
.Height
<= vpy
-1) then exit
;
374 if (pan
.X
>= vpx
+vpw
+1) or (pan
.Y
>= vpy
+vph
+1) then exit
;
375 if g_ol_nice
or g_ol_fill_walls
then
379 if (len
> gWinSizeX
+4) then len
:= gWinSizeX
+4;
380 if (sx
< 0) then begin len
+= sx
; sx
:= 0; end;
381 if (sx
+len
> gWinSizeX
+4) then len
:= gWinSizeX
+4-sx
;
382 if (len
< 1) then exit
;
384 assert(sx
+len
<= gWinSizeX
+4);
387 if (y0
< 0) then y0
:= 0;
388 if (y1
> gWinSizeY
+4) then y1
:= gWinSizeY
+4;
391 FillChar(edgeBmp
[y0
*(gWinSizeX
+4)+sx
], len
*sizeof(edgeBmp
[0]), 1);
397 drawRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, r
, g
, b
);
406 procedure flushLine ();
408 if (lsy
> 0) and (lsx
> 0) then
413 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
419 glVertex2f(lsx
-1+vpx
+0.37, lsy
-1+vpy
+0.37);
420 glVertex2f(lex
-0+vpx
+0.37, lsy
-1+vpy
+0.37);
428 procedure startLine (y
: Integer);
434 procedure putPixel (x
: Integer);
436 if (x
< 1) then exit
;
437 if (lex
+1 <> x
) then flushLine();
438 if (lsx
< 0) then lsx
:= x
;
442 procedure drawEdges ();
448 glDisable(GL_TEXTURE_2D
);
451 glDisable(GL_LINE_SMOOTH
);
452 glDisable(GL_POLYGON_SMOOTH
);
453 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
456 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
462 if (a
[-1] = 0) or (a
[1] = 0) or (a
[-(gWinSizeX
+4)] = 0) or (a
[gWinSizeX
+4] = 0) or
463 (a
[-(gWinSizeX
+4)-1] = 0) or (a
[-(gWinSizeX
+4)+1] = 0) or
464 (a
[gWinSizeX
+4-1] = 0) or (a
[gWinSizeX
+4+1] = 0) then
475 procedure drawFilledWalls ();
481 glDisable(GL_TEXTURE_2D
);
484 glDisable(GL_LINE_SMOOTH
);
485 glDisable(GL_POLYGON_SMOOTH
);
486 glColor4f(r
/255.0, g
/255.0, b
/255.0, 1.0);
489 a
:= @edgeBmp
[y
*(gWinSizeX
+4)+1];
493 if (a
[0] <> 0) then putPixel(x
);
500 procedure doWallsOld (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
508 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
509 for f
:= 0 to High(parr
) do
512 if (pan
= nil) or not pan
.Enabled
or (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
513 if ((pan
.PanelType
and ptype
) = 0) then continue
;
516 if g_ol_nice
then drawEdges();
517 if g_ol_fill_walls
then drawFilledWalls();
523 function doWallCB (pan
: TPanel
; tag
: Integer): Boolean;
525 result
:= false; // don't stop
526 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
527 if ((pan
.PanelType
and xptag
) = 0) then exit
;
531 procedure doWalls (parr
: array of TPanel
; ptype
: Word; ar
, ag
, ab
: Integer);
537 if ((ptype
and (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) <> 0) then ptype
:= GridTagWall
or GridTagDoor
538 else panelTypeToTag(ptype
);
539 if g_ol_nice
or g_ol_fill_walls
then clearEdgeBmp();
540 mapGrid
.forEachInAABB(vpx
-1, vpy
-1, vpw
+2, vph
+2, doWallCB
, ptype
);
541 if g_ol_nice
then drawEdges();
542 if g_ol_fill_walls
then drawFilledWalls();
546 if g_ol_rlayer_back
then doWallsOld(gRenderBackgrounds
, PANEL_BACK
, 255, 127, 0);
547 if g_ol_rlayer_step
then doWallsOld(gSteps
, PANEL_STEP
, 192, 192, 192);
548 if g_ol_rlayer_wall
then doWallsOld(gWalls
, PANEL_WALL
, 255, 255, 255);
549 if g_ol_rlayer_door
then doWallsOld(gWalls
, PANEL_OPENDOOR
or PANEL_CLOSEDOOR
, 0, 255, 0);
550 if g_ol_rlayer_acid1
then doWallsOld(gAcid1
, PANEL_ACID1
, 255, 0, 0);
551 if g_ol_rlayer_acid2
then doWallsOld(gAcid2
, PANEL_ACID2
, 198, 198, 0);
552 if g_ol_rlayer_water
then doWallsOld(gWater
, PANEL_WATER
, 0, 255, 255);
553 if g_ol_rlayer_fore
then doWallsOld(gRenderForegrounds
, PANEL_FORE
, 210, 210, 210);
557 procedure plrDebugDraw ();
559 procedure drawTileGrid ();
563 for y
:= 0 to (mapGrid
.gridHeight
div mapGrid
.tileSize
) do
565 drawLine(mapGrid
.gridX0
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, mapGrid
.gridX0
+mapGrid
.gridWidth
, mapGrid
.gridY0
+y
*mapGrid
.tileSize
, 96, 96, 96, 255);
568 for x
:= 0 to (mapGrid
.gridWidth
div mapGrid
.tileSize
) do
570 drawLine(mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
, mapGrid
.gridX0
+x
*mapGrid
.tileSize
, mapGrid
.gridY0
+y
*mapGrid
.gridHeight
, 96, 96, 96, 255);
574 procedure hilightCell (cx
, cy
: Integer);
576 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 0, 128, 0, 64);
579 procedure hilightCell1 (cx
, cy
: Integer);
581 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
582 fillRect(cx
, cy
, monsGrid
.tileSize
, monsGrid
.tileSize
, 255, 255, 0, 92);
585 function hilightWallTrc (pan
: TPanel
; tag
: Integer; x
, y
, prevx
, prevy
: Integer): Boolean;
587 result
:= false; // don't stop
588 if (pan
= nil) then exit
; // cell completion, ignore
589 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
590 fillRect(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, 0, 128, 128, 64);
593 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
596 mx
, my
, mw
, mh
: Integer;
599 mon
.getMapBox(mx
, my
, mw
, mh
);
600 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
601 if lineAABBIntersects(laserX0
, laserY0
, laserX1
, laserY1
, mx
, my
, mw
, mh
, ex
, ey
) then
603 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
607 procedure drawMonsterInfo (mon
: TMonster
);
609 mx
, my
, mw
, mh
: Integer;
611 procedure drawMonsterTargetLine ();
613 emx
, emy
, emw
, emh
: Integer;
618 if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_PLAYER
) then
620 eplr
:= g_Player_Get(mon
.MonsterTargetUID
);
621 if (eplr
<> nil) then eplr
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
623 else if (g_GetUIDType(mon
.MonsterTargetUID
) = UID_MONSTER
) then
625 enemy
:= g_Monsters_ByUID(mon
.MonsterTargetUID
);
626 if (enemy
<> nil) then enemy
.getMapBox(emx
, emy
, emw
, emh
) else exit
;
632 mon
.getMapBox(mx
, my
, mw
, mh
);
633 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
634 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
636 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
640 procedure drawLOS2Plr ();
642 emx
, emy
, emw
, emh
: Integer;
647 if (eplr
= nil) then exit
;
648 eplr
.getMapBox(emx
, emy
, emw
, emh
);
649 mon
.getMapBox(mx
, my
, mw
, mh
);
650 drawLine(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, 255, 0, 0, 255);
651 {$IF DEFINED(D2F_DEBUG)}
652 //mapGrid.dbgRayTraceTileHitCB := hilightCell1;
654 if (g_Map_traceToNearestWall(mx
+mw
div 2, my
+mh
div 2, emx
+emw
div 2, emy
+emh
div 2, @ex
, @ey
) <> nil) then
655 //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
657 drawLine(mx
+mw
div 2, my
+mh
div 2, ex
, ey
, 0, 255, 0, 255);
659 {$IF DEFINED(D2F_DEBUG)}
660 //mapGrid.dbgRayTraceTileHitCB := nil;
665 if (mon
= nil) then exit
;
666 mon
.getMapBox(mx
, my
, mw
, mh
);
669 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
673 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
674 darkenRect(mx
-4, my
-7*8-6, 110, 7*8+6, 128);
679 drawText6(mx
, my
, Format('%s(U:%u)', [monsTypeToString(mon
.MonsterType
), mon
.UID
]), 255, 127, 0); my
-= 8;
681 drawText6(mx
, my
, Format('Beh: %s', [monsBehToString(mon
.MonsterBehaviour
)]), 255, 127, 0); my
-= 8;
683 drawText6(mx
, my
, Format('State:%s (%d)', [monsStateToString(mon
.MonsterState
), mon
.MonsterSleep
]), 255, 127, 0); my
-= 8;
685 drawText6(mx
, my
, Format('Health:%d', [mon
.MonsterHealth
]), 255, 127, 0); my
-= 8;
687 drawText6(mx
, my
, Format('Ammo:%d', [mon
.MonsterAmmo
]), 255, 127, 0); my
-= 8;
689 drawText6(mx
, my
, Format('TgtUID:%u', [mon
.MonsterTargetUID
]), 255, 127, 0); my
-= 8;
690 drawText6(mx
, my
, Format('TgtTime:%d', [mon
.MonsterTargetTime
]), 255, 127, 0); my
-= 8;
693 drawMonsterTargetLine();
694 if showMonsLOS2Plr
then drawLOS2Plr();
696 property MonsterRemoved: Boolean read FRemoved write FRemoved;
697 property MonsterPain: Integer read FPain write FPain;
698 property MonsterAnim: Byte read FCurAnim write FCurAnim;
702 function highlightAllMonsterCells (mon
: TMonster
): Boolean;
704 result
:= false; // don't stop
705 monsGrid
.forEachBodyCell(mon
.proxyId
, hilightCell
);
710 mx
, my
, mw
, mh
: Integer;
712 if (gPlayer1
= nil) then exit
;
714 glEnable(GL_SCISSOR_TEST
);
715 glScissor(0, gWinSizeY
-gPlayerScreenSize
.Y
-1, vpw
, vph
);
718 glTranslatef(-vpx
, -vpy
, 0);
720 if (showGrid
) then drawTileGrid();
723 if (laserSet
) then g_Mons_AlongLine(laserX0
, laserY0
, laserX1
, laserY1
, monsCollector
, true);
725 if (monMarkedUID
<> -1) then
727 mon
:= g_Monsters_ByUID(monMarkedUID
);
730 mon
.getMapBox(mx
, my
, mw
, mh
);
731 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 0, 0, 30);
732 drawMonsterInfo(mon
);
736 if showAllMonsCells
then g_Mons_ForEach(highlightAllMonsterCells
);
740 glDisable(GL_SCISSOR_TEST
);
742 if showMapCurPos
then drawText8(4, gWinSizeY
-10, Format('mappos:(%d,%d)', [pmsCurMapX
, pmsCurMapY
]), 255, 255, 0);
746 // ////////////////////////////////////////////////////////////////////////// //
747 function g_Holmes_MouseEvent (var ev
: THMouseEvent
): Boolean;
755 if not uiMouseEvent(ev
) then plrDebugMouse(ev
);
759 function g_Holmes_KeyEvent (var ev
: THKeyEvent
): Boolean;
767 procedure dummyWallTrc (cx
, cy
: Integer);
776 SDL_SCANCODE_LCTRL
, SDL_SCANCODE_RCTRL
,
777 SDL_SCANCODE_LALT
, SDL_SCANCODE_RALT
,
778 SDL_SCANCODE_LSHIFT
, SDL_SCANCODE_RSHIFT
:
781 if uiKeyEvent(ev
) then begin result
:= true; exit
; end;
783 if (ev
.kind
= THKeyEvent
.Press
) then
785 // M-M: one monster think step
786 if (ev
.scan
= SDL_SCANCODE_M
) and ((ev
.kstate
and THKeyEvent
.ModAlt
) <> 0) then
789 gmon_debug_think
:= false;
790 gmon_debug_one_think_step
:= true; // do one step
793 // M-I: toggle monster info
794 if (ev
.scan
= SDL_SCANCODE_I
) and ((ev
.kstate
and THKeyEvent
.ModAlt
) <> 0) then
797 showMonsInfo
:= not showMonsInfo
;
800 // M-L: toggle monster LOS to player
801 if (ev
.scan
= SDL_SCANCODE_L
) and ((ev
.kstate
and THKeyEvent
.ModAlt
) <> 0) then
804 showMonsLOS2Plr
:= not showMonsLOS2Plr
;
807 // M-G: toggle "show all cells occupied by monsters"
808 if (ev
.scan
= SDL_SCANCODE_G
) and ((ev
.kstate
and THKeyEvent
.ModAlt
) <> 0) then
811 showAllMonsCells
:= not showAllMonsCells
;
814 // M-A: wake up monster
815 if (ev
.scan
= SDL_SCANCODE_A
) and ((ev
.kstate
and THKeyEvent
.ModAlt
) <> 0) then
818 if (monMarkedUID
<> -1) then
820 mon
:= g_Monsters_ByUID(monMarkedUID
);
821 if (mon
<> nil) then mon
.WakeUp();
825 // C-T: teleport player
826 if (ev
.scan
= SDL_SCANCODE_T
) and ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
829 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
830 if (gPlayers
[0] <> nil) then
832 gPlayers
[0].getMapBox(x
, y
, w
, h
);
833 gPlayers
[0].TeleportTo(pmsCurMapX
-w
div 2, pmsCurMapY
-h
div 2, true, 69); // 69: don't change dir
837 // C-P: show cursor position on the map
838 if (ev
.scan
= SDL_SCANCODE_P
) and ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
841 showMapCurPos
:= not showMapCurPos
;
845 if (ev
.scan
= SDL_SCANCODE_G
) and ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
848 showGrid
:= not showGrid
;
851 // C-L: toggle layers window
852 if (ev
.scan
= SDL_SCANCODE_L
) and ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
855 showLayersWindow
:= not showLayersWindow
;
856 toggleLayersWindow(nil, 0);
859 // C-O: toggle outlines window
860 if (ev
.scan
= SDL_SCANCODE_O
) and ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
863 showOutlineWindow
:= not showOutlineWindow
;
864 toggleOutlineWindow(nil, 0);
867 // F1: toggle options window
868 if (ev
.scan
= SDL_SCANCODE_F1
) and (ev
.kstate
= 0) then
871 if (winOptions
= nil) then createOptionsWindow();
872 if not uiVisibleWindow(winOptions
) then uiAddWindow(winOptions
) else uiRemoveWindow(winOptions
);
875 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
876 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
877 ((ev
.kstate
and THKeyEvent
.ModCtrl
) <> 0) then
883 SDL_SCANCODE_UP
: dy
-= 120;
884 SDL_SCANCODE_DOWN
: dy
+= 120;
885 SDL_SCANCODE_LEFT
: dx
-= 120;
886 SDL_SCANCODE_RIGHT
: dx
+= 120;
888 {$IF DEFINED(D2F_DEBUG)}
889 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
890 mapGrid
.dbgShowTraceLog
:= true;
892 pan
:= g_Map_traceToNearest(pmsCurMapX
, pmsCurMapY
, dx
, dy
, (GridTagWall
or GridTagDoor
or GridTagStep
or GridTagAcid1
or GridTagAcid2
or GridTagWater
), @ex
, @ey
);
893 {$IF DEFINED(D2F_DEBUG)}
894 //mapGrid.dbgRayTraceTileHitCB := nil;
895 mapGrid
.dbgShowTraceLog
:= false;
897 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX
, pmsCurMapY
, dx
, dy
, ex
, ey
, (pan
<> nil)]);
904 // ////////////////////////////////////////////////////////////////////////// //
905 procedure g_Holmes_Draw ();
907 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
908 glDisable(GL_STENCIL_TEST
);
910 glDisable(GL_SCISSOR_TEST
);
911 glDisable(GL_TEXTURE_2D
);
922 procedure g_Holmes_DrawUI ();