add: creating a jump path via menu and console command

This commit is contained in:
Владислав Сухов 2023-05-13 00:19:07 +06:00 committed by GitHub
commit b946cbdcbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 4 deletions

View file

@ -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.

View file

@ -43,7 +43,8 @@ CR_DECLARE_SCOPED_ENUM (FindPath,
CR_DECLARE_SCOPED_ENUM (PathConnection,
Outgoing = 0,
Incoming,
Bidirectional
Bidirectional,
Jumping
)
// node edit states

View file

@ -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);

View file

@ -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);