shithub: sce

Download patch

ref: 0891f6208a02a6b22decb65358e78ca0b61d39ec
parent: b3280e12afd42fe9ae744805c72cfe3858a746cd
author: qwx <qwx@sciops.net>
date: Tue Nov 23 18:32:07 EST 2021

sim.gather: simple gather loop, update resources

--- a/dat.h
+++ b/dat.h
@@ -116,6 +116,7 @@
 	OSidle = OState0,
 	OSmove = OState1,
 	OSgather = OState2,
+	OSwait = OState3,	/* FIXME: ← better solution */
 
 	/* resource */
 	OSrich = OState0,
--- a/drw.c
+++ b/drw.c
@@ -335,7 +335,7 @@
 	Pic *p;
 
 	n = mo->state;
-	if(n == OSskymaybe)
+	if(n == OSskymaybe || n == OSwait)
 		n = OSidle;
 	if(n < 0 || n > OSend){
 		dprint("frm: %M invalid animation frame %d\n", mo, n);
--- a/sim.c
+++ b/sim.c
@@ -11,6 +11,7 @@
 	[OSidle] "idle",
 	[OSmove] "moving",
 	[OSgather] "gathering",
+	[OSwait] "waiting",
 };
 
 static Mobjl mobjl0 = {.l = &mobjl0, .lp = &mobjl0}, *mobjl = &mobjl0;
--- a/sim.gather.c
+++ b/sim.gather.c
@@ -8,6 +8,7 @@
 /* FIXME: additional bullshit logic */
 
 enum{
+	Twait = 8,
 	Tgather = 75,	/* FIXME: 37 for gas, define in db? */
 	Namount = 8,
 };
@@ -18,16 +19,40 @@
 }
 
 static void
+returncargo(Mobj *mo)
+{
+	Resource *r;
+	Command *c;
+
+	c = mo->cmds;
+	r = c->target1->o->res;
+	assert(r != nil);
+	teams[mo->team].r[r-resources] += Namount;
+}
+
+static void
+waitstep(Mobj *mo)
+{
+	Command *c;
+
+	c = mo->cmds;
+	if(--c->tc > 0)
+		return;
+	nextstate(mo);
+}
+
+static void
 step(Mobj *mo)
 {
 	Command *c;
 
 	c = mo->cmds;
-	if(++c->tc >= Tgather){
-		nextstate(mo);
+	if(++c->tc < Tgather)
 		return;
-	}
-	// FIXME: butts
+	returncargo(mo);
+	mo->state = OSwait;
+	c->stepfn = waitstep;
+	c->tc = nrand(Twait+1);
 }
 
 static int
@@ -39,7 +64,7 @@
 	/* FIXME: check if resource still exists? (and amount >0) (needs despawning/death) */
 	c->cleanupfn = cleanup;
 	c->stepfn = step;
-	c->nextfn = nil;
+	c->nextfn = pushgather;
 	c->tc = 0;
 	mo->state = OSgather;
 	return 0;