ref: 596459dd77e5c3e66a57be31e711a58624024881
parent: 05c937e347bbfc1f2758261c15ae0e5a73ada669
author: qwx <[email protected]>
date: Fri Mar 4 03:58:15 EST 2022
path: have setgoal just move goal to center of target mobj the additional pathfinding to nearest will take care of the rest
--- a/a∗.c
+++ b/a∗.c
@@ -40,7 +40,7 @@
}
static Node **
-successors(Mobj *mo, Node *n, Node*)
+a∗successors(Mobj *mo, Node *n, Node*)
{
static Node *dir[8+1];
static dtab[2*(nelem(dir)-1)]={
@@ -151,6 +151,7 @@
dprint("%M a∗findpath: jps pathfinding failed but plain a∗ found the goal\n", mo);
nearest = b;
}
- m = a∗(mo, a, nearest, successors);
+ /* m( */
+ m = a∗(mo, a, nearest, a∗successors);
return m == b ? b : nearest;
}
--- a/jpsb.c
+++ b/jpsb.c
@@ -245,6 +245,7 @@
return (row[2] & 7) << 6 | (row[1] & 7) << 3 | row[0] & 7;
}
+/* FIXME: this is super broken (see notes + sshots) */
Node **
jpsbsuccessors(Mobj *mo, Node *n, Node *goal)
{
--- a/path.c
+++ b/path.c
@@ -75,64 +75,18 @@
pp->step = (Point *)pp->moves.p + pp->moves.n - 1;
}
-/* FIXME: use center of mobj if any instead of upper left corner
- * no need for any of this crap: if target is a mobj, set goal to
- * its center, done */
-/* FIXME: completely broken */
void
setgoal(Mobj *mo, Point *gp, Mobj *block)
{
- int e;
- double Δ, Δ´;
- Point p, g;
- Node *n1, *n2, *gn;
+ Point p;
- if(mo->o->f & Fair || block == nil){
+ if(mo->o->f & Fair || block == nil)
mo->path.blocked = 0;
+ if(block == nil)
return;
- }
- g = *gp;
- mo->path.blocked = 1;
- dprint("%M setgoal: moving goal %P in block %#p ", mo, g, block);
- gn = map + g.y * mapwidth + g.x;
- gn->Point = g;
- Δ = 0x7ffffff;
- p = block->Point;
- n1 = map + p.y * mapwidth + p.x;
- n2 = n1 + (block->o->h - 1) * mapwidth;
- for(e=p.x+block->o->w; p.x<e; p.x++, n1++, n2++){
- n1->Point = p;
- Δ´ = octdist(gn->Point, n1->Point);
- if(Δ´ < Δ){
- Δ = Δ´;
- g = p;
- }
- n2->Point = addpt(p, Pt(0, block->o->h-1));
- Δ´ = octdist(gn->Point, n2->Point);
- if(Δ´ < Δ){
- Δ = Δ´;
- g = n2->Point;
- }
- }
- p = addpt(block->Point, Pt(0,1));
- n1 = map + p.y * mapwidth + p.x;
- n2 = n1 + block->o->w - 1;
- for(e=p.y+block->o->h-2; p.y<e; p.y++, n1+=mapwidth, n2+=mapwidth){
- n1->Point = p;
- Δ´ = octdist(gn->Point, n1->Point);
- if(Δ´ < Δ){
- Δ = Δ´;
- g = p;
- }
- n2->Point = addpt(p, Pt(block->o->w-1, 0));
- Δ´ = octdist(gn->Point, n2->Point);
- if(Δ´ < Δ){
- Δ = Δ´;
- g = n2->Point;
- }
- }
- dprint("to %P\n", g);
- *gp = g;
+ p = addpt(block->Point, divpt(block->o->Size, 2));
+ dprint("%M setgoal: moving goal from %P to %P\n", mo, *gp, p);
+ *gp = p;
}
/* FIXME: fmt for Nodes or w/e */