]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
1 /* $NetBSD: pl_7.c,v 1.42 2011/08/26 06:18:18 dholland Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: pl_7.c,v 1.42 2011/08/26 06:18:18 dholland Exp $");
56 * Use values above KEY_MAX for custom keycodes. (blymn@ says this is ok)
58 #define KEY_ESC(ch) (KEY_MAX+10+ch)
65 static void draw_view(void);
66 static void draw_turn(void);
67 static void draw_stat(void);
68 static void draw_slot(void);
69 static void draw_board(void);
71 static struct stringarray
*sc_lines
;
72 static unsigned sc_scrollup
;
73 static bool sc_hasprompt
;
74 static bool sc_hideprompt
;
75 static const char *sc_prompt
;
76 static const char *sc_buf
;
78 static WINDOW
*view_w
;
79 static WINDOW
*turn_w
;
80 static WINDOW
*stat_w
;
81 static WINDOW
*slot_w
;
82 static WINDOW
*scroll_w
;
89 int loaded
, fired
, changed
, repaired
;
91 static int viewrow
, viewcol
;
92 char movebuf
[sizeof SHIP(0)->file
->movebuf
];
94 struct ship
*ms
; /* memorial structure, &cc->ship[player] */
95 struct File
*mf
; /* ms->file */
96 struct shipspecs
*mc
; /* ms->specs */
98 ////////////////////////////////////////////////////////////
99 // overall initialization
103 define_esc_key(int ch
)
105 char seq
[3] = { '\x1b', ch
, 0 };
107 define_key(seq
, KEY_ESC(ch
));
115 sc_lines
= stringarray_create();
116 if (sc_lines
== NULL
) {
120 if (signal(SIGTSTP
, SIG_DFL
) == SIG_ERR
) {
121 err(1, "signal(SIGTSTP)");
124 if (initscr() == NULL
) {
125 errx(1, "Can't sail on this terminal.");
127 if (STAT_R
>= COLS
|| SCROLL_Y
<= 0) {
128 errx(1, "Window/terminal not large enough.");
131 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
132 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
133 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
134 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
135 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
137 if (view_w
== NULL
||
143 errx(1, "Curses initialization failed.");
157 for (ch
= 0; ch
< 127; ch
++) {
158 if (ch
!= '[' && ch
!= 'O') {
164 (void)define_esc_key
;
180 /* alarm already turned off */
183 wmove(scroll_w
, SCROLL_Y
- 1, 0);
194 ////////////////////////////////////////////////////////////
195 // curses utility functions
198 * fill to eol with spaces
199 * (useful with A_REVERSE since cleartoeol() does not clear to reversed)
206 for (x
= getcurx(stdscr
); x
< COLS
; x
++) {
212 * Add a maybe-selected string.
214 * Place strings starting at (Y0, X0); this is string ITEM; CURITEM
215 * is the selected one; WIDTH is the total width. STR is the string.
218 mvaddselstr(int y
, int x0
, int item
, int curitem
,
219 size_t width
, const char *str
)
226 if (curitem
== item
) {
230 if (curitem
== item
) {
231 for (i
=len
; i
<width
; i
++) {
239 * Likewise but a printf.
241 static void __printflike(6, 7)
242 mvselprintw(int y
, int x0
, int item
, int curitem
,
243 size_t width
, const char *fmt
, ...)
249 if (curitem
== item
) {
253 vwprintw(stdscr
, fmt
, ap
);
255 if (curitem
== item
) {
256 for (x
= getcurx(stdscr
); x
< x0
+ width
; x
++) {
264 * Move up by 1, scrolling if needed.
267 up(int *posp
, int *scrollp
)
272 if (scrollp
!= NULL
) {
273 if (*posp
< *scrollp
) {
280 * Move down by 1, scrolling if needed. MAX is the total number of
281 * items; VISIBLE is the number that can be visible at once.
284 down(int *posp
, int *scrollp
, int max
, int visible
)
286 if (max
> 0 && *posp
< max
- 1) {
289 if (scrollp
!= NULL
) {
290 if (*posp
> *scrollp
+ visible
- 1) {
291 *scrollp
= *posp
- visible
+ 1;
299 static void __printflike(3, 4)
300 oops(int y
, int x
, const char *fmt
, ...)
305 oy
= getcury(stdscr
);
306 ox
= getcurx(stdscr
);
309 vwprintw(stdscr
, fmt
, ap
);
316 ////////////////////////////////////////////////////////////
317 // scrolling message area
320 scrollarea_add(const char *text
)
329 if (stringarray_add(sc_lines
, copy
, NULL
)) {
336 * XXX this should use leave(), but that won't
337 * currently work right.
344 sync_close(!hasdriver
);
353 unsigned total_lines
;
354 unsigned visible_lines
;
355 unsigned index_of_top
;
362 /* XXX: SCROLL_Y and whatnot should be unsigned too */
363 visible_lines
= SCROLL_Y
- 1;
365 total_lines
= stringarray_num(sc_lines
);
366 if (total_lines
> visible_lines
) {
367 index_of_top
= total_lines
- visible_lines
;
371 if (index_of_top
< sc_scrollup
) {
374 index_of_top
-= sc_scrollup
;
377 for (y
= 0; y
< visible_lines
; y
++) {
378 index_of_y
= index_of_top
+ y
;
379 if (index_of_y
>= total_lines
) {
382 wmove(scroll_w
, y
, 0);
383 waddstr(scroll_w
, stringarray_get(sc_lines
, index_of_y
));
385 if (sc_hasprompt
&& !sc_hideprompt
) {
386 wmove(scroll_w
, SCROLL_Y
-1, 0);
387 waddstr(scroll_w
, sc_prompt
);
388 waddstr(scroll_w
, sc_buf
);
389 cursorx
= strlen(sc_prompt
) + strlen(sc_buf
);
390 wmove(scroll_w
, SCROLL_Y
-1, cursorx
);
393 wmove(scroll_w
, SCROLL_Y
-1, 0);
399 Signal(const char *fmt
, struct ship
*ship
, ...)
412 fmtship(format
, sizeof(format
), fmt
, ship
);
413 vsnprintf(buf
, sizeof(buf
), format
, ap
);
420 Msg(const char *fmt
, ...)
432 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
438 prompt(const char *p
, struct ship
*ship
)
440 static char buf
[BUFSIZ
];
442 fmtship(buf
, sizeof(buf
), p
, ship
);
453 sc_hasprompt
= false;
457 * Next two functions called from newturn() to poke display. Shouldn't
462 display_hide_prompt(void)
464 sc_hideprompt
= true;
470 display_reshow_prompt(void)
472 sc_hideprompt
= false;
479 sgetch(const char *p
, struct ship
*ship
, int flag
)
493 while ((c
= wgetch(scroll_w
)) == EOF
)
495 if (flag
&& c
>= ' ' && c
< 0x7f) {
508 sgetstr(const char *pr
, char *buf
, int n
)
513 prompt(pr
, (struct ship
*)0);
522 while ((c
= wgetch(scroll_w
)) == EOF
)
531 /*waddstr(scroll_w, "\b \b");*/
536 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
538 /*waddch(scroll_w, c);*/
545 ////////////////////////////////////////////////////////////
546 // drawing of other panes
549 display_force_full_redraw(void)
563 /* move the cursor */
577 && sp
->file
->row
> viewrow
578 && sp
->file
->row
< viewrow
+ VIEW_Y
579 && sp
->file
->col
> viewcol
580 && sp
->file
->col
< viewcol
+ VIEW_X
) {
581 wmove(view_w
, sp
->file
->row
- viewrow
,
582 sp
->file
->col
- viewcol
);
583 waddch(view_w
, colours(sp
));
585 sternrow(sp
) - viewrow
,
586 sterncol(sp
) - viewcol
);
587 waddch(view_w
, sterncolour(sp
));
597 wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
604 wmove(stat_w
, STAT_1
, 0);
605 wprintw(stat_w
, "Points %3d\n", mf
->points
);
606 wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
607 wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
609 wmove(stat_w
, STAT_2
, 0);
610 wprintw(stat_w
, " 0 %c(%c)\n",
611 maxmove(ms
, winddir
+ 3, -1) + '0',
612 maxmove(ms
, winddir
+ 3, 1) + '0');
613 waddstr(stat_w
, " \\|/\n");
614 wprintw(stat_w
, " -^-%c(%c)\n",
615 maxmove(ms
, winddir
+ 2, -1) + '0',
616 maxmove(ms
, winddir
+ 2, 1) + '0');
617 waddstr(stat_w
, " /|\\\n");
618 wprintw(stat_w
, " | %c(%c)\n",
619 maxmove(ms
, winddir
+ 1, -1) + '0',
620 maxmove(ms
, winddir
+ 1, 1) + '0');
621 wprintw(stat_w
, " %c(%c)\n",
622 maxmove(ms
, winddir
, -1) + '0',
623 maxmove(ms
, winddir
, 1) + '0');
625 wmove(stat_w
, STAT_3
, 0);
626 wprintw(stat_w
, "Load %c%c %c%c\n",
627 loadname
[mf
->loadL
], readyname(mf
->readyL
),
628 loadname
[mf
->loadR
], readyname(mf
->readyR
));
629 wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
630 wprintw(stat_w
, "Crew %2d %2d %2d\n",
631 mc
->crew1
, mc
->crew2
, mc
->crew3
);
632 wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
633 wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
634 wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
638 wprintw(stat_w
, "%d", mc
->rig4
);
647 if (!boarding(ms
, 0)) {
648 mvwaddstr(slot_w
, 0, 0, " ");
649 mvwaddstr(slot_w
, 1, 0, " ");
652 for (i
= 0; i
< 3; i
++) {
653 waddch(slot_w
, obp
[i
] ? '1'+i
: ' ');
655 mvwaddstr(slot_w
, 1, 0, "OBP");
657 if (!boarding(ms
, 1)) {
658 mvwaddstr(slot_w
, 2, 0, " ");
659 mvwaddstr(slot_w
, 3, 0, " ");
662 for (i
= 0; i
< 3; i
++) {
663 waddch(slot_w
, dbp
[i
] ? '1'+i
: ' ');
665 mvwaddstr(slot_w
, 3, 0, "DBP");
668 wmove(slot_w
, SLOT_Y
-4, 0);
670 wprintw(slot_w
, "%dRH", mf
->RH
);
672 waddstr(slot_w
, " ");
673 wmove(slot_w
, SLOT_Y
-3, 0);
675 wprintw(slot_w
, "%dRG", mf
->RG
);
677 waddstr(slot_w
, " ");
678 wmove(slot_w
, SLOT_Y
-2, 0);
680 wprintw(slot_w
, "%dRR", mf
->RR
);
682 waddstr(slot_w
, " ");
686 wprintw(slot_w
,"%d", windspeed
);
687 mvwaddch(slot_w
, Y
, 0, ' ');
688 mvwaddch(slot_w
, Y
, 2, ' ');
689 mvwaddch(slot_w
, Y
-1, 0, ' ');
690 mvwaddch(slot_w
, Y
-1, 1, ' ');
691 mvwaddch(slot_w
, Y
-1, 2, ' ');
692 mvwaddch(slot_w
, Y
+1, 0, ' ');
693 mvwaddch(slot_w
, Y
+1, 1, ' ');
694 mvwaddch(slot_w
, Y
+1, 2, ' ');
695 wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
711 waddch(slot_w
, '\\');
714 mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
731 for (n
= 0; n
< BOX_X
; n
++)
734 for (n
= 0; n
< BOX_X
; n
++)
736 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
737 mvaddch(n
, BOX_L
, '|');
738 mvaddch(n
, BOX_R
, '|');
740 mvaddch(BOX_T
, BOX_L
, '+');
741 mvaddch(BOX_T
, BOX_R
, '+');
742 mvaddch(BOX_B
, BOX_L
, '+');
743 mvaddch(BOX_B
, BOX_R
, '+');
747 #define WSaIM "Wooden Ships & Iron Men"
748 wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
749 waddstr(view_w
, WSaIM
);
750 wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
751 waddstr(view_w
, cc
->name
);
755 move(LINE_T
, LINE_L
);
756 printw("Class %d %s (%d guns) '%s' (%c%c)",
758 classname
[mc
->class],
767 display_set_obp(int which
, bool show
)
773 display_set_dbp(int which
, bool show
)
778 ////////////////////////////////////////////////////////////
779 // external actions on the display
782 display_scroll_pageup(void)
784 unsigned total_lines
, visible_lines
, limit
;
785 unsigned pagesize
= SCROLL_Y
- 2;
787 total_lines
= stringarray_num(sc_lines
);
788 visible_lines
= SCROLL_Y
- 1;
789 limit
= total_lines
- visible_lines
;
791 sc_scrollup
+= pagesize
;
792 if (sc_scrollup
> limit
) {
798 display_scroll_pagedown(void)
800 unsigned pagesize
= SCROLL_Y
- 2;
802 if (sc_scrollup
< pagesize
) {
805 sc_scrollup
-= pagesize
;
812 viewrow
= mf
->row
- VIEW_Y
/ 2;
813 viewcol
= mf
->col
- VIEW_X
/ 2;
819 viewrow
-= VIEW_Y
/ 3;
825 viewrow
+= VIEW_Y
/ 3;
831 viewcol
-= VIEW_X
/ 5;
837 viewcol
+= VIEW_X
/ 5;
840 /* Called from newturn()... rename? */
842 display_adjust_view(void)
846 if (mf
->row
< viewrow
+ VIEW_Y
/4)
847 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
848 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
849 viewrow
= mf
->row
- VIEW_Y
/4;
850 if (mf
->col
< viewcol
+ VIEW_X
/8)
851 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
852 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
853 viewcol
= mf
->col
- VIEW_X
/8;
856 ////////////////////////////////////////////////////////////
859 static bool shipselected
;
866 case L_ROUND
: return L_GRAPE
;
867 case L_GRAPE
: return L_CHAIN
;
868 case L_CHAIN
: return L_DOUBLE
;
869 case L_DOUBLE
: return L_ROUND
;
878 case 'r': return L_ROUND
;
879 case 'g': return L_GRAPE
;
880 case 'c': return L_CHAIN
;
881 case 'd': return L_DOUBLE
;
890 case L_ROUND
: return "round";
891 case L_GRAPE
: return "grape";
892 case L_CHAIN
: return "chain";
893 case L_DOUBLE
: return "double";
899 displayshiplist(void)
907 mvaddstr(1, 4, cc
->name
);
912 mvselprintw(which
+ 3, 4, which
, player
, 60,
913 " %2d: %-10s %-15s (%-2d pts) %s",
915 countryname
[sp
->nationality
],
923 mvaddstr(15, 4, "Choose your ship");
924 move(player
+ 3, 63);
926 mvselprintw(15, 4, 0, loadpos
, 32,
927 "Initial left broadside: %s", loadstr(mf
->loadL
));
928 mvselprintw(16, 4, 1, loadpos
, 32,
929 "Initial right broadside: %s", loadstr(mf
->loadR
));
930 mvselprintw(17, 4, 2, loadpos
, 32, "Set sail");
931 move(loadpos
+15, 35);
947 if (sp
->file
->captain
[0] == 0 && !sp
->file
->struck
948 && sp
->file
->captured
== 0)
953 player
= sp
- SHIP(0);
982 down(&player
, NULL
, cc
->vessels
,
995 fp
= SHIP(player
)->file
;
996 if (fp
->captain
[0] || fp
->struck
|| fp
->captured
!= 0)
997 oops(16, 4, "That ship is taken.");
1010 mf
->loadL
= L_ROUND
;
1011 mf
->loadR
= L_ROUND
;
1028 case 0: mf
->loadL
= loadbychar(ch
); break;
1029 case 1: mf
->loadR
= loadbychar(ch
); break;
1030 case 2: beep(); break;
1036 case 0: mf
->loadL
= nextload(mf
->loadL
); break;
1037 case 1: mf
->loadR
= nextload(mf
->loadR
); break;
1038 case 2: done
= true; break;
1053 down(&loadpos
, NULL
, 3, 3);
1060 mf
->readyR
= R_LOADED
|R_INITIAL
;
1061 mf
->readyL
= R_LOADED
|R_INITIAL
;
1069 shipselected
= false;
1073 hasdriver
= sync_exists(game
);
1074 if (sync_open() < 0) {
1075 oops(21, 10, "syncfile: %s", strerror(errno
));
1082 mvaddstr(21, 10, "Synchronizing with the other players...");
1088 mvaddstr(21, 10, "Starting driver...");
1094 if (pickship() < 0) {
1095 oops(21, 10, "All ships taken in that scenario.");
1102 shipselected
= true;
1114 ////////////////////////////////////////////////////////////
1117 static int pickerpos
;
1118 static int pickerscroll
;
1121 absdirectionname(int dir
)
1124 case 1: return "South";
1125 case 2: return "Southwest";
1126 case 3: return "West";
1127 case 4: return "Northwest";
1128 case 5: return "North";
1129 case 6: return "Northeast";
1130 case 7: return "East";
1131 case 8: return "Southeast";
1140 case 0: return "calm";
1141 case 1: return "light breeze";
1142 case 2: return "moderate breeze";
1143 case 3: return "fresh breeze";
1144 case 4: return "strong breeze";
1145 case 5: return "gale";
1146 case 6: return "full gale";
1147 case 7: return "hurricane";
1153 nationalityname(int nationality
)
1155 switch (nationality
) {
1156 case N_A
: return "a";
1157 case N_B
: return "b";
1158 case N_S
: return "s";
1159 case N_F
: return "f";
1160 case N_J
: return "j";
1161 case N_D
: return "d";
1162 case N_K
: return "k";
1163 case N_O
: return "o";
1176 mvaddstr(0, 0, "## SHIPS TITLE");
1177 for (y
=1; y
<LINES
-11; y
++) {
1178 sc
= (y
-1) + pickerscroll
;
1180 mvselprintw(y
, 0, sc
, pickerpos
, 56,
1182 sc
, scene
[sc
].vessels
, scene
[sc
].name
);
1186 mvprintw(2, 60 + 2, "%s wind",
1187 absdirectionname(scene
[pickerpos
].winddir
));
1188 mvprintw(3, 60 + 2, "(%s)",
1189 windname(scene
[pickerpos
].windspeed
));
1191 for (i
=0; i
<scene
[pickerpos
].vessels
; i
++) {
1192 ship
= &scene
[pickerpos
].ship
[i
];
1193 mvprintw(LINES
-10 + i
, 0,
1194 "(%s) %-16s %3d gun %s (%s crew) (%d pts)",
1195 nationalityname(ship
->nationality
),
1198 shortclassname
[ship
->specs
->class],
1199 qualname
[ship
->specs
->qual
],
1203 move(1 + pickerpos
- pickerscroll
, 55);
1208 pickscenario(int initpos
)
1212 pickerpos
= initpos
;
1213 if (pickerpos
< 0) {
1234 up(&pickerpos
, &pickerscroll
);
1238 down(&pickerpos
, &pickerscroll
, NSCENE
, LINES
-12);
1248 ////////////////////////////////////////////////////////////
1251 #define MAINITEMS_NUM 5
1252 #define STARTITEMS_NUM 4
1253 #define OPTIONSITEMS_NUM 5
1256 static bool connected
;
1258 static bool joinactive
;
1260 static int joinscroll
;
1261 static int joinable
[NSCENE
];
1262 static int numjoinable
;
1264 static bool startactive
;
1265 static int startpos
;
1266 static int startscenario
;
1268 static bool optionsactive
;
1269 static int optionspos
;
1270 static char o_myname
[MAXNAMESIZE
];
1271 static bool o_randomize
;
1272 static bool o_longfmt
;
1273 static bool o_nobells
;
1277 * this and sgetstr() should share code
1280 startup_getstr(int y
, int x
, char *buf
, size_t max
)
1300 /*waddstr(scroll_w, "\b \b");*/
1305 if (ch
>= ' ' && ch
< 0x7f && pos
< max
- 1) {
1317 mvaddstr(LINES
-2, COLS
/2, "Enter your name:");
1318 startup_getstr(LINES
-1, COLS
/2, o_myname
, sizeof(o_myname
));
1327 if (numjoinable
> 0) {
1328 prev
= joinable
[joinpos
];
1334 for (i
= 0; i
< NSCENE
; i
++) {
1335 if (!sync_exists(i
)) {
1339 joinpos
= numjoinable
;
1341 joinable
[numjoinable
++] = i
;
1343 if (joinpos
> numjoinable
) {
1344 joinpos
= (numjoinable
> 0) ? numjoinable
- 1 : 0;
1346 if (joinscroll
> joinpos
) {
1347 joinscroll
= (joinpos
> 0) ? joinpos
- 1 : 0;
1352 drawstartmenus(void)
1354 const int mainy0
= 8;
1355 const int mainx0
= 12;
1359 mvaddstr(5, 10, "Wooden Ships & Iron Men");
1361 mvaddselstr(mainy0
+0, mainx0
, 0, mainpos
, 17, "Join a game");
1362 mvaddselstr(mainy0
+1, mainx0
, 1, mainpos
, 17, "Start a game");
1363 mvaddselstr(mainy0
+2, mainx0
, 2, mainpos
, 17, "Options");
1364 mvaddselstr(mainy0
+3, mainx0
, 3, mainpos
, 17, "Show high scores");
1365 mvaddselstr(mainy0
+4, mainx0
, 4, mainpos
, 17, "Quit");
1367 mvprintw(15, 10, "Captain %s", myname
);
1369 mvaddstr(16, 10, "Connected via scratch files.");
1371 mvaddstr(16, 10, "Not connected.");
1375 int y0
, leavey
= 0, i
, sc
;
1377 mvaddstr(0, COLS
/2, "## SHIPS TITLE");
1379 for (i
= 0; i
< numjoinable
; i
++) {
1380 if (i
>= joinscroll
&& i
< joinscroll
+ LINES
-1) {
1381 move(y0
+ i
- joinscroll
, COLS
/2);
1386 printw("%-2d %-5d %s",
1387 sc
, scene
[sc
].vessels
, scene
[sc
].name
);
1391 leavey
= y0
+ i
- joinscroll
;
1395 mvaddstr(19, 10, "(Esc to abort)");
1396 if (numjoinable
> 0) {
1397 mvaddstr(18, 10, "Choose a game to join.");
1398 move(leavey
, COLS
-1);
1400 mvaddstr(2, COLS
/2, "No games.");
1401 mvaddstr(18, 10, "Press return to refresh.");
1404 } else if (startactive
) {
1407 mvaddstr(18, 10, "Start a new game");
1408 mvaddstr(19, 10, "(Esc to abort)");
1409 mvaddstr(2, COLS
/2, "New game");
1411 name
= (startscenario
< 0) ?
1412 "not selected" : scene
[startscenario
].name
;
1414 mvselprintw(4, COLS
/2, 0, startpos
, COLS
/2 - 1,
1415 "Scenario: %s", name
);
1416 mvaddselstr(5, COLS
/2, 1, startpos
, COLS
/2 - 1,
1417 "Visibility: local");
1418 mvaddselstr(6, COLS
/2, 2, startpos
, COLS
/2 - 1,
1420 mvaddselstr(7, COLS
/2, 3, startpos
, COLS
/2 - 1,
1422 move(4+startpos
, COLS
- 2);
1424 } else if (optionsactive
) {
1425 mvaddstr(18, 10, "Adjust options");
1426 mvaddstr(19, 10, "(Esc to abort)");
1427 mvaddstr(2, COLS
/2, "Adjust options");
1429 mvselprintw(4, COLS
/2, 0, optionspos
, COLS
/2-1,
1430 "Your name: %s", o_myname
);
1431 mvselprintw(5, COLS
/2, 1, optionspos
, COLS
/2-1,
1432 "Auto-pick ships: %s", o_randomize
? "ON" : "off");
1433 mvselprintw(6, COLS
/2, 2, optionspos
, COLS
/2-1,
1434 "Usernames in scores: %s",
1435 o_longfmt
? "ON" : "off");
1436 mvselprintw(7, COLS
/2, 3, optionspos
, COLS
/2-1,
1437 "Beeping: %s", o_nobells
? "OFF" : "on");
1438 mvselprintw(8, COLS
/2, 4, optionspos
, COLS
/2-1,
1440 move(4+optionspos
, COLS
- 2);
1443 move(mainy0
+ mainpos
, mainx0
+ 16);
1463 startactive
= false;
1467 optionsactive
= false;
1482 if (joinactive
&& numjoinable
> 0) {
1483 game
= joinable
[joinpos
];
1486 } else if (startactive
) {
1489 startscenario
= pickscenario(startscenario
);
1494 oops(21, 10, "That doesn't work yet.");
1497 if (startscenario
>= 0) {
1498 game
= startscenario
;
1499 /* can't do this here yet */
1502 startactive
= false;
1506 "Pick a scenario.");
1510 } else if (optionsactive
) {
1511 switch (optionspos
) {
1512 case 0: changename(); break;
1513 case 1: o_randomize
= !o_randomize
; break;
1514 case 2: o_longfmt
= !o_longfmt
; break;
1515 case 3: o_nobells
= !o_nobells
; break;
1517 strlcpy(myname
, o_myname
,
1519 randomize
= o_randomize
;
1520 longfmt
= o_longfmt
;
1521 nobells
= o_nobells
;
1522 optionsactive
= false;
1527 case 0: joinactive
= true; break;
1528 case 1: startactive
= true; break;
1530 strlcpy(o_myname
, myname
,
1532 o_randomize
= randomize
;
1533 o_longfmt
= longfmt
;
1534 o_nobells
= nobells
;
1535 optionsactive
= true;
1537 case 3: lo_curses(); break;
1548 } else if (startactive
) {
1549 startactive
= false;
1550 } else if (optionsactive
) {
1551 optionsactive
= false;
1559 up(&joinpos
, &joinscroll
);
1560 } else if (startactive
) {
1561 up(&startpos
, NULL
);
1562 } else if (optionsactive
) {
1563 up(&optionspos
, NULL
);
1571 down(&joinpos
, &joinscroll
,
1572 numjoinable
, LINES
-1);
1573 } else if (startactive
) {
1574 down(&startpos
, NULL
,
1575 STARTITEMS_NUM
, STARTITEMS_NUM
);
1576 } else if (optionsactive
) {
1577 down(&optionspos
, NULL
,
1578 OPTIONSITEMS_NUM
, OPTIONSITEMS_NUM
);
1580 down(&mainpos
, NULL
,
1581 MAINITEMS_NUM
, MAINITEMS_NUM
);