From d354cd7a11af564156b13568eac5b4ff94a2c4a3 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Wed, 23 Aug 2017 16:53:45 +0300 Subject: [PATCH] "dbg_holmes" console command; draw line to monster target --- src/game/g_console.pas | 1 + src/game/g_game.pas | 7 +++++- src/game/g_holmes.inc | 55 ++++++++++++++++++++++++++++++++++++++++-- src/game/g_holmes.pas | 27 +++++++++++++++++++++ src/game/g_window.pas | 8 +++--- 5 files changed, 92 insertions(+), 6 deletions(-) diff --git a/src/game/g_console.pas b/src/game/g_console.pas index c9568f0..d80fb01 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -415,6 +415,7 @@ begin AddCommand('los_enabled', ProfilerCommands, 'enable/disable LOS calculations'); AddCommand('mon_think', ProfilerCommands, 'enable/disable monster thinking'); + AddCommand('dbg_holmes', ProfilerCommands, 'turn Holmes on/off'); AddCommand('p1_name', GameCVars); AddCommand('p2_name', GameCVars); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 833baf5..129370d 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -3255,7 +3255,7 @@ begin end; // draw inspector - g_Holmes_Draw(); + if (g_holmes_enabled) then g_Holmes_Draw(); g_Console_Draw(); @@ -4991,7 +4991,12 @@ begin if (cmd = 'pr_enabled') then begin binaryFlag(gpart_dbg_enabled, 'particles'); exit; end; if (cmd = 'pr_phys_enabled') then begin binaryFlag(gpart_dbg_phys_enabled, 'particle physics'); exit; end; if (cmd = 'los_enabled') then begin binaryFlag(gmon_dbg_los_enabled, 'LOS calculations'); exit; end; + + if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and + (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode)) or g_Game_IsNet then exit; + if (cmd = 'mon_think') then begin binaryFlag(gmon_debug_think, 'monster thinking'); exit; end; + if (cmd = 'dbg_holmes') then begin binaryFlag(g_holmes_enabled, 'Holmes'); exit; end; end; diff --git a/src/game/g_holmes.inc b/src/game/g_holmes.inc index 8df305c..e3dd380 100644 --- a/src/game/g_holmes.inc +++ b/src/game/g_holmes.inc @@ -419,8 +419,7 @@ var begin result := 0; if (Length(s) = 0) then exit; - if (a < 0) then a := 0; - if (a > 255) then a := 255; + if (a < 0) then a := 0 else if (a > 255) then a := 255; if (r < 0) then r := 0 else if (r > 255) then r := 255; if (g < 0) then g := 0 else if (g > 255) then g := 255; if (b < 0) then b := 0 else if (b > 255) then b := 255; @@ -462,6 +461,58 @@ begin end; +// ////////////////////////////////////////////////////////////////////////// // +procedure drawLine (x1, y1, x2, y2: Integer; r, g, b: Integer; a: Integer=255); + + procedure lcor (var x1, y1, x2, y2: Integer); + begin + if (y2 < y1) then + begin + x1 := x1 xor x2; + x2 := x1 xor x2; + x1 := x1 xor x2; + + y1 := y1 xor y2; + y2 := y1 xor y2; + y1 := y1 xor y2; + end; + + if (x1 < x2) then Inc(X2) else Inc(x1); + Inc(y2); + end; + +begin + lcor(x1, y1, x2, y2); + + if (a < 0) then a := 0 else if (a > 255) then a := 255; + if (r < 0) then r := 0 else if (r > 255) then r := 255; + if (g < 0) then g := 0 else if (g > 255) then g := 255; + if (b < 0) then b := 0 else if (b > 255) then b := 255; + + if (a < 255) then + begin + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + end + else + begin + glDisable(GL_BLEND); + end; + + glDisable(GL_TEXTURE_2D); + glColor4f(r/255.0, g/255.0, b/255.0, a/255.0); + glLineWidth(1); + + glBegin(GL_LINES); + glVertex2i(x1, y1); + glVertex2i(x2, y2); + glEnd(); + + glColor4f(1, 1, 1, 1); + glDisable(GL_BLEND); +end; + + // ////////////////////////////////////////////////////////////////////////// // procedure shadeRect (x, y, w, h: Integer; a: Integer); begin diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 6683922..75e03bb 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -73,6 +73,10 @@ procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer) procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer); +var + g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF}; + + implementation uses @@ -204,6 +208,9 @@ procedure plrDebugDraw (); procedure drawMonsterInfo (mon: TMonster); var mx, my, mw, mh: Integer; + emx, emy, emw, emh: Integer; + enemy: TMonster; + eplr: TPlayer; begin if (mon = nil) then exit; mon.getMapBox(mx, my, mw, mh); @@ -228,6 +235,26 @@ procedure plrDebugDraw (); drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8; drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8; + mon.getMapBox(mx, my, mw, mh); + if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then + begin + eplr := g_Player_Get(mon.MonsterTargetUID); + if (eplr <> nil) then + begin + eplr.getMapBox(emx, emy, emw, emh); + drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 128); + end; + end + else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then + begin + enemy := g_Monsters_ByUID(mon.MonsterTargetUID); + if (enemy <> nil) then + begin + enemy.getMapBox(emx, emy, emw, emh); + drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 128); + end; + end; + { property MonsterRemoved: Boolean read FRemoved write FRemoved; property MonsterPain: Integer read FPain write FPain; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 998c681..1ac9c9e 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -461,7 +461,7 @@ begin curMsButState := curMsButState or msev.but; msev.bstate := curMsButState; msev.kstate := curKbState; - g_Holmes_mouseEvent(msev); + if (g_holmes_enabled) then g_Holmes_mouseEvent(msev); end; end; SDL_MOUSEWHEEL: @@ -476,7 +476,7 @@ begin msev.y := curMsY; msev.bstate := curMsButState; msev.kstate := curKbState; - g_Holmes_mouseEvent(msev); + if (g_holmes_enabled) then g_Holmes_mouseEvent(msev); end; end; SDL_MOUSEMOTION: @@ -491,7 +491,7 @@ begin msev.y := curMsY; msev.bstate := curMsButState; msev.kstate := curKbState; - g_Holmes_mouseEvent(msev); + if (g_holmes_enabled) then g_Holmes_mouseEvent(msev); end; SDL_TEXTINPUT: @@ -822,6 +822,8 @@ begin if ParamStr(idx) = '--no-particles-physics' then gpart_dbg_phys_enabled := false; if ParamStr(idx) = '--no-particle-phys' then gpart_dbg_phys_enabled := false; if ParamStr(idx) = '--no-particle-physics' then gpart_dbg_phys_enabled := false; + + if ParamStr(idx) = '--holmes' then g_holmes_enabled := false; end; //if gdbg_map_use_tree_draw then e_WriteLog('using TREE renderer', MSG_NOTIFY); -- 2.29.2