From 4628d3889bef6c557e06f62d90ffddc57765e255 Mon Sep 17 00:00:00 2001 From: art0007i Date: Thu, 2 Jan 2025 18:12:55 +0100 Subject: [PATCH] teleport hook line (only when there is 1 possible exit) --- src/game/client/components/players.cpp | 57 ++++++++++++++++++++------ 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/game/client/components/players.cpp b/src/game/client/components/players.cpp index e0240f23070..14b54e321c5 100644 --- a/src/game/client/components/players.cpp +++ b/src/game/client/components/players.cpp @@ -257,6 +257,8 @@ void CPlayers::RenderHookCollLine( bool DoBreak = false; + std::vector> vLineSegments; + do { OldPos = NewPos; @@ -268,9 +270,25 @@ void CPlayers::RenderHookCollLine( DoBreak = true; } - int Hit = Collision()->IntersectLineTeleHook(OldPos, NewPos, &FinishPos, 0x0); + int Tele; + int Hit = Collision()->IntersectLineTeleHook(OldPos, NewPos, &FinishPos, 0x0, &Tele); + if(!DoBreak && Hit == TILE_TELEINHOOK) + { + if(Collision()->TeleOuts(Tele - 1).size() != 1) + { + Hit = Collision()->IntersectLineTeleHook(OldPos, NewPos, &FinishPos, 0x0); + } + else + { + std::pair NewPair = std::make_pair(InitPos, FinishPos); + if(std::find(vLineSegments.begin(), vLineSegments.end(), NewPair) != vLineSegments.end()) + break; + vLineSegments.push_back(NewPair); + InitPos = NewPos = Collision()->TeleOuts(Tele - 1)[0]; + } + } - if(!DoBreak && Hit) + if(!DoBreak && Hit && Hit != TILE_TELEINHOOK) { if(Hit != TILE_NOHOOK) { @@ -284,7 +302,7 @@ void CPlayers::RenderHookCollLine( break; } - if(Hit) + if(Hit && Hit != TILE_TELEINHOOK) break; NewPos.x = round_to_int(NewPos.x); @@ -297,28 +315,41 @@ void CPlayers::RenderHookCollLine( ExDirection.y = round_to_int(ExDirection.y * 256.0f) / 256.0f; } while(!DoBreak); + std::pair NewPair = std::make_pair(InitPos, FinishPos); + if(std::find(vLineSegments.begin(), vLineSegments.end(), NewPair) == vLineSegments.end()) + vLineSegments.push_back(NewPair); + if(AlwaysRenderHookColl && RenderHookCollPlayer) { // invert the hook coll colors when using cl_show_hook_coll_always and +showhookcoll is pressed HookCollColor = color_invert(HookCollColor); } Graphics()->SetColor(HookCollColor.WithAlpha(Alpha)); + for(const auto &[DrawInitPos, DrawFinishPos] : vLineSegments) + { + if(HookCollSize > 0) + { + float LineWidth = 0.5f + (float)(HookCollSize - 1) * 0.25f; + vec2 PerpToAngle = normalize(vec2(ExDirection.y, -ExDirection.x)) * GameClient()->m_Camera.m_Zoom; + vec2 Pos0 = DrawFinishPos + PerpToAngle * -LineWidth; + vec2 Pos1 = DrawFinishPos + PerpToAngle * LineWidth; + vec2 Pos2 = DrawInitPos + PerpToAngle * -LineWidth; + vec2 Pos3 = DrawInitPos + PerpToAngle * LineWidth; + IGraphics::CFreeformItem FreeformItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y, Pos2.x, Pos2.y, Pos3.x, Pos3.y); + Graphics()->QuadsDrawFreeform(&FreeformItem, 1); + } + else + { + IGraphics::CLineItem LineItem(DrawInitPos.x, DrawInitPos.y, DrawFinishPos.x, DrawFinishPos.y); + Graphics()->LinesDraw(&LineItem, 1); + } + } if(HookCollSize > 0) { - float LineWidth = 0.5f + (float)(HookCollSize - 1) * 0.25f; - vec2 PerpToAngle = normalize(vec2(ExDirection.y, -ExDirection.x)) * GameClient()->m_Camera.m_Zoom; - vec2 Pos0 = FinishPos + PerpToAngle * -LineWidth; - vec2 Pos1 = FinishPos + PerpToAngle * LineWidth; - vec2 Pos2 = InitPos + PerpToAngle * -LineWidth; - vec2 Pos3 = InitPos + PerpToAngle * LineWidth; - IGraphics::CFreeformItem FreeformItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y, Pos2.x, Pos2.y, Pos3.x, Pos3.y); - Graphics()->QuadsDrawFreeform(&FreeformItem, 1); Graphics()->QuadsEnd(); } else { - IGraphics::CLineItem LineItem(InitPos.x, InitPos.y, FinishPos.x, FinishPos.y); - Graphics()->LinesDraw(&LineItem, 1); Graphics()->LinesEnd(); } }