aboutsummaryrefslogtreecommitdiff
path: root/bts.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-09-01 21:41:09 +0000
committerrodri <rgl@antares-labs.eu>2023-09-01 21:41:09 +0000
commit2723bb6ff3e339f7f56a6276fa1c7c9f28d63871 (patch)
tree5398980304f82a0332fb7f846a4d9f9e90785f5a /bts.c
parenta764a5069421930c9261f87f02b0b4db3e80783b (diff)
downloadbattleship-2723bb6ff3e339f7f56a6276fa1c7c9f28d63871.tar.gz
battleship-2723bb6ff3e339f7f56a6276fa1c7c9f28d63871.tar.bz2
battleship-2723bb6ff3e339f7f56a6276fa1c7c9f28d63871.zip
obtain each player's username and show it during battle.
Diffstat (limited to 'bts.c')
-rw-r--r--bts.c23
1 files changed, 21 insertions, 2 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);