aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bts.c23
-rw-r--r--btsd.c20
-rw-r--r--dat.h1
3 files changed, 35 insertions, 9 deletions
diff --git a/bts.c b/bts.c
index a167f86..093b4fe 100644
--- a/bts.c
+++ b/bts.c
@@ -65,6 +65,7 @@ Cursor aimcursor = {
};
char deffont[] = "/lib/font/bit/pelm/unicode.9.font";
char winspec[32];
+char uid[8+1], oid[8+1];
Channel *drawchan;
Channel *ingress, *egress;
Mousectl *mctl; /* only used to update the cursor */
@@ -172,6 +173,7 @@ resetgame(void)
}
curship = nil;
layoutdone = 0;
+ oid[0] = 0;
}
Point
@@ -272,11 +274,15 @@ drawinfo(Image *dst)
s = "TARGET";
p = subpt(alienboard.bbox.min, Pt(font->width+2,0));
vstring(dst, p, display->white, ZP, font, s);
-
s = "LOCAL";
p = Pt(localboard.bbox.max.x+2, localboard.bbox.min.y);
vstring(dst, p, display->white, ZP, font, s);
+ p = Pt(alienboard.bbox.max.x+2, alienboard.bbox.min.y);
+ vstring(dst, p, display->white, ZP, font, oid);
+ p = subpt(localboard.bbox.min, Pt(font->width+2,0));
+ vstring(dst, p, display->white, ZP, font, uid);
+
if(game.state == Outlaying){
if(c == nil)
c = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DYellow);
@@ -716,7 +722,8 @@ processcmd(char *cmd)
if(strcmp(cmd, "layout") == 0){
game.state = Outlaying;
curship = &armada[0];
- }
+ }else if(strcmp(cmd, "id") == 0)
+ chanprint(egress, "id %s\n", uid);
csetcursor(mctl, &patrolcursor);
break;
case Outlaying:
@@ -725,6 +732,8 @@ processcmd(char *cmd)
csetcursor(mctl, &waitcursor);
}else if(strcmp(cmd, "play") == 0)
game.state = Playing;
+ else if(strncmp(cmd, "oid", 3) == 0)
+ snprint(oid, sizeof oid, "%s", cmd+4);
break;
case Playing:
if(strcmp(cmd, "wait") == 0){
@@ -812,6 +821,13 @@ void
threadmain(int argc, char *argv[])
{
char *addr;
+ /*
+ * TODO
+ * if it's not static it messes with in.mc->xy later, probably
+ * because of an stack overflow somewhere. have to investigate
+ * with wpset("w", &in.mc->xy, sizeof(Point*)); in acid(1)
+ */
+ static char *user;
int fd;
Input in;
@@ -849,6 +865,9 @@ threadmain(int argc, char *argv[])
unlockdisplay(display);
mctl = in.mc;
+ if((user = getenv("user")) == nil)
+ user = getuser();
+ snprint(uid, sizeof uid, "%s", user);
screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), screen->chan, 0, DNofill);
worldrf.p = Pt2(0,0,1);
diff --git a/btsd.c b/btsd.c
index cef60b0..5a722d2 100644
--- a/btsd.c
+++ b/btsd.c
@@ -139,11 +139,8 @@ battleproc(void *arg)
threadcreate(netrecvthread, &cp[0], mainstacksize);
threadcreate(netrecvthread, &cp[1], mainstacksize);
- /* TODO ask for the username */
- write(m->pl[0]->fd, "layout\n", 7);
- write(m->pl[1]->fd, "layout\n", 7);
- m->pl[0]->state = Outlaying;
- m->pl[1]->state = Outlaying;
+ write(m->pl[0]->fd, "id\n", 3);
+ write(m->pl[1]->fd, "id\n", 3);
while((i = alt(a)) >= 0){
p = m->pl[i];
@@ -161,6 +158,17 @@ battleproc(void *arg)
fprint(2, "[%d] said '%s'\n", i, s);
switch(p->state){
+ case Waiting0:
+ if(strncmp(s, "id", 2) == 0){
+ snprint(p->name, sizeof p->name, "%s", strlen(s) > 3? s+3: "???");
+ write(p->fd, "layout\n", 7);
+ p->state = Outlaying;
+ if(op->state == Outlaying){
+ fprint(p->fd, "oid %s\n", op->name);
+ fprint(op->fd, "oid %s\n", p->name);
+ }
+ }
+ break;
case Outlaying:
if(strncmp(s, "layout", 6) == 0)
if(gettokens(s+7, coords, nelem(coords), ",") == nelem(coords)){
@@ -173,8 +181,6 @@ battleproc(void *arg)
settiles(p, cell, orient, shiplen(j), Tship);
}
p->state = Waiting;
- if(debug)
- fprint(2, "curstates [%d] %d / [%d] %d\n", i, p->state, i^1, op->state);
if(op->state == Waiting){
if(debug){
fprint(2, "map%d:\n", i);
diff --git a/dat.h b/dat.h
index 6c443c0..a4a5df3 100644
--- a/dat.h
+++ b/dat.h
@@ -71,6 +71,7 @@ struct Board
struct Player
{
Map;
+ char name[8+1];
int fd;
int sfd;
int state;