shithub: battleship

Download patch

ref: 4f514003a8236aaeb9621b932c0f8329e03c1dd8
parent: 344e764a193a70807d429e54c36f4cf5a5d0e8c7
author: rodri <rgl@antares-labs.eu>
date: Fri Sep 1 07:07:48 EDT 2023

change mmb to rotate the ship without presenting a menu.

--- a/bts.c
+++ b/bts.c
@@ -39,15 +39,15 @@
 };
 Cursor boxcursor = {
 	{-7, -7},
-	{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-	  0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F,
-	  0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF,
-	  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+	{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+	  0xff, 0xff, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
+	  0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xff, 0xff,
+	  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
 	},
-	{ 0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE,
-	  0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
-	  0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
-	  0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00
+	{ 0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe,
+	  0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e,
+	  0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e,
+	  0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x00, 0x00
 	}
 };
 Cursor aimcursor = {
@@ -500,47 +500,38 @@
 void
 mmb(Mousectl *mc)
 {
-	enum {
-		ROTATE,
-	};
-	static char *items[] = {
-	 [ROTATE]	"rotate ship",
-		nil
-	};
-	static Menu menu = { .item = items };
-
 	if(game.state != Outlaying)
 		return;
 
-	mc->xy = addpt(mc->xy, screen->r.min);
-	switch(menuhit(2, mc, &menu, _screen)){
-	case ROTATE:
-		if(curship != nil){
-			curship->orient = curship->orient == OH? OV: OH;
-			curship->bbox = mkshipbbox(curship->p, curship->orient, curship->ncells);
+	if(curship != nil){
+		curship->orient = curship->orient == OH? OV: OH;
+		curship->bbox = mkshipbbox(curship->p, curship->orient, curship->ncells);
 
-			/* steer it, captain! don't let it go off-board! */
-			if(!rectinrect(curship->bbox, localboard.bbox)){
-				switch(curship->orient){
-				case OH:
-					curship->bbox.min.x -= curship->bbox.max.x-localboard.bbox.max.x;
-					curship->bbox.max.x = localboard.bbox.max.x;
-					break;
-				case OV:
-					curship->bbox.min.y -= curship->bbox.max.y-localboard.bbox.max.y;
-					curship->bbox.max.y = localboard.bbox.max.y;
-					break;
-				}
-				curship->p = toboard(&localboard, curship->bbox.min);
-				moveto(mc, addpt(screen->r.min, curship->bbox.min));
+		if(debug)
+			fprint(2, "curship orient %c\n", curship->orient == OH? 'h': 'v');
+
+		/* steer it, captain! don't let it go off-board! */
+		if(!rectinrect(curship->bbox, localboard.bbox)){
+			switch(curship->orient){
+			case OH:
+				curship->bbox.min.x -= curship->bbox.max.x-localboard.bbox.max.x;
+				curship->bbox.max.x = localboard.bbox.max.x;
+				break;
+			case OV:
+				curship->bbox.min.y -= curship->bbox.max.y-localboard.bbox.max.y;
+				curship->bbox.max.y = localboard.bbox.max.y;
+				break;
 			}
-			/* …nor ram allied ships! */
-			if(rectXarmada(curship->bbox))
-				curship->bbox = ZR;
+			curship->p = toboard(&localboard, curship->bbox.min);
+			moveto(mc, addpt(screen->r.min, curship->bbox.min));
+			readmouse(mc); /* ignore mmb click triggered by moveto */
 		}
-		break;
+		/* …nor ram allied ships! */
+		if(rectXarmada(curship->bbox))
+			curship->bbox = ZR;
+
+		send(drawchan, nil);
 	}
-	send(drawchan, nil);
 }
 
 void
--- a/readme.md
+++ b/readme.md
@@ -11,12 +11,11 @@
 Then wait for another player to show up (admire the velero).  When
 they do, you'll have to place your ships in the lower (local) board by
 clicking LMB when the ship is at the right location; you can also
-change the orientation of the ship by pressing MMB and selecting
-“rotate ship”.  If you are not happy with the current layout, press
-RMB and select “place ships” to start all over again (tip: if you
-don't want to move a ship, click LMB without moving the mouse.) Once
-you are done—a banner at the bottom will inform you—, press RMB and
-choose “done”.
+change the orientation of the ship by pressing MMB.  If you are not
+happy with the current layout, press RMB and select “place ships” to
+start all over again (tip: if you don't want to move a ship, click LMB
+without moving the mouse.) Once you are done—a banner at the bottom
+will inform you—, press RMB and choose “done”.
 
 At this moment the battle will begin.  Each of you has a turn (read
 [battleship.pdf](battleship.pdf)), and if you are the one shooting you
@@ -26,5 +25,5 @@
 just do that.
 
 There's no turn timeout so the battles can get as long as any of the
-players's will.  If you quit or your connection is lost, your opponent
+players will.  If you quit or your connection is lost, your opponent
 wins.