1 /* Tetrinet for Linux, by Andrew Church <achurch@achurch.org>
2 * This program is public domain.
4 * Text terminal I/O routines.
21 /*************************************************************************/
23 #define MY_HLINE (fancy ? ACS_HLINE : '-')
24 #define MY_VLINE (fancy ? ACS_VLINE : '|')
25 #define MY_ULCORNER (fancy ? ACS_ULCORNER : '+')
26 #define MY_URCORNER (fancy ? ACS_URCORNER : '+')
27 #define MY_LLCORNER (fancy ? ACS_LLCORNER : '+')
28 #define MY_LRCORNER (fancy ? ACS_LRCORNER : '+')
30 #define MY_HLINE2 (fancy ? (ACS_HLINE | A_BOLD) : '=')
31 #define MY_BOLD (fancy ? A_BOLD : 0)
33 /*************************************************************************/
34 /******************************* Input stuff *****************************/
35 /*************************************************************************/
37 /* Return either an ASCII code 0-255, a K_* value, or -1 if server input is
38 * waiting. Return -2 if we run out of time with no input.
41 static int wait_for_input(int msec
)
46 static int escape
= 0;
50 FD_SET(server_sock
, &fds
);
51 tv
.tv_sec
= msec
/1000;
52 tv
.tv_usec
= (msec
*1000) % 1000000;
53 while (select(server_sock
+1, &fds
, NULL
, NULL
, msec
<0 ? NULL
: &tv
) < 0) {
55 perror("Warning: select() failed");
57 if (FD_ISSET(0, &fds
)) {
59 if (!escape
&& c
== 27) { /* Escape */
61 c
= wait_for_input(1000);
70 else if (c
== KEY_DOWN
)
72 else if (c
== KEY_LEFT
)
74 else if (c
== KEY_RIGHT
)
76 else if (c
== KEY_F(1) || c
== ('1'|0x80) || (escape
&& c
== '1'))
78 else if (c
== KEY_F(2) || c
== ('2'|0x80) || (escape
&& c
== '2'))
80 else if (c
== KEY_F(3) || c
== ('3'|0x80) || (escape
&& c
== '3'))
82 else if (c
== KEY_F(4) || c
== ('4'|0x80) || (escape
&& c
== '4'))
84 else if (c
== KEY_F(5) || c
== ('5'|0x80) || (escape
&& c
== '5'))
86 else if (c
== KEY_F(6) || c
== ('6'|0x80) || (escape
&& c
== '6'))
88 else if (c
== KEY_F(7) || c
== ('7'|0x80) || (escape
&& c
== '7'))
90 else if (c
== KEY_F(8) || c
== ('8'|0x80) || (escape
&& c
== '8'))
92 else if (c
== KEY_F(9) || c
== ('9'|0x80) || (escape
&& c
== '9'))
94 else if (c
== KEY_F(10) || c
== ('0'|0x80) || (escape
&& c
== '0'))
96 else if (c
== KEY_F(11))
98 else if (c
== KEY_F(12))
100 else if (c
== KEY_BACKSPACE
)
102 else if (c
>= 0x0100)
104 else if (c
== 7) /* ^G */
105 return 27; /* Escape */
108 } /* if (FD_ISSET(0, &fds)) */
109 else if (FD_ISSET(server_sock
, &fds
))
112 return -2; /* out of time */
115 /*************************************************************************/
116 /****************************** Output stuff *****************************/
117 /*************************************************************************/
119 /* Size of the screen */
120 static int scrwidth
, scrheight
;
122 /* Is color available? */
123 static int has_color
;
125 /*************************************************************************/
130 int x
, y
, width
, height
;
132 WINDOW
*win
; /* NULL if not currently displayed */
136 static TextBuffer plinebuf
, gmsgbuf
, attdefbuf
;
138 /*************************************************************************/
140 /* Window for typing in-game text, and its coordinates: */
142 static WINDOW
*gmsg_inputwin
;
143 static int gmsg_inputpos
, gmsg_inputheight
;
145 /*************************************************************************/
146 /*************************************************************************/
148 /* Clean up the screen on exit. */
150 static void screen_cleanup()
152 wmove(stdscr
, scrheight
-1, 0);
158 /*************************************************************************/
160 /* Little signal handler that just does an exit(1) (thereby getting our
161 * cleanup routine called), except for TSTP, which does a clean suspend.
164 static void (*old_tstp
)(int sig
);
166 static void sighandler(int sig
)
168 if (sig
!= SIGTSTP
) {
170 psignal(sig
, "tetrinet");
174 signal(SIGTSTP
, old_tstp
);
177 signal(SIGTSTP
, sighandler
);
180 /*************************************************************************/
181 /*************************************************************************/
183 #define MAXCOLORS 256
185 static int colors
[MAXCOLORS
][2] = { {-1,-1} };
187 /* Return a color attribute value. */
189 static long getcolor(int fg
, int bg
)
193 if (colors
[0][0] < 0) {
195 memset(colors
, -1, sizeof(colors
));
196 colors
[0][0] = COLOR_WHITE
;
197 colors
[0][1] = COLOR_BLACK
;
199 if (fg
== COLOR_WHITE
&& bg
== COLOR_BLACK
)
200 return COLOR_PAIR(0);
201 for (i
= 1; i
< MAXCOLORS
; i
++) {
202 if (colors
[i
][0] == fg
&& colors
[i
][1] == bg
)
203 return COLOR_PAIR(i
);
205 for (i
= 1; i
< MAXCOLORS
; i
++) {
206 if (colors
[i
][0] < 0) {
207 if (init_pair(i
, fg
, bg
) == ERR
)
211 return COLOR_PAIR(i
);
217 /*************************************************************************/
218 /*************************************************************************/
220 /* Set up the screen stuff. */
222 static void screen_setup(void)
224 /* Avoid messy keyfield signals while we're setting up */
225 signal(SIGINT
, SIG_IGN
);
226 signal(SIGTSTP
, SIG_IGN
);
231 nodelay(stdscr
, TRUE
);
232 keypad(stdscr
, TRUE
);
233 leaveok(stdscr
, TRUE
);
234 if ((has_color
= has_colors()))
236 getmaxyx(stdscr
, scrheight
, scrwidth
);
237 scrwidth
--; /* Don't draw in last column--this can cause scroll */
239 /* Cancel all this when we exit. */
240 atexit(screen_cleanup
);
242 /* Catch signals so we can exit cleanly. */
243 signal(SIGINT
, sighandler
);
244 signal(SIGTERM
, sighandler
);
245 signal(SIGHUP
, sighandler
);
246 signal(SIGUSR1
, sighandler
);
247 signal(SIGUSR2
, sighandler
);
248 signal(SIGALRM
, sighandler
);
249 signal(SIGTSTP
, sighandler
);
251 signal(SIGXCPU
, sighandler
);
254 signal(SIGXFSZ
, sighandler
);
257 /* Broken pipes don't want to bother us at all. */
258 signal(SIGPIPE
, SIG_IGN
);
261 /*************************************************************************/
263 /* Redraw everything on the screen. */
265 static void screen_refresh(void)
268 touchline(stdscr
, gmsg_inputpos
, gmsg_inputheight
);
270 touchline(stdscr
, plinebuf
.y
, plinebuf
.height
);
272 touchline(stdscr
, gmsgbuf
.y
, gmsgbuf
.height
);
274 touchline(stdscr
, attdefbuf
.y
, attdefbuf
.height
);
275 wnoutrefresh(stdscr
);
279 /*************************************************************************/
281 /* Like screen_refresh(), but clear the screen first. */
283 static void screen_redraw(void)
285 clearok(stdscr
, TRUE
);
289 /*************************************************************************/
290 /************************* Text buffer routines **************************/
291 /*************************************************************************/
293 /* Put a line of text in a text buffer. */
295 static void outline(TextBuffer
*buf
, const unsigned char *s
)
297 if (buf
->line
== buf
->height
) {
300 memmove(buf
->text
, buf
->text
+1, (buf
->height
-1) * sizeof(char *));
304 int i
, x
= 0, l
= strlen(s
);
306 for (i
= 0; i
< l
; i
++) {
307 unsigned char c
= s
[i
] - 1;
310 static const int cmap
[8] = {
311 COLOR_BLACK
, COLOR_RED
, COLOR_GREEN
, COLOR_YELLOW
,
312 COLOR_BLUE
, COLOR_MAGENTA
, COLOR_CYAN
, COLOR_WHITE
,
317 wattrset(buf
->win
, A_NORMAL
);
320 wattron(buf
->win
, A_BOLD
);
323 wattron(buf
->win
, A_STANDOUT
);
325 case TATTR_UNDERLINE
:
326 wattron(buf
->win
, A_UNDERLINE
);
329 assert(c
< TATTR_CMAX
);
330 wattron(buf
->win
, getcolor(c
== 0 ? COLOR_WHITE
: cmap
[c
% 8], COLOR_BLACK
)
331 | (A_BOLD
* (c
/ 8)));
336 mvwaddch(buf
->win
, buf
->line
, x
++, c
+ 1);
340 wattrset(buf
->win
, A_NORMAL
);
342 if (s
!= (const unsigned char *) buf
->text
[buf
->line
]) /* check for restoring display */
343 buf
->text
[buf
->line
] = strdup(s
);
347 static void draw_text(int bufnum
, const char *s
)
349 char str
[1024]; /* hopefully scrwidth < 1024 */
356 case BUFFER_PLINE
: buf
= &plinebuf
; break;
357 case BUFFER_GMSG
: buf
= &gmsgbuf
; break;
358 case BUFFER_ATTDEF
: buf
= &attdefbuf
; break;
365 attrset(getcolor(COLOR_WHITE
, COLOR_BLACK
));
367 while (*s
&& isspace(*s
))
369 while (strlen(s
) > buf
->width
- indent
) {
370 t
= s
+ buf
->width
- indent
;
371 while (t
>= s
&& !isspace(*t
))
373 while (t
>= s
&& isspace(*t
))
377 t
= s
+ buf
->width
- indent
;
379 sprintf(str
, "%*s", indent
, "");
380 strncpy(str
+indent
, s
, t
-s
);
389 sprintf(str
, "%*s", indent
, "");
390 strcpy(str
+indent
, s
);
398 /*************************************************************************/
400 /* Clear the contents of a text buffer. */
402 static void clear_text(int bufnum
)
408 case BUFFER_PLINE
: buf
= &plinebuf
; break;
409 case BUFFER_GMSG
: buf
= &gmsgbuf
; break;
410 case BUFFER_ATTDEF
: buf
= &attdefbuf
; break;
414 for (i
= 0; i
< buf
->height
; i
++) {
428 /*************************************************************************/
430 /* Restore the contents of the given text buffer. */
432 static void restore_text(TextBuffer
*buf
)
435 while (buf
->line
< buf
->height
&& buf
->text
[buf
->line
])
436 outline(buf
, buf
->text
[buf
->line
]);
439 /*************************************************************************/
441 /* Open a window for the given text buffer. */
443 static void open_textwin(TextBuffer
*buf
)
445 if (buf
->height
<= 0 || buf
->width
<= 0) {
447 move(scrheight
-1, 0);
448 snprintf(str
, sizeof(str
), "ERROR: bad textwin size (%d,%d)",
449 buf
->width
, buf
->height
);
454 buf
->win
= subwin(stdscr
, buf
->height
, buf
->width
, buf
->y
, buf
->x
);
455 scrollok(buf
->win
, TRUE
);
458 buf
->text
= calloc(buf
->height
, sizeof(char *));
463 /*************************************************************************/
465 /* Close the window for the given text buffer, if it's open. */
467 static void close_textwin(TextBuffer
*buf
)
475 /*************************************************************************/
476 /************************ Field drawing routines *************************/
477 /*************************************************************************/
479 /* Are we on a wide screen (>=92 columns)? */
480 static int wide_screen
= 0;
482 /* Field display X/Y coordinates. */
483 static const int own_coord
[2] = {1,0};
484 static int other_coord
[5][2] = /* Recomputed based on screen width */
485 { {30,0}, {47,0}, {64,0}, {47,24}, {64,24} };
487 /* Position of the status window. */
488 static const int status_coord
[2] = {29,25};
489 static const int next_coord
[2] = {41,24};
490 static const int alt_status_coord
[2] = {29,2};
491 static const int alt_next_coord
[2] = {30,8};
493 /* Position of the attacks/defenses window. */
494 static const int attdef_coord
[2] = {28,28};
495 static const int alt_attdef_coord
[2] = {28,24};
497 /* Position of the text window. X coordinate is ignored. */
498 static const int field_text_coord
[2] = {0,47};
500 /* Information for drawing blocks. Color attributes are added to blocks in
501 * the setup_fields() routine. */
502 static int tile_chars
[15] =
503 { ' ','#','#','#','#','#','a','c','n','r','s','b','g','q','o' };
505 /* Are we redrawing the entire display? */
506 static int field_redraw
= 0;
508 /*************************************************************************/
509 /*************************************************************************/
511 /* Set up the field display. */
513 static void draw_own_field(void);
514 static void draw_other_field(int player
);
515 static void draw_status(void);
516 static void draw_specials(void);
517 static void draw_gmsg_input(const char *s
, int pos
);
519 static void setup_fields(void)
521 int i
, j
, x
, y
, base
, delta
, attdefbot
;
524 if (!(tile_chars
[0] & A_ATTRIBUTES
)) {
525 for (i
= 1; i
< 15; i
++)
526 tile_chars
[i
] |= A_BOLD
;
527 tile_chars
[1] |= getcolor(COLOR_BLUE
, COLOR_BLACK
);
528 tile_chars
[2] |= getcolor(COLOR_YELLOW
, COLOR_BLACK
);
529 tile_chars
[3] |= getcolor(COLOR_GREEN
, COLOR_BLACK
);
530 tile_chars
[4] |= getcolor(COLOR_MAGENTA
, COLOR_BLACK
);
531 tile_chars
[5] |= getcolor(COLOR_RED
, COLOR_BLACK
);
535 leaveok(stdscr
, TRUE
);
536 close_textwin(&plinebuf
);
538 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
540 if (scrwidth
>= 92) {
546 delta
= (scrwidth
- base
) / 3;
547 base
+= 2 + (delta
- (FIELD_WIDTH
+5)) / 2;
548 other_coord
[0][0] = base
;
549 other_coord
[1][0] = base
+ delta
;
550 other_coord
[2][0] = base
+ delta
*2;
551 other_coord
[3][0] = base
+ delta
;
552 other_coord
[4][0] = base
+ delta
*2;
554 attdefbot
= field_text_coord
[1] - 1;
555 if (scrheight
- field_text_coord
[1] > 3) {
556 move(field_text_coord
[1], 0);
557 hline(MY_HLINE2
, scrwidth
);
559 if (scrheight
- field_text_coord
[1] > 5) {
560 move(scrheight
-2, 0);
561 hline(MY_HLINE2
, scrwidth
);
563 move(scrheight
-1, 0);
564 addstr("F1=Show Fields F2=Partyline F3=Winlist");
565 move(scrheight
-1, scrwidth
-8);
568 gmsgbuf
.y
= field_text_coord
[1]+1;
569 gmsgbuf
.height
= scrheight
- field_text_coord
[1] - 3;
571 gmsgbuf
.y
= field_text_coord
[1]+1;
572 gmsgbuf
.height
= scrheight
- field_text_coord
[1] - 1;
575 gmsgbuf
.y
= field_text_coord
[1];
576 gmsgbuf
.height
= scrheight
- field_text_coord
[1];
578 gmsgbuf
.x
= field_text_coord
[0];
579 gmsgbuf
.width
= scrwidth
;
580 open_textwin(&gmsgbuf
);
584 sprintf(buf
, "%d", my_playernum
);
585 mvaddstr(y
, x
-1, buf
);
586 for (i
= 2; i
< FIELD_HEIGHT
*2 && players
[my_playernum
-1][i
-2]; i
++)
587 mvaddch(y
+i
, x
-1, players
[my_playernum
-1][i
-2]);
588 if (teams
[my_playernum
-1] != '\0') {
589 mvaddstr(y
, x
+FIELD_WIDTH
*2+2, "T");
590 for (i
= 2; i
< FIELD_HEIGHT
*2 && teams
[my_playernum
-1][i
-2]; i
++)
591 mvaddch(y
+i
, x
+FIELD_WIDTH
*2+2, teams
[my_playernum
-1][i
-2]);
594 vline(MY_VLINE
, FIELD_HEIGHT
*2);
595 move(y
, x
+FIELD_WIDTH
*2+1);
596 vline(MY_VLINE
, FIELD_HEIGHT
*2);
597 move(y
+FIELD_HEIGHT
*2, x
);
599 hline(MY_HLINE
, FIELD_WIDTH
*2);
600 move(y
+FIELD_HEIGHT
*2, x
+FIELD_WIDTH
*2+1);
602 mvaddstr(y
+FIELD_HEIGHT
*2+2, x
, "Specials:");
606 for (j
= 0; j
< 5; j
++) {
607 x
= other_coord
[j
][0];
608 y
= other_coord
[j
][1];
610 vline(MY_VLINE
, FIELD_HEIGHT
);
611 move(y
, x
+FIELD_WIDTH
+1);
612 vline(MY_VLINE
, FIELD_HEIGHT
);
613 move(y
+FIELD_HEIGHT
, x
);
615 hline(MY_HLINE
, FIELD_WIDTH
);
616 move(y
+FIELD_HEIGHT
, x
+FIELD_WIDTH
+1);
618 if (j
+1 >= my_playernum
) {
619 sprintf(buf
, "%d", j
+2);
620 mvaddstr(y
, x
-1, buf
);
622 for (i
= 0; i
< FIELD_HEIGHT
-2 && players
[j
+1][i
]; i
++)
623 mvaddch(y
+i
+2, x
-1, players
[j
+1][i
]);
624 if (teams
[j
+1] != '\0') {
625 mvaddstr(y
, x
+FIELD_WIDTH
+2, "T");
626 for (i
= 0; i
< FIELD_HEIGHT
-2 && teams
[j
+1][i
]; i
++)
627 mvaddch(y
+i
+2, x
+FIELD_WIDTH
+2, teams
[j
+1][i
]);
630 draw_other_field(j
+2);
632 sprintf(buf
, "%d", j
+1);
633 mvaddstr(y
, x
-1, buf
);
635 for (i
= 0; i
< FIELD_HEIGHT
-2 && players
[j
][i
]; i
++)
636 mvaddch(y
+i
+2, x
-1, players
[j
][i
]);
637 if (teams
[j
] != '\0') {
638 mvaddstr(y
, x
+FIELD_WIDTH
+2, "T");
639 for (i
= 0; i
< FIELD_HEIGHT
-2 && teams
[j
][i
]; i
++)
640 mvaddch(y
+i
+2, x
+FIELD_WIDTH
+2, teams
[j
][i
]);
643 draw_other_field(j
+1);
648 x
= alt_status_coord
[0];
649 y
= alt_status_coord
[1];
650 mvaddstr(y
, x
, "Lines:");
651 mvaddstr(y
+1, x
, "Level:");
652 x
= alt_next_coord
[0];
653 y
= alt_next_coord
[1];
654 mvaddstr(y
-2, x
-1, "Next piece:");
658 mvaddch(y
-1, x
+8, MY_URCORNER
);
666 mvaddch(y
+8, x
+8, MY_LRCORNER
);
670 mvaddstr(y
-1, x
, "Next piece:");
671 mvaddstr(y
, x
, "Lines:");
672 mvaddstr(y
+1, x
, "Level:");
677 attdefbuf
.x
= wide_screen
? alt_attdef_coord
[0] : attdef_coord
[0];
678 attdefbuf
.y
= wide_screen
? alt_attdef_coord
[1] : attdef_coord
[1];
679 attdefbuf
.width
= (other_coord
[3][0]-1) - attdefbuf
.x
;
680 attdefbuf
.height
= (attdefbot
+1) - attdefbuf
.y
;
681 open_textwin(&attdefbuf
);
684 delwin(gmsg_inputwin
);
685 gmsg_inputwin
= NULL
;
686 draw_gmsg_input(NULL
, -1);
694 /*************************************************************************/
696 /* Display the player's own field. */
698 static void draw_own_field(void)
701 Field
*f
= &fields
[my_playernum
-1];
702 int shadow
[4] = { -1, -1, -1, -1 };
704 if (dispmode
!= MODE_FIELDS
)
707 /* XXX: Code duplication with tetris.c:draw_piece(). --pasky */
708 if (playing_game
&& cast_shadow
) {
709 int y
= current_y
- piecedata
[current_piece
][current_rotation
].hot_y
;
710 char *shape
= (char *) piecedata
[current_piece
][current_rotation
].shape
;
713 for (j
= 0; j
< 4; j
++) {
718 for (i
= 0; i
< 4; i
++) {
727 for (y
= 0; y
< 22; y
++) {
728 for (x
= 0; x
< 12; x
++) {
729 int c
= tile_chars
[(int) (*f
)[y
][x
]];
731 if (playing_game
&& cast_shadow
) {
732 PieceData
*piece
= &piecedata
[current_piece
][current_rotation
];
733 int piece_x
= current_x
- piece
->hot_x
;
735 if (x
>= piece_x
&& x
<= piece_x
+ 3
736 && shadow
[(x
- piece_x
)] >= 0
737 && shadow
[(x
- piece_x
)] < y
738 && ((c
& 0x7f) == ' ')) {
739 c
= (c
& (~0x7f)) | '.'
740 | getcolor(COLOR_BLACK
, COLOR_BLACK
) | A_BOLD
;
744 mvaddch(y0
+y
*2, x0
+x
*2, c
);
746 mvaddch(y0
+y
*2+1, x0
+x
*2, c
);
751 delwin(gmsg_inputwin
);
752 gmsg_inputwin
= NULL
;
753 draw_gmsg_input(NULL
, -1);
761 /*************************************************************************/
763 /* Display another player's field. */
765 static void draw_other_field(int player
)
770 if (dispmode
!= MODE_FIELDS
)
772 f
= &fields
[player
-1];
773 if (player
> my_playernum
)
776 x0
= other_coord
[player
][0]+1;
777 y0
= other_coord
[player
][1];
778 for (y
= 0; y
< 22; y
++) {
780 for (x
= 0; x
< 12; x
++) {
781 addch(tile_chars
[(int) (*f
)[y
][x
]]);
785 delwin(gmsg_inputwin
);
786 gmsg_inputwin
= NULL
;
787 draw_gmsg_input(NULL
, -1);
795 /*************************************************************************/
797 /* Display the current game status (level, lines, next piece). */
799 static void draw_status(void)
802 char buf
[32], shape
[4][4];
804 x
= wide_screen
? alt_status_coord
[0] : status_coord
[0];
805 y
= wide_screen
? alt_status_coord
[1] : status_coord
[1];
806 sprintf(buf
, "%d", lines
>99999 ? 99999 : lines
);
807 mvaddstr(y
, x
+7, buf
);
808 sprintf(buf
, "%d", levels
[my_playernum
]);
809 mvaddstr(y
+1, x
+7, buf
);
810 x
= wide_screen
? alt_next_coord
[0] : next_coord
[0];
811 y
= wide_screen
? alt_next_coord
[1] : next_coord
[1];
812 if (get_shape(next_piece
, 0, shape
) == 0) {
813 for (j
= 0; j
< 4; j
++) {
816 for (i
= 0; i
< 4; i
++) {
819 addch(tile_chars
[(int) shape
[j
][i
]]);
820 addch(tile_chars
[(int) shape
[j
][i
]]);
821 move(y
+j
*2+1, x
+i
*2);
822 addch(tile_chars
[(int) shape
[j
][i
]]);
823 addch(tile_chars
[(int) shape
[j
][i
]]);
825 addch(tile_chars
[(int) shape
[j
][i
]]);
831 /*************************************************************************/
833 /* Display the special inventory and description of the current special. */
835 static const char *descs
[] = {
840 "Clear Random Blocks ",
842 "Clear Special Blocks",
848 static void draw_specials(void)
852 if (dispmode
!= MODE_FIELDS
)
856 mvaddstr(y
, x
, descs
[specials
[0]+1]);
859 while (i
< special_capacity
&& specials
[i
] >= 0 && x
< attdef_coord
[0]-1) {
860 addch(tile_chars
[specials
[i
]+6]);
864 while (x
< attdef_coord
[0]-1) {
865 addch(tile_chars
[0]);
874 /*************************************************************************/
876 /* Display an attack/defense message. */
878 static const char *msgs
[][2] = {
879 { "cs1", "1 Line Added to All" },
880 { "cs2", "2 Lines Added to All" },
881 { "cs4", "4 Lines Added to All" },
883 { "c", "Clear Line" },
884 { "n", "Nuke Field" },
885 { "r", "Clear Random Blocks" },
886 { "s", "Switch Fields" },
887 { "b", "Clear Special Blocks" },
888 { "g", "Block Gravity" },
889 { "q", "Blockquake" },
890 { "o", "Block Bomb" },
894 static void draw_attdef(const char *type
, int from
, int to
)
899 width
= other_coord
[4][0] - attdef_coord
[0] - 1;
900 for (i
= 0; msgs
[i
][0]; i
++) {
901 if (strcmp(type
, msgs
[i
][0]) == 0)
906 strcpy(buf
, msgs
[i
][1]);
908 sprintf(buf
+strlen(buf
), " on %s", players
[to
-1]);
910 sprintf(buf
+strlen(buf
), " by Server");
912 sprintf(buf
+strlen(buf
), " by %s", players
[from
-1]);
913 draw_text(BUFFER_ATTDEF
, buf
);
916 /*************************************************************************/
918 /* Display the in-game text window. */
920 static void draw_gmsg_input(const char *s
, int pos
)
922 static int start
= 0; /* Start of displayed part of input line */
923 static const char *last_s
;
935 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
937 if (!gmsg_inputwin
) {
938 gmsg_inputpos
= scrheight
/2 - 1;
939 gmsg_inputheight
= 3;
941 subwin(stdscr
, gmsg_inputheight
, scrwidth
, gmsg_inputpos
, 0);
942 werase(gmsg_inputwin
);
943 leaveok(gmsg_inputwin
, FALSE
);
944 leaveok(stdscr
, FALSE
);
945 mvwaddstr(gmsg_inputwin
, 1, 0, "Text>");
948 if (strlen(s
) < scrwidth
-7) {
950 mvwaddstr(gmsg_inputwin
, 1, 6, s
);
951 wmove(gmsg_inputwin
, 1, 6+strlen(s
));
952 move(gmsg_inputpos
+1, 6+strlen(s
));
953 wclrtoeol(gmsg_inputwin
);
954 wmove(gmsg_inputwin
, 1, 6+pos
);
955 move(gmsg_inputpos
+1, 6+pos
);
961 } else if (pos
> start
+ scrwidth
-15) {
962 start
= pos
- (scrwidth
-15);
963 if (start
> strlen(s
) - (scrwidth
-7))
964 start
= strlen(s
) - (scrwidth
-7);
966 mvwaddnstr(gmsg_inputwin
, 1, 6, s
+start
, scrwidth
-6);
967 wmove(gmsg_inputwin
, 1, 6 + (pos
-start
));
968 move(gmsg_inputpos
+1, 6 + (pos
-start
));
974 /*************************************************************************/
976 /* Clear the in-game text window. */
978 static void clear_gmsg_input(void)
981 delwin(gmsg_inputwin
);
982 gmsg_inputwin
= NULL
;
983 leaveok(stdscr
, TRUE
);
984 touchline(stdscr
, gmsg_inputpos
, gmsg_inputheight
);
991 /*************************************************************************/
992 /*************************** Partyline display ***************************/
993 /*************************************************************************/
995 static void setup_partyline(void)
997 close_textwin(&gmsgbuf
);
998 close_textwin(&attdefbuf
);
1001 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
1003 plinebuf
.x
= plinebuf
.y
= 0;
1004 plinebuf
.width
= scrwidth
;
1005 plinebuf
.height
= scrheight
-4;
1006 open_textwin(&plinebuf
);
1008 move(scrheight
-4, 0);
1009 hline(MY_HLINE
, scrwidth
);
1010 move(scrheight
-3, 0);
1013 move(scrheight
-2, 0);
1014 hline(MY_HLINE2
, scrwidth
);
1016 move(scrheight
-1, 0);
1017 addstr("F1=Show Fields F2=Partyline F3=Winlist");
1018 move(scrheight
-1, scrwidth
-8);
1022 move(scrheight
-3, 2);
1023 leaveok(stdscr
, FALSE
);
1028 /*************************************************************************/
1030 static void draw_partyline_input(const char *s
, int pos
)
1032 static int start
= 0; /* Start of displayed part of input line */
1034 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
1035 if (strlen(s
) < scrwidth
-3) {
1037 mvaddstr(scrheight
-3, 2, s
);
1038 move(scrheight
-3, 2+strlen(s
));
1040 move(scrheight
-3, 2+pos
);
1042 if (pos
< start
+8) {
1046 } else if (pos
> start
+ scrwidth
-11) {
1047 start
= pos
- (scrwidth
-11);
1048 if (start
> strlen(s
) - (scrwidth
-3))
1049 start
= strlen(s
) - (scrwidth
-3);
1051 mvaddnstr(scrheight
-3, 2, s
+start
, scrwidth
-2);
1052 move(scrheight
-3, 2 + (pos
-start
));
1057 /*************************************************************************/
1058 /**************************** Winlist display ****************************/
1059 /*************************************************************************/
1061 static void setup_winlist(void)
1066 leaveok(stdscr
, TRUE
);
1067 close_textwin(&plinebuf
);
1069 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
1071 for (i
= 0; i
< MAXWINLIST
&& *winlist
[i
].name
; i
++) {
1072 x
= scrwidth
/2 - strlen(winlist
[i
].name
);
1075 if (winlist
[i
].team
) {
1078 mvaddstr(i
*2, x
-4, "<T>");
1080 mvaddstr(i
*2, x
, winlist
[i
].name
);
1081 snprintf(buf
, sizeof(buf
), "%4d", winlist
[i
].points
);
1082 if (winlist
[i
].games
) {
1083 int avg100
= winlist
[i
].points
*100 / winlist
[i
].games
;
1084 snprintf(buf
+strlen(buf
), sizeof(buf
)-strlen(buf
),
1085 " %d.%02d",avg100
/100, avg100
%100);
1087 x
+= strlen(winlist
[i
].name
) + 2;
1088 if (x
> scrwidth
- strlen(buf
))
1089 x
= scrwidth
- strlen(buf
);
1090 mvaddstr(i
*2, x
, buf
);
1093 move(scrheight
-2, 0);
1094 hline(MY_HLINE2
, scrwidth
);
1096 move(scrheight
-1, 0);
1097 addstr("F1=Show Fields F2=Partyline F3=Winlist");
1098 move(scrheight
-1, scrwidth
-8);
1106 /*************************************************************************/
1107 /************************** Interface declaration ************************/
1108 /*************************************************************************/
1110 Interface tty_interface
= {
1131 draw_partyline_input
,
1136 /*************************************************************************/