shithub: sce

Download patch

ref: 97914a3f07abd4bd71d0a54ca11cd9693d22a081
parent: afa5c513017b1d6dccd1dbee33fa79d110d4b19a
author: qwx <qwx@sciops.net>
date: Tue Nov 23 17:14:19 EST 2021

sim: add waypoints

- stop message unless shift is pressed down
- workaround for shift key swapping mb 2 and 3 (real fix → ?)
- subsequent queued moves can attempt to move unit to itself;
ideally should be rejected/skipped immediately, but
invalidation can only be done server-side when queuing
commands, dunno

--- a/com.c
+++ b/com.c
@@ -105,7 +105,6 @@
 		werrstr("reqgather: invalid location %d,%d", click.x, click.y);
 		return -1;
 	}
-	clearcommands(mo);
 	if(pushgathercommand(click, mo, tgt) < 0)
 		return -1;
 	return n;
@@ -135,7 +134,6 @@
 		werrstr("reqmovenear: invalid location %d,%d", click.x, click.y);
 		return -1;
 	}
-	clearcommands(mo);
 	if(pushmovecommand(click, mo, tgt) < 0)
 		return -1;
 	return n;
@@ -162,7 +160,6 @@
 		werrstr("reqmove: invalid target %d,%d", tgt.x, tgt.y);
 		return -1;
 	}
-	clearcommands(mo);
 	if(pushmovecommand(tgt, mo, nil) < 0)
 		return -1;
 	return n;
@@ -169,6 +166,21 @@
 }
 
 static int
+reqstop(uchar *p, uchar *e)
+{
+	int n;
+	Mobj reqm, *mo;
+
+	if((n = unpack(p, e, "dldd",
+	&reqm.idx, &reqm.uuid, &reqm.x, &reqm.y)) < 0)
+		return -1;
+	if((mo = mobjfromreq(&reqm)) == nil)
+		return -1;
+	clearcommands(mo);
+	return n;
+}
+
+static int
 reqpause(uchar *, uchar *)
 {
 	pause ^= 1;
@@ -205,6 +217,7 @@
 		type = *p++;
 		switch(type){
 		case CTpause: fn = reqpause; break;
+		case CTstop: fn = reqstop; break;
 		case CTmove: fn = reqmove; break;
 		case CTmovenear: fn = reqmovenear; break;
 		case CTgather: fn = reqgather; break;
@@ -332,6 +345,20 @@
 	mo->idx, mo->uuid, mo->x, mo->y,
 	tgt.x, tgt.y) < 0){
 		fprint(2, "sendmove: %r\n");
+		return -1;
+	}
+	return 0;
+}
+
+int
+sendstop(Mobj *mo)
+{
+	Msg *m;
+
+	m = getclbuf();
+	if(packmsg(m, "h dldd", CTstop,
+	mo->idx, mo->uuid, mo->x, mo->y) < 0){
+		fprint(2, "sendstop: %r\n");
 		return -1;
 	}
 	return 0;
--- a/dat.h
+++ b/dat.h
@@ -262,6 +262,7 @@
 enum{
 	CTquit = 0x1f,
 	CTpause,
+	CTstop,
 	CTmove,
 	CTmovenear,
 	CTgather,
--- a/drw.c
+++ b/drw.c
@@ -68,7 +68,7 @@
 }
 
 void
-doaction(Point p)
+doaction(Point p, int clearcmds)
 {
 	int i;
 	Point vp;
@@ -91,6 +91,8 @@
 		dprint("doaction: %M destination beyond map edge\n", it);
 		return;
 	}
+	if(clearcmds)
+		sendstop(it);
 	if(mo != nil){
 		if((mo->o->f & Fresource) && (it->o->f & Fgather))
 			sendgather(it, p, mo);
--- a/fns.h
+++ b/fns.h
@@ -5,6 +5,7 @@
 void	endmsg(Msg*);
 int	sendgather(Mobj*, Point, Mobj*);
 int	sendmovenear(Mobj*, Point, Mobj*);
+int	sendstop(Mobj*);
 int	sendmove(Mobj*, Point);
 int	sendpause(void);
 void	stepsnd(void);
@@ -33,7 +34,7 @@
 Msg*	getclbuf(void);
 void	dopan(Point);
 void	doselect(Point);
-void	doaction(Point);
+void	doaction(Point, int);
 void	compose(int, int, u32int);
 void	redraw(void);
 void	updatefb(void);
--- a/sce.c
+++ b/sce.c
@@ -158,7 +158,7 @@
 void
 threadmain(int argc, char **argv)
 {
-	int tv;
+	int tv, shiftdown;
 	Kev ke;
 	Mev me;
 
@@ -195,6 +195,7 @@
 	initfs();
 	initsv(tv, *argv);
 	initcl();
+	shiftdown = 0;
 	enum{
 		Aresize,
 		Amouse,
@@ -220,16 +221,21 @@
 			qlock(&drawlock);	/* just for security */
 			if(me.b & 1)
 				doselect(me);
-			if(me.b & 2)
-				dopan(me.Δ);
-			if(me.b & 4)
-				doaction(me);
+			/* FIXME */
+			if(me.b & 2){
+				if(!shiftdown) dopan(me.Δ); else doaction(me, 0);
+			}
+			if(me.b & 4){
+				if(!shiftdown) doaction(me, 1); else dopan(me.Δ);
+			}
 			qunlock(&drawlock);
 			flushcl();
 			break;
 		case Akbd:
-			if(ke.r == Kdel)
-				threadexitsall(nil);
+			switch(ke.r){
+			case Kdel: threadexitsall(nil);
+			case Kshift: shiftdown = ke.down; break;
+			}
 			if(!ke.down)
 				continue;
 			switch(ke.r){
--- a/sim.c
+++ b/sim.c
@@ -144,10 +144,12 @@
 			abortcommands(mo);
 			continue;
 		}
-		if(mo->state == OSskymaybe)
-			sysfatal("updatemobj: %s cmd %s impossible/stale state %d",
-				mo->o->name, mo->cmds[0].name, mo->state);
-		c->stepfn(mo);
+		if(mo->state == OSskymaybe){
+			dprint("%M updatemobj: %s cmd %s init bailed early\n",
+				mo, mo->o->name, mo->cmds[0].name);
+			nextstate(mo);
+		}else
+			c->stepfn(mo);
 	}
 }
 
--- a/sim.move.c
+++ b/sim.move.c
@@ -300,6 +300,11 @@
 	c = mo->cmds;
 	c->cleanupfn = cleanup;
 	goal = c->goal;
+	/* FIXME: shitty */
+	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;