ref: 2834b114cfe13279b5742649cc655506c53dde8c
parent: 786f41cb2f7787933a0f939a221728b844776702
author: rodri <rgl@antares-labs.eu>
date: Thu Sep 28 13:18:54 EDT 2023
added a border to the boards and corrected a bug when placing a ship. the bug allowed the player to move the ship when the cursor was outside the board in the negative side of its rframe. by using floor(2) instead of a cast to int the problem is over.
--- a/bts.c
+++ b/bts.c
@@ -19,6 +19,7 @@
PCBlue,
PCWater,
PCWaves,
+ PCBrown,
PCShadow,
NCOLORS
};
@@ -180,8 +181,8 @@
Point2 np;
np = rframexform(rframexform(Pt2(p.x,p.y,1), worldrf), *b);
- np.x = (int)np.x;
- np.y = (int)np.y;
+ np.x = floor(np.x);
+ np.y = floor(np.y);
return np;
}
@@ -308,6 +309,7 @@
{
int i, j;
+ border(dst, b->bbox, -Borderwidth, pal[PCBrown], ZP);
for(i = 0; i < MAPW; i++)
for(j = 0; j < MAPH; j++)
drawtile(dst, b, Pt2(i,j,1), b->map[i][j]);
@@ -351,15 +353,15 @@
string(dst, p, pal[PCWhite], ZP, font, s);
s = "TARGET";
- p = subpt(alienboard.bbox.min, Pt(font->width+2,0));
+ p = subpt(alienboard.bbox.min, Pt(font->width+2+Borderwidth,0));
vstring(dst, p, pal[PCWhite], ZP, font, s);
s = "LOCAL";
- p = Pt(localboard.bbox.max.x+2, localboard.bbox.min.y);
+ p = Pt(localboard.bbox.max.x+2+Borderwidth, localboard.bbox.min.y);
vstring(dst, p, pal[PCWhite], ZP, font, s);
- p = Pt(alienboard.bbox.max.x+2, alienboard.bbox.min.y);
+ p = Pt(alienboard.bbox.max.x+2+Borderwidth, alienboard.bbox.min.y);
vstring(dst, p, pal[PCWhite], ZP, font, game.state == Watching? match.pl[1].uid: oid);
- p = subpt(localboard.bbox.min, Pt(font->width+2,0));
+ p = subpt(localboard.bbox.min, Pt(font->width+2+Borderwidth,0));
vstring(dst, p, pal[PCWhite], ZP, font, game.state == Watching? match.pl[0].uid: uid);
/* TODO make this an info panel and show errors from bad transactions. */
@@ -462,6 +464,7 @@
pal[PCWater] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreyblue);
pal[PCWaves] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalebluegreen);
pal[PCBlue] = pal[PCWaves];
+ pal[PCBrown] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x806000FF);
pal[PCShadow] = eallocimage(display, Rect(0,0,1,1), RGBA32, 1, 0x0000007f);
}
@@ -508,13 +511,13 @@
initboards(void)
{
memset(alienboard.map, Twater, MAPW*MAPH);
- alienboard.p = Pt2(Boardmargin,Boardmargin,1);
+ alienboard.p = Pt2(Boardmargin+Borderwidth,Boardmargin+Borderwidth,1);
alienboard.bx = Vec2(TW,0);
alienboard.by = Vec2(0,TH);
alienboard.bbox = Rpt(fromworld(alienboard.p), fromworld(addpt2(alienboard.p, Pt2(TW*MAPW,TH*MAPH,1))));
memset(localboard.map, Twater, MAPW*MAPH);
- localboard.p = addpt2(alienboard.p, Vec2(0,MAPH*TH+TH));
+ localboard.p = addpt2(alienboard.p, Vec2(0,MAPH*TH+Borderwidth+TH+Borderwidth));
localboard.bx = Vec2(TW,0);
localboard.by = Vec2(0,TH);
localboard.bbox = Rpt(fromworld(localboard.p), fromworld(addpt2(localboard.p, Pt2(TW*MAPW,TH*MAPH,1))));
--- a/dat.h
+++ b/dat.h
@@ -30,8 +30,12 @@
TH = TW,
MAPW = 17,
MAPH = MAPW,
- SCRW = Boardmargin+MAPW*TW+Boardmargin,
- SCRH = Boardmargin+MAPH*TH+TH+MAPH*TH+Boardmargin,
+ SCRW = Boardmargin + Borderwidth+MAPW*TW+Borderwidth + Boardmargin,
+ SCRH = Boardmargin+
+ Borderwidth+MAPH*TH+Borderwidth+
+ TH+
+ Borderwidth+MAPH*TH+Borderwidth+
+ Boardmargin,
KB = 1024,
BY2MAP = (TBITS*MAPW*MAPH+7)/8,
@@ -136,7 +140,7 @@
{
Mentry *entries;
int nentries;
- int filling;
+ int filling; /* lock-alike */
};
struct Menulist
--- a/fns.h
+++ b/fns.h
@@ -21,8 +21,8 @@
int shiplen(int);
char *shipname(int);
char *statename(int);
-int max(int, int);
int min(int, int);
+int max(int, int);
int bitpackmap(uchar*, ulong, Map*);
int bitunpackmap(Map*, uchar*, ulong);
int chanvprint(Channel*, char*, va_list);
--- a/util.c
+++ b/util.c
@@ -146,15 +146,15 @@
}
int
-max(int a, int b)
+min(int a, int b)
{
- return a > b? a: b;
+ return a < b? a: b;
}
int
-min(int a, int b)
+max(int a, int b)
{
- return a < b? a: b;
+ return a > b? a: b;
}
int