+ for (y = y1 + 1; y < y2; y++) {
+ mvaddch(y, x1, Sets.ascii ? '|' : ACS_VLINE); //left
+ mvaddch(y, x2, Sets.ascii ? '|' : ACS_VLINE); //right
+ } //draw vertical lines
+ move(y1, x1); //top
+ addch(Sets.ascii ? '+' : ACS_ULCORNER);
+ for (x = x1 + 1; x < x2; x++)
+ addch(Sets.ascii ? '-' : ACS_HLINE);
+ addch(Sets.ascii ? '+' : ACS_URCORNER);
+ move(y2, x1); //bottom
+ addch(Sets.ascii ? '+' : ACS_LLCORNER);
+ for (x = x1 + 1; x < x2; x++)
+ addch(Sets.ascii ? '-' : ACS_HLINE);
+ addch(Sets.ascii ? '+' : ACS_LRCORNER);
+}
+
+void window_draw(int player)
+{ //draw field for player
+ if (!window[player].shown) return;
+ window_border(window[player].posx - 1, window[player].posy - Players[player].boardVisible,
+ window[player].posx + window[player].size * Players[player].boardWidth, window[player].posy + 1);
+ {
+ char s[window[player].size * Players[player].boardWidth + 1];
+
+ if (Players[player].host && Players[player].host[0])
+ snprintf(s, sizeof(s), " %s <%s> ",
+ Players[player].name, Players[player].host);
+ else snprintf(s, sizeof(s), " %s ", Players[player].name);
+ s[sizeof(s)] = 0;
+ if (haveColor && Players[player].team > 0 && Players[player].team <= 7)
+ attrset(A_REVERSE | COLOR_PAIR(Players[player].team + 1));
+ mvaddstr(1, window[player].posx, s);
+ if (haveColor) standend();
+ } //display playername/host
+
+ {
+ int x, y;
+ for (y = 0; y <= Players[player].boardVisible; y++)
+ for (x = 0; x <= Players[player].boardWidth; x++)
+ block_draw_window(player, y, x, block_get(player, y, x));
+ } //draw field
+
+ window_msg_status(player);
+}
+
+void screen_setup(void)
+{ //calculate positions of all fields
+ int i, prev;
+ int y, x;
+ int spaceavail;
+
+ clear();
+ DrawTitle();
+ getmaxyx(stdscr, y, x);
+ window[me].size = 2;
+ window[me].posx = 1;
+ window[me].posy = 21;
+ window[me].shown = 1;
+ statusXPos = window[me].size * Players[me].boardWidth + 3;
+ statusYPos = 21;
+ status_draw(me, Players[me].score);
+
+ messageXPos = 2;
+ messageYPos = 24;
+ messageWidth = MIN(x - messageXPos - 2, MSG_WIDTH);
+ messageHeight = MIN(y - messageYPos - 1, MSG_HEIGHT);
+ if (messageHeight < 3) {
+ messageWidth = MIN(x - statusXPos - 18, 27);
+ messageHeight = y - 3;
+ messageXPos = statusXPos + 16;
+ messageYPos = 2;
+ } //messagebox doesn't fit below
+ window_border(messageXPos - 2, messageYPos - 1,
+ messageXPos + messageWidth + 1, messageYPos+messageHeight);
+ if (msgwin = subwin(stdscr, messageHeight, messageWidth,
+ messageYPos, messageXPos))
+ scrollok(msgwin, 1); //allow scrolling
+ wmove(msgwin, messageHeight - 2, 0);
+ for (i = messageHeight - 2; i >= 0; i--) //display message history
+ msg_draw(message[i]);
+
+ spaceavail = x;
+ for (i = 1; i <= maxPlayer; i++)
+ spaceavail -= Players[i].boardWidth+2;
+ prev = me;
+ for (i = 1; i < MAX_SCREENS; i++) if (i != me) {
+ window[i].posy = 21;
+ window[i].posx =
+ window[prev].posx + 2 + window[prev].size * Players[prev].boardWidth;
+ if (prev == me) {
+ window[i].posx += 15; //scorebar
+ if (messageYPos < 24)
+ window[i].posx += messageWidth + 4; //messagebox
+ spaceavail -= window[i].posx - 3;
+ } //stuff before second player
+ if (spaceavail >= 0) {
+ window[i].size = 2;
+ spaceavail -= Players[i].boardWidth;
+ } //not enough space, half width
+ else
+ window[i].size = 1;
+ if (x < window[i].posx + 1 + window[i].size * Players[i].boardWidth)
+ window[i].shown = 0; //field doesn't fit on screen
+ else
+ window[i].shown = 1;
+ prev = i;