shithub: sce

Download patch

ref: a274d4d1fafc06576c039ab16551c80491749851
parent: 97914a3f07abd4bd71d0a54ca11cd9693d22a081
author: qwx <[email protected]>
date: Tue Nov 23 17:48:28 EST 2021

sim.move: add turning half-state when move towards target done

--- a/sim.move.c
+++ b/sim.move.c
@@ -53,6 +53,16 @@
 	return θ256;
 }
 
+static double
+facemobj(Mobj *mo, Mobj *tgt)
+{
+	Point p;
+
+	p.x = tgt->px + tgt->o->w * Nodewidth / 2;
+	p.y = tgt->py + tgt->o->h * Nodeheight / 2;
+	return facegoal(p, mo);
+}
+
 static void
 nextpathnode(Mobj *mo)
 {
@@ -79,10 +89,27 @@
 }
 
 static void
+movereallyreallyreallydone(Mobj *mo)
+{
+	dprint("%M really really really successfully reached goal\n", mo);
+	nextstate(mo);
+}
+
+static void	turnstep(Mobj*);
+
+static void
 movedone(Mobj *mo)
 {
+	Command *c;
+
 	dprint("%M successfully reached goal\n", mo);
-	nextstate(mo);
+	c = mo->cmds;
+	if(c->target1 == nil){
+		nextstate(mo);
+		return;
+	}
+	facemobj(mo, c->target1);
+	c->stepfn = turnstep;
 }
 
 static void
@@ -92,6 +119,8 @@
 	abortcommands(mo);
 }
 
+/* FIXME: kind of weird to mix up argument order,
+ * mo should be first like elsewhere */
 static int
 repath(Point p, Mobj *mo)
 {
@@ -229,6 +258,13 @@
 		mo->θ -= 256;
 	mo->Δθ -= Δθ;
 	return r;
+}
+
+static void
+turnstep(Mobj *mo)
+{
+	if(!tryturn(mo))
+		movereallyreallyreallydone(mo);
 }
 
 static int