shithub: sce

Download patch

ref: 2a9f768f9e36997f1cc75773ad892cfc72719ea0
parent: 219ea3130072f8e0fed4bd78d3d5eb668f698a13
author: qwx <qwx@sciops.net>
date: Sat Nov 20 21:55:10 EST 2021

sim: rudimentary and unreachable gather state

pathing:
1) not using nearest point on the mobj
2) ignoring whether arrived next to object
so move always fails

--- a/com.c
+++ b/com.c
@@ -97,6 +97,10 @@
 	}
 	if((tgt = mobjfromreq(&reqt)) == nil)
 		return -1;
+	if((tgt->o->f & Fresource) == 0){
+		werrstr("reqgather: target %M not a resource", tgt);
+		return -1;
+	}
 	if(click.x >= nodemapwidth || click.y >= nodemapheight){
 		werrstr("reqgather: invalid location %d,%d", click.x, click.y);
 		return -1;
--- a/drw.c
+++ b/drw.c
@@ -68,7 +68,7 @@
 }
 
 void
-domove(Point p)
+doaction(Point p)
 {
 	int i;
 	Point vp;
@@ -81,7 +81,7 @@
 	i = fbvis[vp.y * fbw + vp.x];
 	mo = i == -1 ? nil : visbuf[i];
 	if(mo == it){
-		dprint("select: %M not moving to itself\n", it);
+		dprint("doaction: %M targeting itself\n", it);
 		return;
 	}
 	p = divpt(addpt(subpt(p, selr.min), pan), scale);
@@ -88,12 +88,15 @@
 	p.x /= Nodewidth;
 	p.y /= Nodeheight;
 	if(nodemapwidth - p.x < it->o->w || nodemapheight - p.y < it->o->h){
-		dprint("select: %M not moving beyond map edge\n", it);
+		dprint("doaction: %M destination beyond map edge\n", it);
 		return;
 	}
-	if(mo != nil)
-		sendmovenear(it, p, mo);
-	else
+	if(mo != nil){
+		if((mo->o->f & Fresource) && (it->o->f & Fgather))
+			sendgather(it, p, mo);
+		else
+			sendmovenear(it, p, mo);
+	}else
 		sendmove(it, p);
 }
 
--- a/fns.h
+++ b/fns.h
@@ -3,6 +3,7 @@
 void	initnet(char*);
 int	parsemsg(Msg*);
 void	endmsg(Msg*);
+int	sendgather(Mobj*, Point, Mobj*);
 int	sendmovenear(Mobj*, Point, Mobj*);
 int	sendmove(Mobj*, Point);
 int	sendpause(void);
@@ -31,7 +32,7 @@
 Msg*	getclbuf(void);
 void	dopan(Point);
 void	doselect(Point);
-void	domove(Point);
+void	doaction(Point);
 void	compose(int, int, u32int);
 void	redraw(void);
 void	updatefb(void);
@@ -43,6 +44,7 @@
 Mobj*	unitat(int, int);
 int	isblocked(int, int, Obj*);
 void	markmobj(Mobj*, int);
+int	isnextto(Mobj*, Mobj*);
 int	findpath(Point, Mobj*);
 Mobj*	mapspawn(int, int, Obj*);
 void	initmap(void);
--- a/path.c
+++ b/path.c
@@ -444,6 +444,18 @@
 	assert(p == mo->paths - 1);
 }
 
+int
+isnextto(Mobj *, Mobj *tgt)
+{
+	if(tgt == nil)
+		return 0;
+	/*
+	FIXME: ??
+		get nearest tgt node, distance = 0? other functions would use that too
+	*/
+	return 0;
+}
+
 static Node *
 nearestnonjump(Node *n, Node *b, Mobj *mo)
 {
--- a/sce.c
+++ b/sce.c
@@ -223,7 +223,7 @@
 			if(me.b & 2)
 				dopan(me.Δ);
 			if(me.b & 4)
-				domove(me);
+				doaction(me);
 			qunlock(&drawlock);
 			flushcl();
 			break;
--- a/sim.move.c
+++ b/sim.move.c
@@ -271,6 +271,11 @@
 		movedone(mo);
 		return;
 	}
+	if(isnextto(mo, mo->cmds[0].target1)){
+		dprint("%M stepmove: next to target, stopping\n", mo);
+		movedone(mo);
+		return;
+	}
 	dprint("%M stepmove: reached final node, but not target\n", mo);
 	if(mo->goalblocked && isblocked(mo->target.x, mo->target.y, mo->o)){
 		dprint("%M stepmove: goal still blocked, stopping\n", mo);