ref: 3a7a70853c38b79291760a4a0b923d1964139c90
parent: be4306b3a29b736001c2aad5326837be44e3f1cc
author: qwx <[email protected]>
date: Thu Dec 2 15:35:07 EST 2021
move: avoid issuing a command to move to itself forced to do it at multiple places: - when issuing a mouse command - when receiving a command to move - when initiating pathfinding if goal was set to itself and as a sanity check the original tries to move anyway, but it wouldn't work with our system
--- a/com.c
+++ b/com.c
@@ -115,6 +115,10 @@
&click.x, &click.y,
&reqt.idx, &reqt.uuid, &reqt.x, &reqt.y)) < 0)
return -1;
+ if(eqpt(reqm.Point, reqt.Point) || eqpt(reqm.Point, click)){
+ dprint("reqmovenear: %P [%#ux,%ld] → %P [%#ux,%ld] (%P), not moving to itself\n", reqm.Point, reqm.idx, reqm.uuid, reqt.Point, reqt.idx, reqt.uuid, click);
+ return n;
+ }
if((mo = mobjfromreq(&reqm)) == nil)
return -1;
if((mo->o->f & Fimmutable) || mo->o->speed == 0.0){
@@ -143,6 +147,10 @@
&reqm.idx, &reqm.uuid, &reqm.x, &reqm.y,
&tgt.x, &tgt.y)) < 0)
return -1;
+ if(eqpt(reqm.Point, tgt)){
+ dprint("reqmove: %P [%#ux,%ld] → %P, not moving to itself\n", reqm.Point, reqm.idx, reqm.uuid, tgt);
+ return n;
+ }
if((mo = mobjfromreq(&reqm)) == nil)
return -1;
if((mo->o->f & Fimmutable) || mo->o->speed == 0.0){
--- a/drw.c
+++ b/drw.c
@@ -80,15 +80,15 @@
vp = divpt(subpt(p, selr.min), scale);
i = fbvis[vp.y * fbw + vp.x];
mo = i == -1 ? nil : visbuf[i];
- if(mo == it){
- dprint("doaction: %M targeting itself\n", it);
- return;
- }
p = divpt(addpt(subpt(p, selr.min), pan), scale);
p.x /= Nodewidth;
p.y /= Nodeheight;
if(nodemapwidth - p.x < it->o->w || nodemapheight - p.y < it->o->h){
dprint("doaction: %M destination beyond map edge\n", it);
+ return;
+ }
+ if(mo == it || eqpt(it->Point, p)){
+ dprint("doaction: %M targeting itself\n", it);
return;
}
if(clearcmds)
--- a/path.c
+++ b/path.c
@@ -555,7 +555,11 @@
{
Node *a, *b, *n;
- dprint("%M findpath to %d,%d\n", mo, p.x, p.y);
+ dprint("%M findpath to %P\n", mo, p);
+ if(eqpt(p, mo->Point)){
+ werrstr("not moving to itself");
+ return -1;
+ }
clearpath();
a = nodemap + mo->y * nodemapwidth + mo->x;
a->x = mo->x;
@@ -576,7 +580,7 @@
markmobj(mo, 1);
return -1;
}
- dprint("%M nearest: %#p %d,%d dist %f\n", mo, n, n->x, n->y, n->h);
+ dprint("%M nearest: %#p %P dist %f\n", mo, n, n->Point, n->h);
b = nearestnonjump(n, b, mo);
if(b == a){
werrstr("a∗: really can't move");
--- a/sim.move.c
+++ b/sim.move.c
@@ -31,6 +31,8 @@
dx = p.x - mo->px;
dy = p.y - mo->py;
d = sqrt(dx * dx + dy * dy);
+ if(d == 0.0)
+ sysfatal("facegoal: %M → %P: moving in place, shouldn't happen", mo, p);
vx = dx / d;
vy = dy / d;
/* angle in radians [0;2π[ with 0 facing north */
@@ -336,14 +338,13 @@
c = mo->cmds;
c->cleanupfn = cleanup;
goal = c->goal;
- /* FIXME: shitty */
+ setgoal(&goal, mo, c->target1);
+ if(repath(goal, mo) < 0)
+ return -1;
if(eqpt(goal, mo->Point)){
mo->state = OSskymaybe;
return 0;
}
- setgoal(&goal, mo, c->target1); /* FIXME: target[12] might be a problem for returns */
- if(repath(goal, mo) < 0)
- return -1;
c->stepfn = step;
mo->state = OSmove;
return 0;