DEADSOFTWARE

more debug code in grid and holmes
[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 Motion = 0;
41 Press = 1;
42 Release = 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 button or 0
49 bstate: Word; // button state
50 kstate: Word; // keyboard state (see THKeyEvent);
51 end;
53 THKeyEvent = record
54 public
55 const
56 ModCtrl = $0001;
57 ModAlt = $0002;
58 ModShift = $0004;
59 end;
62 procedure g_Holmes_VidModeChanged ();
63 procedure g_Holmes_WindowFocused ();
64 procedure g_Holmes_WindowBlured ();
66 procedure g_Holmes_Draw ();
68 function g_Holmes_mouseEvent (var ev: THMouseEvent): Boolean; // returns `true` if event was eaten
69 function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean; // returns `true` if event was eaten
71 // hooks for player
72 procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer);
73 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
76 var
77 g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
80 implementation
82 uses
83 SysUtils, GL,
84 MAPDEF, g_options;
87 var
88 //globalInited: Boolean = false;
89 msX: Integer = -666;
90 msY: Integer = -666;
91 msB: Word = 0; // button state
92 kbS: Word = 0; // keyboard modifiers state
95 // ////////////////////////////////////////////////////////////////////////// //
96 {$INCLUDE g_holmes.inc}
98 // ////////////////////////////////////////////////////////////////////////// //
99 procedure g_Holmes_VidModeChanged ();
100 begin
101 e_WriteLog(Format('Inspector: videomode changed: %dx%d', [gScreenWidth, gScreenHeight]), MSG_NOTIFY);
102 // texture space is possibly lost here, idc
103 curtexid := 0;
104 font6texid := 0;
105 font8texid := 0;
106 prfont6texid := 0;
107 prfont8texid := 0;
108 //createCursorTexture();
109 end;
111 procedure g_Holmes_WindowFocused ();
112 begin
113 msB := 0;
114 kbS := 0;
115 end;
117 procedure g_Holmes_WindowBlured ();
118 begin
119 end;
122 // ////////////////////////////////////////////////////////////////////////// //
123 var
124 vpSet: Boolean = false;
125 vpx, vpy: Integer;
126 vpw, vph: Integer;
127 laserSet: Boolean = false;
128 laserX0, laserY0, laserX1, laserY1: Integer;
129 monMarkedUID: Integer = -1;
131 procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer);
132 begin
133 vpSet := true;
134 vpx := viewPortX;
135 vpy := viewPortY;
136 vpw := viewPortW;
137 vph := viewPortH;
138 end;
140 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
141 begin
142 laserSet := true;
143 laserX0 := ax0;
144 laserY0 := ay0;
145 laserX1 := ax1;
146 laserY1 := ay1;
147 end;
150 function pmsCurMapX (): Integer; inline; begin result := msX+vpx; end;
151 function pmsCurMapY (): Integer; inline; begin result := msY+vpy; end;
154 procedure plrDebugMouse (var ev: THMouseEvent);
156 function wallToggle (pan: TPanel; tag: Integer): Boolean;
157 begin
158 result := false; // don't stop
159 if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
160 end;
162 function monsAtDump (mon: TMonster; tag: Integer): Boolean;
163 begin
164 result := false; // don't stop
165 e_WriteLog(Format('monster #%d; UID=%d', [mon.arrIdx, mon.UID]), MSG_NOTIFY);
166 monMarkedUID := mon.UID;
167 //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
168 end;
170 function monsInCell (mon: TMonster; tag: Integer): Boolean;
171 begin
172 result := false; // don't stop
173 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), MSG_NOTIFY);
174 end;
176 begin
177 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
178 if (gPlayer1 = nil) then exit;
179 if (ev.kind <> THMouseEvent.Press) then exit;
181 if (ev.but = THMouseEvent.Left) then
182 begin
183 if ((kbS and THKeyEvent.ModShift) <> 0) then
184 begin
185 // dump monsters in cell
186 e_WriteLog('===========================', MSG_NOTIFY);
187 monsGrid.forEachInCell(pmsCurMapX, pmsCurMapY, monsInCell);
188 e_WriteLog('---------------------------', MSG_NOTIFY);
189 end
190 else
191 begin
192 // toggle wall
193 mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
194 end;
195 exit;
196 end;
198 if (ev.but = THMouseEvent.Right) then
199 begin
200 monMarkedUID := -1;
201 e_WriteLog('===========================', MSG_NOTIFY);
202 monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
203 e_WriteLog('---------------------------', MSG_NOTIFY);
204 exit;
205 end;
206 end;
209 procedure plrDebugDraw ();
211 procedure drawTileGrid ();
212 var
213 x, y: Integer;
214 begin
215 y := mapGrid.gridY0;
216 while (y < mapGrid.gridY0+mapGrid.gridHeight) do
217 begin
218 x := mapGrid.gridX0;
219 while (x < mapGrid.gridX0+mapGrid.gridWidth) do
220 begin
221 if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and
222 (x < vpx+vpw) and (y < vpy+vph) then
223 begin
224 //e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
225 drawRect(x, y, mapGrid.tileSize, mapGrid.tileSize, 96, 96, 96, 255);
226 end;
227 Inc(x, mapGrid.tileSize);
228 end;
229 Inc(y, mapGrid.tileSize);
230 end;
231 end;
233 procedure hilightCell (cx, cy: Integer);
234 begin
235 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 0, 128, 0, 64);
236 end;
238 function monsCollector (mon: TMonster; tag: Integer): Boolean;
239 var
240 ex, ey: Integer;
241 mx, my, mw, mh: Integer;
242 begin
243 result := false;
244 mon.getMapBox(mx, my, mw, mh);
245 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
246 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
247 begin
248 e_DrawPoint(8, ex, ey, 0, 255, 0);
249 end;
250 end;
252 procedure drawMonsterInfo (mon: TMonster);
253 var
254 mx, my, mw, mh: Integer;
255 emx, emy, emw, emh: Integer;
256 enemy: TMonster;
257 eplr: TPlayer;
258 begin
259 if (mon = nil) then exit;
260 mon.getMapBox(mx, my, mw, mh);
261 //mx += mw div 2;
263 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
265 if ((kbS and THKeyEvent.ModCtrl) <> 0) then
266 begin
267 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
268 shadeRect(mx-4, my-7*8-6, 110, 7*8+6, 128);
269 my -= 8;
270 my -= 2;
272 // type
273 drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), 255, 127, 0); my -= 8;
274 // beh
275 drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), 255, 127, 0); my -= 8;
276 // state
277 drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), 255, 127, 0); my -= 8;
278 // health
279 drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), 255, 127, 0); my -= 8;
280 // ammo
281 drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), 255, 127, 0); my -= 8;
282 // target
283 drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8;
284 drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8;
286 mon.getMapBox(mx, my, mw, mh);
287 end;
289 if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
290 begin
291 eplr := g_Player_Get(mon.MonsterTargetUID);
292 if (eplr <> nil) then
293 begin
294 eplr.getMapBox(emx, emy, emw, emh);
295 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 128);
296 end;
297 end
298 else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then
299 begin
300 enemy := g_Monsters_ByUID(mon.MonsterTargetUID);
301 if (enemy <> nil) then
302 begin
303 enemy.getMapBox(emx, emy, emw, emh);
304 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 128);
305 end;
306 end;
309 property MonsterRemoved: Boolean read FRemoved write FRemoved;
310 property MonsterPain: Integer read FPain write FPain;
311 property MonsterAnim: Byte read FCurAnim write FCurAnim;
313 end;
315 var
316 mon: TMonster;
317 mx, my, mw, mh: Integer;
318 begin
319 //e_DrawPoint(4, plrMouseX, plrMouseY, 255, 0, 255);
320 if (gPlayer1 = nil) then exit;
322 //e_WriteLog(Format('(%d,%d)-(%d,%d)', [laserX0, laserY0, laserX1, laserY1]), MSG_NOTIFY);
324 glPushMatrix();
325 glTranslatef(-vpx, -vpy, 0);
327 drawTileGrid();
329 g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
331 if (monMarkedUID <> -1) then
332 begin
333 mon := g_Monsters_ByUID(monMarkedUID);
334 if (mon <> nil) then
335 begin
336 mon.getMapBox(mx, my, mw, mh);
337 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
338 drawMonsterInfo(mon);
339 end;
340 end;
342 //e_DrawPoint(16, laserX0, laserY0, 255, 255, 255);
344 glPopMatrix();
345 end;
348 // ////////////////////////////////////////////////////////////////////////// //
349 function g_Holmes_mouseEvent (var ev: THMouseEvent): Boolean;
350 begin
351 result := true;
352 msX := ev.x;
353 msY := ev.y;
354 msB := ev.bstate;
355 kbS := ev.kstate;
356 plrDebugMouse(ev);
357 end;
360 function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean;
361 begin
362 result := false;
363 end;
366 // ////////////////////////////////////////////////////////////////////////// //
367 procedure g_Holmes_Draw ();
368 begin
369 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
370 glDisable(GL_STENCIL_TEST);
371 glDisable(GL_BLEND);
372 glDisable(GL_SCISSOR_TEST);
373 glDisable(GL_TEXTURE_2D);
375 if gGameOn then
376 begin
377 plrDebugDraw();
378 end;
380 //drawText6Prop(10, 10, 'Hi there, I''m Holmes!', 255, 255, 0);
381 //drawText8Prop(10, 20, 'Hi there, I''m Holmes!', 255, 255, 0);
383 drawCursor();
384 end;
387 end.