From b946cbdcbf48925d64654d15eca6016fe520dde8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A1=D1=83=D1=85=D0=BE=D0=B2?= <22411953+Vladislav4KZ@users.noreply.github.com> Date: Sat, 13 May 2023 00:19:07 +0600 Subject: [PATCH] add: creating a jump path via menu and console command --- cfg/addons/yapb/conf/lang/ru_lang.cfg | 8 ++++++++ inc/graph.h | 3 ++- src/control.cpp | 16 +++++++++++++--- src/graph.cpp | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/cfg/addons/yapb/conf/lang/ru_lang.cfg b/cfg/addons/yapb/conf/lang/ru_lang.cfg index 5fc7b05..0b2c83b 100644 --- a/cfg/addons/yapb/conf/lang/ru_lang.cfg +++ b/cfg/addons/yapb/conf/lang/ru_lang.cfg @@ -507,6 +507,7 @@ 1. Outgoing Path 2. Incoming Path 3. Bidirectional (Both Ways) +4. Jumping Path 0. Exit @@ -516,6 +517,7 @@ 1. Исходящий путь 2. Входящий путь 3. Двунаправленный (Оба пути) +4. Прыговой путь 0. Выход @@ -1799,6 +1801,12 @@ Creates both-ways path connection between faced and nearest node. [TRANSLATED] Создаёт двойной путь между указанной и ближайшей точкой. +[ORIGINAL] +Creates jumping path connection from nearest to faced node. + +[TRANSLATED] +Создаёт прыговой путь от ближайшей к указанной точке. + [ORIGINAL] Deletes path from nearest to faced node. diff --git a/inc/graph.h b/inc/graph.h index 168fa94..627888e 100644 --- a/inc/graph.h +++ b/inc/graph.h @@ -43,7 +43,8 @@ CR_DECLARE_SCOPED_ENUM (FindPath, CR_DECLARE_SCOPED_ENUM (PathConnection, Outgoing = 0, Incoming, - Bidirectional + Bidirectional, + Jumping ) // node edit states diff --git a/src/control.cpp b/src/control.cpp index 0df86c6..da65805 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -347,6 +347,7 @@ int BotControl::cmdNode () { addGraphCmd ("path_create_in", "path_create_in [noarguments]", "Creates incoming path connection from faced to nearest node.", &BotControl::cmdNodePathCreate); addGraphCmd ("path_create_out", "path_create_out [noarguments]", "Creates outgoing path connection from nearest to faced node.", &BotControl::cmdNodePathCreate); addGraphCmd ("path_create_both", "path_create_both [noarguments]", "Creates both-ways path connection between faced and nearest node.", &BotControl::cmdNodePathCreate); + addGraphCmd ("path_create_jump", "path_create_jump [noarguments]", "Creates jumping path connection from nearest to faced node.", &BotControl::cmdNodePathCreate); addGraphCmd ("path_delete", "path_delete [noarguments]", "Deletes path from nearest to faced node.", &BotControl::cmdNodePathDelete); addGraphCmd ("path_set_autopath", "path_set_autopath [max_distance]", "Opens menu for setting autopath maximum distance.", &BotControl::cmdNodePathSetAutoDistance); @@ -697,7 +698,10 @@ int BotControl::cmdNodePathCreate () { graph.setEditFlag (GraphEdit::On); // choose the direction for path creation - if (strValue (cmd).endsWith ("_both")) { + if (strValue (cmd).endsWith ("_jump")) { + graph.pathCreate (PathConnection::Jumping); + } + else if (strValue (cmd).endsWith ("_both")) { graph.pathCreate (PathConnection::Bidirectional); } else if (strValue (cmd).endsWith ("_in")) { @@ -1719,6 +1723,11 @@ int BotControl::menuGraphPath (int item) { showMenu (Menu::NodePath); break; + case 4: + graph.pathCreate (PathConnection::Jumping); + showMenu (Menu::NodePath); + break; + case 10: closeMenu (); break; @@ -2409,11 +2418,12 @@ void BotControl::createMenus () { // path connections m_menus.emplace ( - Menu::NodePath, keys (3), + Menu::NodePath, keys (4), "\\yCreate Path (Choose Direction)\\w\n\n" "1. Outgoing Path\n" "2. Incoming Path\n" - "3. Bidirectional (Both Ways)\n\n" + "3. Bidirectional (Both Ways)\n" + "4. Jumping Path\n\n" "0. Exit", &BotControl::menuGraphPath); diff --git a/src/graph.cpp b/src/graph.cpp index 2630088..849e607 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -1059,6 +1059,21 @@ void BotGraph::pathCreate (char dir) { else if (dir == PathConnection::Incoming) { addPath (nodeTo, nodeFrom, distance); } + else if (dir == PathConnection::Jumping) { + if (!isConnected (nodeFrom, nodeTo)) { + addPath (nodeFrom, nodeTo, distance); + } + for (auto &link : m_paths[nodeFrom].links) { + if (link.index == nodeTo && !(link.flags & PathFlag::Jump)) { + link.flags |= PathFlag::Jump; + m_paths[nodeFrom].radius = 0.0f; + msg ("Path added from %d to %d.", nodeFrom, nodeTo); + } + else if (link.index == nodeTo && (link.flags & PathFlag::Jump)) { + msg ("Denied path creation from %d to %d (path already exists).", nodeFrom, nodeTo); + } + } + } else { addPath (nodeFrom, nodeTo, distance); addPath (nodeTo, nodeFrom, distance);