ref: 165e0028e4533966f78eab011aa7fda3984fd90e
parent: 39f8a2bc4a686447c0eb1aac2ca39bb14fbaf06e
author: qwx <[email protected]>
date: Sat Mar 26 20:49:18 EDT 2022
prevent pathfinding on blocked nodes
--- a/path/a∗.c
+++ b/path/a∗.c
@@ -141,10 +141,12 @@
mouseinput(Node *n, Mouse m)
{
switch(m.buttons & 7){
- case 1: if(goal != n) start = n; return findpath();
- case 2: if(start != n) goal = n; return findpath();
- case 4: n->blocked ^= 1; break;
+ case 1: if(goal != n && !n->blocked) start = n; break;
+ case 2: if(start != n && !n->blocked) goal = n; break;
+ case 4: n->blocked ^= 1; return 0;
}
+ if(start != nil && goal != nil)
+ return findpath();
return 0;
}
--- a/path/bfs.c
+++ b/path/bfs.c
@@ -139,10 +139,12 @@
mouseinput(Node *n, Mouse m)
{
switch(m.buttons & 7){
- case 1: if(goal != n) start = n; return findpath();
- case 2: if(start != n) goal = n; return findpath();
- case 4: n->blocked ^= 1; break;
+ case 1: if(goal != n && !n->blocked) start = n; break;
+ case 2: if(start != n && !n->blocked) goal = n; break;
+ case 4: n->blocked ^= 1; return 0;
}
+ if(start != nil && goal != nil)
+ return findpath();
return 0;
}
--- a/path/dijkstra.c
+++ b/path/dijkstra.c
@@ -138,10 +138,12 @@
mouseinput(Node *n, Mouse m)
{
switch(m.buttons & 7){
- case 1: if(goal != n) start = n; return findpath();
- case 2: if(start != n) goal = n; return findpath();
- case 4: n->blocked ^= 1; break;
+ case 1: if(goal != n && !n->blocked) start = n; break;
+ case 2: if(start != n && !n->blocked) goal = n; break;
+ case 4: n->blocked ^= 1; return 0;
}
+ if(start != nil && goal != nil)
+ return findpath();
return 0;
}