| @@ -1,710 +1,711 @@ | | | @@ -1,710 +1,711 @@ |
1 | /* $NetBSD: pl_7.c,v 1.35 2009/03/15 03:33:56 dholland Exp $ */ | | 1 | /* $NetBSD: pl_7.c,v 1.36 2009/03/15 20:11:24 dholland Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1983, 1993 | | 4 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the University nor the names of its contributors | | 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 | | 16 | * may be used to endorse or promote products derived from this software |
17 | * without specific prior written permission. | | 17 | * without specific prior written permission. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 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 | | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 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 | | 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 | | 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 | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | #if 0 | | 34 | #if 0 |
35 | static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93"; | | 35 | static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93"; |
36 | #else | | 36 | #else |
37 | __RCSID("$NetBSD: pl_7.c,v 1.35 2009/03/15 03:33:56 dholland Exp $"); | | 37 | __RCSID("$NetBSD: pl_7.c,v 1.36 2009/03/15 20:11:24 dholland Exp $"); |
38 | #endif | | 38 | #endif |
39 | #endif /* not lint */ | | 39 | #endif /* not lint */ |
40 | | | 40 | |
41 | #include <curses.h> | | 41 | #include <curses.h> |
42 | #include <err.h> | | 42 | #include <err.h> |
43 | #include <errno.h> | | 43 | #include <errno.h> |
44 | #include <signal.h> | | 44 | #include <signal.h> |
45 | #include <stdarg.h> | | 45 | #include <stdarg.h> |
46 | #include <stdio.h> | | 46 | #include <stdio.h> |
47 | #include <stdlib.h> | | 47 | #include <stdlib.h> |
48 | #include <string.h> | | 48 | #include <string.h> |
49 | #include "array.h" | | 49 | #include "array.h" |
50 | #include "extern.h" | | 50 | #include "extern.h" |
51 | #include "player.h" | | 51 | #include "player.h" |
52 | #include "display.h" | | 52 | #include "display.h" |
53 | | | 53 | |
54 | /* | | 54 | /* |
55 | * Use values above KEY_MAX for custom keycodes. (blymn@ says this is ok) | | 55 | * Use values above KEY_MAX for custom keycodes. (blymn@ says this is ok) |
56 | */ | | 56 | */ |
57 | #define KEY_ESC(ch) (KEY_MAX+10+ch) | | 57 | #define KEY_ESC(ch) (KEY_MAX+10+ch) |
58 | | | 58 | |
59 | | | 59 | |
60 | /* | | 60 | /* |
61 | * Display interface | | 61 | * Display interface |
62 | */ | | 62 | */ |
63 | | | 63 | |
64 | static void draw_view(void); | | 64 | static void draw_view(void); |
65 | static void draw_turn(void); | | 65 | static void draw_turn(void); |
66 | static void draw_stat(void); | | 66 | static void draw_stat(void); |
67 | static void draw_slot(void); | | 67 | static void draw_slot(void); |
68 | static void draw_board(void); | | 68 | static void draw_board(void); |
69 | | | 69 | |
70 | static struct stringarray *sc_lines; | | 70 | static struct stringarray *sc_lines; |
71 | static unsigned sc_scrollup; | | 71 | static unsigned sc_scrollup; |
72 | static bool sc_hasprompt; | | 72 | static bool sc_hasprompt; |
73 | static bool sc_hideprompt; | | 73 | static bool sc_hideprompt; |
74 | static const char *sc_prompt; | | 74 | static const char *sc_prompt; |
75 | static const char *sc_buf; | | 75 | static const char *sc_buf; |
76 | | | 76 | |
77 | static WINDOW *view_w; | | 77 | static WINDOW *view_w; |
78 | static WINDOW *turn_w; | | 78 | static WINDOW *turn_w; |
79 | static WINDOW *stat_w; | | 79 | static WINDOW *stat_w; |
80 | static WINDOW *slot_w; | | 80 | static WINDOW *slot_w; |
81 | static WINDOW *scroll_w; | | 81 | static WINDOW *scroll_w; |
82 | | | 82 | |
83 | static bool obp[3]; | | 83 | static bool obp[3]; |
84 | static bool dbp[3]; | | 84 | static bool dbp[3]; |
85 | | | 85 | |
86 | int done_curses; | | 86 | int done_curses; |
87 | int loaded, fired, changed, repaired; | | 87 | int loaded, fired, changed, repaired; |
88 | int dont_adjust; | | 88 | int dont_adjust; |
89 | int viewrow, viewcol; | | 89 | int viewrow, viewcol; |
90 | char movebuf[sizeof SHIP(0)->file->movebuf]; | | 90 | char movebuf[sizeof SHIP(0)->file->movebuf]; |
91 | int player; | | 91 | int player; |
92 | struct ship *ms; /* memorial structure, &cc->ship[player] */ | | 92 | struct ship *ms; /* memorial structure, &cc->ship[player] */ |
93 | struct File *mf; /* ms->file */ | | 93 | struct File *mf; /* ms->file */ |
94 | struct shipspecs *mc; /* ms->specs */ | | 94 | struct shipspecs *mc; /* ms->specs */ |
95 | | | 95 | |
96 | //////////////////////////////////////////////////////////// | | 96 | //////////////////////////////////////////////////////////// |
97 | // overall initialization | | 97 | // overall initialization |
98 | | | 98 | |
99 | static | | 99 | static |
100 | void | | 100 | void |
101 | define_esc_key(int ch) | | 101 | define_esc_key(int ch) |
102 | { | | 102 | { |
103 | char seq[3] = { '\x1b', ch, 0 }; | | 103 | char seq[3] = { '\x1b', ch, 0 }; |
104 | | | 104 | |
105 | define_key(seq, KEY_ESC(ch)); | | 105 | define_key(seq, KEY_ESC(ch)); |
106 | } | | 106 | } |
107 | | | 107 | |
108 | void | | 108 | void |
109 | initscreen(void) | | 109 | initscreen(void) |
110 | { | | 110 | { |
111 | int ch; | | 111 | int ch; |
112 | | | 112 | |
113 | sc_lines = stringarray_create(); | | 113 | sc_lines = stringarray_create(); |
114 | if (sc_lines == NULL) { | | 114 | if (sc_lines == NULL) { |
115 | err(1, "malloc"); | | 115 | err(1, "malloc"); |
116 | } | | 116 | } |
117 | | | 117 | |
118 | if (signal(SIGTSTP, SIG_DFL) == SIG_ERR) { | | 118 | if (signal(SIGTSTP, SIG_DFL) == SIG_ERR) { |
119 | err(1, "signal(SIGTSTP)"); | | 119 | err(1, "signal(SIGTSTP)"); |
120 | } | | 120 | } |
121 | | | 121 | |
122 | if (initscr() == NULL) { | | 122 | if (initscr() == NULL) { |
123 | errx(1, "Can't sail on this terminal."); | | 123 | errx(1, "Can't sail on this terminal."); |
124 | } | | 124 | } |
125 | if (STAT_R >= COLS || SCROLL_Y <= 0) { | | 125 | if (STAT_R >= COLS || SCROLL_Y <= 0) { |
126 | errx(1, "Window/terminal not large enough."); | | 126 | errx(1, "Window/terminal not large enough."); |
127 | } | | 127 | } |
128 | | | 128 | |
129 | view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L); | | 129 | view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L); |
130 | slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L); | | 130 | slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L); |
131 | scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L); | | 131 | scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L); |
132 | stat_w = newwin(STAT_Y, STAT_X, STAT_T, STAT_L); | | 132 | stat_w = newwin(STAT_Y, STAT_X, STAT_T, STAT_L); |
133 | turn_w = newwin(TURN_Y, TURN_X, TURN_T, TURN_L); | | 133 | turn_w = newwin(TURN_Y, TURN_X, TURN_T, TURN_L); |
134 | | | 134 | |
135 | if (view_w == NULL || | | 135 | if (view_w == NULL || |
136 | slot_w == NULL || | | 136 | slot_w == NULL || |
137 | scroll_w == NULL || | | 137 | scroll_w == NULL || |
138 | stat_w == NULL || | | 138 | stat_w == NULL || |
139 | turn_w == NULL) { | | 139 | turn_w == NULL) { |
140 | endwin(); | | 140 | endwin(); |
141 | errx(1, "Curses initialization failed."); | | 141 | errx(1, "Curses initialization failed."); |
142 | } | | 142 | } |
143 | | | 143 | |
144 | leaveok(view_w, 1); | | 144 | leaveok(view_w, 1); |
145 | leaveok(slot_w, 1); | | 145 | leaveok(slot_w, 1); |
146 | leaveok(stat_w, 1); | | 146 | leaveok(stat_w, 1); |
147 | leaveok(turn_w, 1); | | 147 | leaveok(turn_w, 1); |
148 | noecho(); | | 148 | noecho(); |
149 | cbreak(); | | 149 | cbreak(); |
150 | | | 150 | |
151 | /* | | 151 | /* |
152 | * Define esc-x keys | | 152 | * Define esc-x keys |
153 | */ | | 153 | */ |
154 | for (ch = 0; ch < 127; ch++) { | | 154 | for (ch = 0; ch < 127; ch++) { |
155 | define_esc_key(ch); | | 155 | define_esc_key(ch); |
156 | } | | 156 | } |
157 | | | 157 | |
158 | done_curses++; | | 158 | done_curses++; |
159 | } | | 159 | } |
160 | | | 160 | |
161 | void | | 161 | void |
162 | cleanupscreen(void) | | 162 | cleanupscreen(void) |
163 | { | | 163 | { |
164 | /* alarm already turned off */ | | 164 | /* alarm already turned off */ |
165 | if (done_curses) { | | 165 | if (done_curses) { |
166 | wmove(scroll_w, SCROLL_Y - 1, 0); | | 166 | wmove(scroll_w, SCROLL_Y - 1, 0); |
167 | wclrtoeol(scroll_w); | | 167 | wclrtoeol(scroll_w); |
168 | display_redraw(); | | 168 | display_redraw(); |
169 | endwin(); | | 169 | endwin(); |
170 | } | | 170 | } |
171 | } | | 171 | } |
172 | | | 172 | |
173 | //////////////////////////////////////////////////////////// | | 173 | //////////////////////////////////////////////////////////// |
174 | // scrolling message area | | 174 | // scrolling message area |
175 | | | 175 | |
176 | static void | | 176 | static void |
177 | scrollarea_add(const char *text) | | 177 | scrollarea_add(const char *text) |
178 | { | | 178 | { |
179 | char *copy; | | 179 | char *copy; |
180 | int errsave; | | 180 | int errsave; |
181 | | | 181 | |
182 | copy = strdup(text); | | 182 | copy = strdup(text); |
183 | if (copy == NULL) { | | 183 | if (copy == NULL) { |
184 | goto nomem; | | 184 | goto nomem; |
185 | } | | 185 | } |
186 | if (stringarray_add(sc_lines, copy, NULL)) { | | 186 | if (stringarray_add(sc_lines, copy, NULL)) { |
187 | goto nomem; | | 187 | goto nomem; |
188 | } | | 188 | } |
189 | return; | | 189 | return; |
190 | | | 190 | |
191 | nomem: | | 191 | nomem: |
192 | /* | | 192 | /* |
193 | * XXX this should use leave(), but that won't | | 193 | * XXX this should use leave(), but that won't |
194 | * currently work right. | | 194 | * currently work right. |
195 | */ | | 195 | */ |
196 | errsave = errno; | | 196 | errsave = errno; |
197 | #if 0 | | 197 | #if 0 |
198 | leave(LEAVE_MALLOC); | | 198 | leave(LEAVE_MALLOC); |
199 | #else | | 199 | #else |
200 | cleanupscreen(); | | 200 | cleanupscreen(); |
201 | sync_close(!hasdriver); | | 201 | sync_close(!hasdriver); |
202 | errno = errsave; | | 202 | errno = errsave; |
203 | err(1, "malloc"); | | 203 | err(1, "malloc"); |
204 | #endif | | 204 | #endif |
205 | } | | 205 | } |
206 | | | 206 | |
207 | static void | | 207 | static void |
208 | draw_scroll(void) | | 208 | draw_scroll(void) |
209 | { | | 209 | { |
210 | unsigned total_lines; | | 210 | unsigned total_lines; |
211 | unsigned visible_lines; | | 211 | unsigned visible_lines; |
212 | unsigned index_of_top; | | 212 | unsigned index_of_top; |
213 | unsigned index_of_y; | | 213 | unsigned index_of_y; |
214 | unsigned y; | | 214 | unsigned y; |
215 | unsigned cursorx; | | 215 | unsigned cursorx; |
216 | | | 216 | |
217 | werase(scroll_w); | | 217 | werase(scroll_w); |
218 | | | 218 | |
219 | visible_lines = SCROLL_Y - 1; | | 219 | visible_lines = SCROLL_Y - 1; |
220 | | | 220 | |
221 | total_lines = stringarray_num(sc_lines); | | 221 | total_lines = stringarray_num(sc_lines); |
222 | if (total_lines > visible_lines) { | | 222 | if (total_lines > visible_lines) { |
223 | index_of_top = total_lines - visible_lines; | | 223 | index_of_top = total_lines - visible_lines; |
224 | } else { | | 224 | } else { |
225 | index_of_top = 0; | | 225 | index_of_top = 0; |
226 | } | | 226 | } |
227 | if (index_of_top < sc_scrollup) { | | 227 | if (index_of_top < sc_scrollup) { |
228 | index_of_top = 0; | | 228 | index_of_top = 0; |
229 | } else { | | 229 | } else { |
230 | index_of_top -= sc_scrollup; | | 230 | index_of_top -= sc_scrollup; |
231 | } | | 231 | } |
232 | | | 232 | |
233 | for (y = 0; y < SCROLL_Y - 1; y++) { | | 233 | /* XXX: SCROLL_Y and whatnot should be unsigned too */ |
| | | 234 | for (y = 0; y < (unsigned) (SCROLL_Y - 1); y++) { |
234 | index_of_y = index_of_top + y; | | 235 | index_of_y = index_of_top + y; |
235 | if (index_of_y >= total_lines) { | | 236 | if (index_of_y >= total_lines) { |
236 | break; | | 237 | break; |
237 | } | | 238 | } |
238 | wmove(scroll_w, y, 0); | | 239 | wmove(scroll_w, y, 0); |
239 | waddstr(scroll_w, stringarray_get(sc_lines, index_of_y)); | | 240 | waddstr(scroll_w, stringarray_get(sc_lines, index_of_y)); |
240 | } | | 241 | } |
241 | if (sc_hasprompt && !sc_hideprompt) { | | 242 | if (sc_hasprompt && !sc_hideprompt) { |
242 | wmove(scroll_w, SCROLL_Y-1, 0); | | 243 | wmove(scroll_w, SCROLL_Y-1, 0); |
243 | waddstr(scroll_w, sc_prompt); | | 244 | waddstr(scroll_w, sc_prompt); |
244 | waddstr(scroll_w, sc_buf); | | 245 | waddstr(scroll_w, sc_buf); |
245 | cursorx = strlen(sc_prompt) + strlen(sc_buf); | | 246 | cursorx = strlen(sc_prompt) + strlen(sc_buf); |
246 | wmove(scroll_w, SCROLL_Y-1, cursorx); | | 247 | wmove(scroll_w, SCROLL_Y-1, cursorx); |
247 | } | | 248 | } |
248 | else { | | 249 | else { |
249 | wmove(scroll_w, SCROLL_Y-1, 0); | | 250 | wmove(scroll_w, SCROLL_Y-1, 0); |
250 | } | | 251 | } |
251 | } | | 252 | } |
252 | | | 253 | |
253 | /*VARARGS2*/ | | 254 | /*VARARGS2*/ |
254 | void | | 255 | void |
255 | Signal(const char *fmt, struct ship *ship, ...) | | 256 | Signal(const char *fmt, struct ship *ship, ...) |
256 | { | | 257 | { |
257 | va_list ap; | | 258 | va_list ap; |
258 | char format[BUFSIZ]; | | 259 | char format[BUFSIZ]; |
259 | char buf[BUFSIZ]; | | 260 | char buf[BUFSIZ]; |
260 | | | 261 | |
261 | if (!done_curses) | | 262 | if (!done_curses) |
262 | return; | | 263 | return; |
263 | va_start(ap, ship); | | 264 | va_start(ap, ship); |
264 | if (*fmt == '\a') { | | 265 | if (*fmt == '\a') { |
265 | beep(); | | 266 | beep(); |
266 | fmt++; | | 267 | fmt++; |
267 | } | | 268 | } |
268 | fmtship(format, sizeof(format), fmt, ship); | | 269 | fmtship(format, sizeof(format), fmt, ship); |
269 | vsnprintf(buf, sizeof(buf), format, ap); | | 270 | vsnprintf(buf, sizeof(buf), format, ap); |
270 | va_end(ap); | | 271 | va_end(ap); |
271 | scrollarea_add(buf); | | 272 | scrollarea_add(buf); |
272 | } | | 273 | } |
273 | | | 274 | |
274 | /*VARARGS2*/ | | 275 | /*VARARGS2*/ |
275 | void | | 276 | void |
276 | Msg(const char *fmt, ...) | | 277 | Msg(const char *fmt, ...) |
277 | { | | 278 | { |
278 | va_list ap; | | 279 | va_list ap; |
279 | char buf[BUFSIZ]; | | 280 | char buf[BUFSIZ]; |
280 | | | 281 | |
281 | if (!done_curses) | | 282 | if (!done_curses) |
282 | return; | | 283 | return; |
283 | va_start(ap, fmt); | | 284 | va_start(ap, fmt); |
284 | if (*fmt == '\a') { | | 285 | if (*fmt == '\a') { |
285 | beep(); | | 286 | beep(); |
286 | fmt++; | | 287 | fmt++; |
287 | } | | 288 | } |
288 | vsnprintf(buf, sizeof(buf), fmt, ap); | | 289 | vsnprintf(buf, sizeof(buf), fmt, ap); |
289 | va_end(ap); | | 290 | va_end(ap); |
290 | scrollarea_add(buf); | | 291 | scrollarea_add(buf); |
291 | } | | 292 | } |
292 | | | 293 | |
293 | void | | 294 | void |
294 | prompt(const char *p, struct ship *ship) | | 295 | prompt(const char *p, struct ship *ship) |
295 | { | | 296 | { |
296 | static char buf[BUFSIZ]; | | 297 | static char buf[BUFSIZ]; |
297 | | | 298 | |
298 | fmtship(buf, sizeof(buf), p, ship); | | 299 | fmtship(buf, sizeof(buf), p, ship); |
299 | sc_prompt = buf; | | 300 | sc_prompt = buf; |
300 | sc_buf = ""; | | 301 | sc_buf = ""; |
301 | sc_hasprompt = true; | | 302 | sc_hasprompt = true; |
302 | } | | 303 | } |
303 | | | 304 | |
304 | static void | | 305 | static void |
305 | endprompt(void) | | 306 | endprompt(void) |
306 | { | | 307 | { |
307 | sc_prompt = NULL; | | 308 | sc_prompt = NULL; |
308 | sc_buf = NULL; | | 309 | sc_buf = NULL; |
309 | sc_hasprompt = false; | | 310 | sc_hasprompt = false; |
310 | } | | 311 | } |
311 | | | 312 | |
312 | /* | | 313 | /* |
313 | * Next two functions called from newturn() to poke display. Shouldn't | | 314 | * Next two functions called from newturn() to poke display. Shouldn't |
314 | * exist... XXX | | 315 | * exist... XXX |
315 | */ | | 316 | */ |
316 | | | 317 | |
317 | void | | 318 | void |
318 | display_hide_prompt(void) | | 319 | display_hide_prompt(void) |
319 | { | | 320 | { |
320 | sc_hideprompt = true; | | 321 | sc_hideprompt = true; |
321 | draw_scroll(); | | 322 | draw_scroll(); |
322 | wrefresh(scroll_w); | | 323 | wrefresh(scroll_w); |
323 | } | | 324 | } |
324 | | | 325 | |
325 | void | | 326 | void |
326 | display_reshow_prompt(void) | | 327 | display_reshow_prompt(void) |
327 | { | | 328 | { |
328 | sc_hideprompt = false; | | 329 | sc_hideprompt = false; |
329 | draw_scroll(); | | 330 | draw_scroll(); |
330 | wrefresh(scroll_w); | | 331 | wrefresh(scroll_w); |
331 | } | | 332 | } |
332 | | | 333 | |
333 | | | 334 | |
334 | int | | 335 | int |
335 | sgetch(const char *p, struct ship *ship, int flag) | | 336 | sgetch(const char *p, struct ship *ship, int flag) |
336 | { | | 337 | { |
337 | int c; | | 338 | int c; |
338 | char input[2]; | | 339 | char input[2]; |
339 | | | 340 | |
340 | prompt(p, ship); | | 341 | prompt(p, ship); |
341 | input[0] = '\0'; | | 342 | input[0] = '\0'; |
342 | input[1] = '\0'; | | 343 | input[1] = '\0'; |
343 | sc_buf = input; | | 344 | sc_buf = input; |
344 | blockalarm(); | | 345 | blockalarm(); |
345 | draw_scroll(); | | 346 | draw_scroll(); |
346 | wrefresh(scroll_w); | | 347 | wrefresh(scroll_w); |
347 | fflush(stdout); | | 348 | fflush(stdout); |
348 | unblockalarm(); | | 349 | unblockalarm(); |
349 | while ((c = wgetch(scroll_w)) == EOF) | | 350 | while ((c = wgetch(scroll_w)) == EOF) |
350 | ; | | 351 | ; |
351 | if (flag && c >= ' ' && c < 0x7f) { | | 352 | if (flag && c >= ' ' && c < 0x7f) { |
352 | blockalarm(); | | 353 | blockalarm(); |
353 | input[0] = c; | | 354 | input[0] = c; |
354 | draw_scroll(); | | 355 | draw_scroll(); |
355 | wrefresh(scroll_w); | | 356 | wrefresh(scroll_w); |
356 | fflush(stdout); | | 357 | fflush(stdout); |
357 | unblockalarm(); | | 358 | unblockalarm(); |
358 | } | | 359 | } |
359 | endprompt(); | | 360 | endprompt(); |
360 | return c; | | 361 | return c; |
361 | } | | 362 | } |
362 | | | 363 | |
363 | void | | 364 | void |
364 | sgetstr(const char *pr, char *buf, int n) | | 365 | sgetstr(const char *pr, char *buf, int n) |
365 | { | | 366 | { |
366 | int c; | | 367 | int c; |
367 | char *p = buf; | | 368 | char *p = buf; |
368 | | | 369 | |
369 | prompt(pr, (struct ship *)0); | | 370 | prompt(pr, (struct ship *)0); |
370 | sc_buf = buf; | | 371 | sc_buf = buf; |
371 | for (;;) { | | 372 | for (;;) { |
372 | *p = 0; | | 373 | *p = 0; |
373 | blockalarm(); | | 374 | blockalarm(); |
374 | draw_scroll(); | | 375 | draw_scroll(); |
375 | wrefresh(scroll_w); | | 376 | wrefresh(scroll_w); |
376 | fflush(stdout); | | 377 | fflush(stdout); |
377 | unblockalarm(); | | 378 | unblockalarm(); |
378 | while ((c = wgetch(scroll_w)) == EOF) | | 379 | while ((c = wgetch(scroll_w)) == EOF) |
379 | ; | | 380 | ; |
380 | switch (c) { | | 381 | switch (c) { |
381 | case '\n': | | 382 | case '\n': |
382 | case '\r': | | 383 | case '\r': |
383 | endprompt(); | | 384 | endprompt(); |
384 | return; | | 385 | return; |
385 | case '\b': | | 386 | case '\b': |
386 | if (p > buf) { | | 387 | if (p > buf) { |
387 | /*waddstr(scroll_w, "\b \b");*/ | | 388 | /*waddstr(scroll_w, "\b \b");*/ |
388 | p--; | | 389 | p--; |
389 | } | | 390 | } |
390 | break; | | 391 | break; |
391 | default: | | 392 | default: |
392 | if (c >= ' ' && c < 0x7f && p < buf + n - 1) { | | 393 | if (c >= ' ' && c < 0x7f && p < buf + n - 1) { |
393 | *p++ = c; | | 394 | *p++ = c; |
394 | /*waddch(scroll_w, c);*/ | | 395 | /*waddch(scroll_w, c);*/ |
395 | } else | | 396 | } else |
396 | beep(); | | 397 | beep(); |
397 | } | | 398 | } |
398 | } | | 399 | } |
399 | } | | 400 | } |
400 | | | 401 | |
401 | //////////////////////////////////////////////////////////// | | 402 | //////////////////////////////////////////////////////////// |
402 | // drawing of other panes | | 403 | // drawing of other panes |
403 | | | 404 | |
404 | void | | 405 | void |
405 | display_force_full_redraw(void) | | 406 | display_force_full_redraw(void) |
406 | { | | 407 | { |
407 | clear(); | | 408 | clear(); |
408 | } | | 409 | } |
409 | | | 410 | |
410 | void | | 411 | void |
411 | display_redraw(void) | | 412 | display_redraw(void) |
412 | { | | 413 | { |
413 | draw_board(); | | 414 | draw_board(); |
414 | draw_view(); | | 415 | draw_view(); |
415 | draw_turn(); | | 416 | draw_turn(); |
416 | draw_stat(); | | 417 | draw_stat(); |
417 | draw_slot(); | | 418 | draw_slot(); |
418 | draw_scroll(); | | 419 | draw_scroll(); |
419 | /* move the cursor */ | | 420 | /* move the cursor */ |
420 | wrefresh(scroll_w); | | 421 | wrefresh(scroll_w); |
421 | /* paranoia */ | | 422 | /* paranoia */ |
422 | fflush(stdout); | | 423 | fflush(stdout); |
423 | } | | 424 | } |
424 | | | 425 | |
425 | static void | | 426 | static void |
426 | draw_view(void) | | 427 | draw_view(void) |
427 | { | | 428 | { |
428 | struct ship *sp; | | 429 | struct ship *sp; |
429 | | | 430 | |
430 | werase(view_w); | | 431 | werase(view_w); |
431 | foreachship(sp) { | | 432 | foreachship(sp) { |
432 | if (sp->file->dir | | 433 | if (sp->file->dir |
433 | && sp->file->row > viewrow | | 434 | && sp->file->row > viewrow |
434 | && sp->file->row < viewrow + VIEW_Y | | 435 | && sp->file->row < viewrow + VIEW_Y |
435 | && sp->file->col > viewcol | | 436 | && sp->file->col > viewcol |
436 | && sp->file->col < viewcol + VIEW_X) { | | 437 | && sp->file->col < viewcol + VIEW_X) { |
437 | wmove(view_w, sp->file->row - viewrow, | | 438 | wmove(view_w, sp->file->row - viewrow, |
438 | sp->file->col - viewcol); | | 439 | sp->file->col - viewcol); |
439 | waddch(view_w, colours(sp)); | | 440 | waddch(view_w, colours(sp)); |
440 | wmove(view_w, | | 441 | wmove(view_w, |
441 | sternrow(sp) - viewrow, | | 442 | sternrow(sp) - viewrow, |
442 | sterncol(sp) - viewcol); | | 443 | sterncol(sp) - viewcol); |
443 | waddch(view_w, sterncolour(sp)); | | 444 | waddch(view_w, sterncolour(sp)); |
444 | } | | 445 | } |
445 | } | | 446 | } |
446 | wrefresh(view_w); | | 447 | wrefresh(view_w); |
447 | } | | 448 | } |
448 | | | 449 | |
449 | static void | | 450 | static void |
450 | draw_turn(void) | | 451 | draw_turn(void) |
451 | { | | 452 | { |
452 | wmove(turn_w, 0, 0); | | 453 | wmove(turn_w, 0, 0); |
453 | wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn); | | 454 | wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn); |
454 | wrefresh(turn_w); | | 455 | wrefresh(turn_w); |
455 | } | | 456 | } |
456 | | | 457 | |
457 | static void | | 458 | static void |
458 | draw_stat(void) | | 459 | draw_stat(void) |
459 | { | | 460 | { |
460 | wmove(stat_w, STAT_1, 0); | | 461 | wmove(stat_w, STAT_1, 0); |
461 | wprintw(stat_w, "Points %3d\n", mf->points); | | 462 | wprintw(stat_w, "Points %3d\n", mf->points); |
462 | wprintw(stat_w, "Fouls %2d\n", fouled(ms)); | | 463 | wprintw(stat_w, "Fouls %2d\n", fouled(ms)); |
463 | wprintw(stat_w, "Grapples %2d\n", grappled(ms)); | | 464 | wprintw(stat_w, "Grapples %2d\n", grappled(ms)); |
464 | | | 465 | |
465 | wmove(stat_w, STAT_2, 0); | | 466 | wmove(stat_w, STAT_2, 0); |
466 | wprintw(stat_w, " 0 %c(%c)\n", | | 467 | wprintw(stat_w, " 0 %c(%c)\n", |
467 | maxmove(ms, winddir + 3, -1) + '0', | | 468 | maxmove(ms, winddir + 3, -1) + '0', |
468 | maxmove(ms, winddir + 3, 1) + '0'); | | 469 | maxmove(ms, winddir + 3, 1) + '0'); |
469 | waddstr(stat_w, " \\|/\n"); | | 470 | waddstr(stat_w, " \\|/\n"); |
470 | wprintw(stat_w, " -^-%c(%c)\n", | | 471 | wprintw(stat_w, " -^-%c(%c)\n", |
471 | maxmove(ms, winddir + 2, -1) + '0', | | 472 | maxmove(ms, winddir + 2, -1) + '0', |
472 | maxmove(ms, winddir + 2, 1) + '0'); | | 473 | maxmove(ms, winddir + 2, 1) + '0'); |
473 | waddstr(stat_w, " /|\\\n"); | | 474 | waddstr(stat_w, " /|\\\n"); |
474 | wprintw(stat_w, " | %c(%c)\n", | | 475 | wprintw(stat_w, " | %c(%c)\n", |
475 | maxmove(ms, winddir + 1, -1) + '0', | | 476 | maxmove(ms, winddir + 1, -1) + '0', |
476 | maxmove(ms, winddir + 1, 1) + '0'); | | 477 | maxmove(ms, winddir + 1, 1) + '0'); |
477 | wprintw(stat_w, " %c(%c)\n", | | 478 | wprintw(stat_w, " %c(%c)\n", |
478 | maxmove(ms, winddir, -1) + '0', | | 479 | maxmove(ms, winddir, -1) + '0', |
479 | maxmove(ms, winddir, 1) + '0'); | | 480 | maxmove(ms, winddir, 1) + '0'); |
480 | | | 481 | |
481 | wmove(stat_w, STAT_3, 0); | | 482 | wmove(stat_w, STAT_3, 0); |
482 | wprintw(stat_w, "Load %c%c %c%c\n", | | 483 | wprintw(stat_w, "Load %c%c %c%c\n", |
483 | loadname[mf->loadL], readyname(mf->readyL), | | 484 | loadname[mf->loadL], readyname(mf->readyL), |
484 | loadname[mf->loadR], readyname(mf->readyR)); | | 485 | loadname[mf->loadR], readyname(mf->readyR)); |
485 | wprintw(stat_w, "Hull %2d\n", mc->hull); | | 486 | wprintw(stat_w, "Hull %2d\n", mc->hull); |
486 | wprintw(stat_w, "Crew %2d %2d %2d\n", | | 487 | wprintw(stat_w, "Crew %2d %2d %2d\n", |
487 | mc->crew1, mc->crew2, mc->crew3); | | 488 | mc->crew1, mc->crew2, mc->crew3); |
488 | wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR); | | 489 | wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR); |
489 | wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR); | | 490 | wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR); |
490 | wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3); | | 491 | wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3); |
491 | if (mc->rig4 < 0) | | 492 | if (mc->rig4 < 0) |
492 | waddch(stat_w, '-'); | | 493 | waddch(stat_w, '-'); |
493 | else | | 494 | else |
494 | wprintw(stat_w, "%d", mc->rig4); | | 495 | wprintw(stat_w, "%d", mc->rig4); |
495 | wrefresh(stat_w); | | 496 | wrefresh(stat_w); |
496 | } | | 497 | } |
497 | | | 498 | |
498 | void | | 499 | void |
499 | draw_slot(void) | | 500 | draw_slot(void) |
500 | { | | 501 | { |
501 | int i; | | 502 | int i; |
502 | | | 503 | |
503 | if (!boarding(ms, 0)) { | | 504 | if (!boarding(ms, 0)) { |
504 | mvwaddstr(slot_w, 0, 0, " "); | | 505 | mvwaddstr(slot_w, 0, 0, " "); |
505 | mvwaddstr(slot_w, 1, 0, " "); | | 506 | mvwaddstr(slot_w, 1, 0, " "); |
506 | } else { | | 507 | } else { |
507 | wmove(slot_w, 0, 0); | | 508 | wmove(slot_w, 0, 0); |
508 | for (i = 0; i < 3; i++) { | | 509 | for (i = 0; i < 3; i++) { |
509 | waddch(slot_w, obp[i] ? '1'+i : ' '); | | 510 | waddch(slot_w, obp[i] ? '1'+i : ' '); |
510 | } | | 511 | } |
511 | mvwaddstr(slot_w, 1, 0, "OBP"); | | 512 | mvwaddstr(slot_w, 1, 0, "OBP"); |
512 | } | | 513 | } |
513 | if (!boarding(ms, 1)) { | | 514 | if (!boarding(ms, 1)) { |
514 | mvwaddstr(slot_w, 2, 0, " "); | | 515 | mvwaddstr(slot_w, 2, 0, " "); |
515 | mvwaddstr(slot_w, 3, 0, " "); | | 516 | mvwaddstr(slot_w, 3, 0, " "); |
516 | } else { | | 517 | } else { |
517 | wmove(slot_w, 2, 0); | | 518 | wmove(slot_w, 2, 0); |
518 | for (i = 0; i < 3; i++) { | | 519 | for (i = 0; i < 3; i++) { |
519 | waddch(slot_w, dbp[i] ? '1'+i : ' '); | | 520 | waddch(slot_w, dbp[i] ? '1'+i : ' '); |
520 | } | | 521 | } |
521 | mvwaddstr(slot_w, 3, 0, "DBP"); | | 522 | mvwaddstr(slot_w, 3, 0, "DBP"); |
522 | } | | 523 | } |
523 | | | 524 | |
524 | wmove(slot_w, SLOT_Y-4, 0); | | 525 | wmove(slot_w, SLOT_Y-4, 0); |
525 | if (mf->RH) | | 526 | if (mf->RH) |
526 | wprintw(slot_w, "%dRH", mf->RH); | | 527 | wprintw(slot_w, "%dRH", mf->RH); |
527 | else | | 528 | else |
528 | waddstr(slot_w, " "); | | 529 | waddstr(slot_w, " "); |
529 | wmove(slot_w, SLOT_Y-3, 0); | | 530 | wmove(slot_w, SLOT_Y-3, 0); |
530 | if (mf->RG) | | 531 | if (mf->RG) |
531 | wprintw(slot_w, "%dRG", mf->RG); | | 532 | wprintw(slot_w, "%dRG", mf->RG); |
532 | else | | 533 | else |
533 | waddstr(slot_w, " "); | | 534 | waddstr(slot_w, " "); |
534 | wmove(slot_w, SLOT_Y-2, 0); | | 535 | wmove(slot_w, SLOT_Y-2, 0); |
535 | if (mf->RR) | | 536 | if (mf->RR) |
536 | wprintw(slot_w, "%dRR", mf->RR); | | 537 | wprintw(slot_w, "%dRR", mf->RR); |
537 | else | | 538 | else |
538 | waddstr(slot_w, " "); | | 539 | waddstr(slot_w, " "); |
539 | | | 540 | |
540 | #define Y (SLOT_Y/2) | | 541 | #define Y (SLOT_Y/2) |
541 | wmove(slot_w, 7, 1); | | 542 | wmove(slot_w, 7, 1); |
542 | wprintw(slot_w,"%d", windspeed); | | 543 | wprintw(slot_w,"%d", windspeed); |
543 | mvwaddch(slot_w, Y, 0, ' '); | | 544 | mvwaddch(slot_w, Y, 0, ' '); |
544 | mvwaddch(slot_w, Y, 2, ' '); | | 545 | mvwaddch(slot_w, Y, 2, ' '); |
545 | mvwaddch(slot_w, Y-1, 0, ' '); | | 546 | mvwaddch(slot_w, Y-1, 0, ' '); |
546 | mvwaddch(slot_w, Y-1, 1, ' '); | | 547 | mvwaddch(slot_w, Y-1, 1, ' '); |
547 | mvwaddch(slot_w, Y-1, 2, ' '); | | 548 | mvwaddch(slot_w, Y-1, 2, ' '); |
548 | mvwaddch(slot_w, Y+1, 0, ' '); | | 549 | mvwaddch(slot_w, Y+1, 0, ' '); |
549 | mvwaddch(slot_w, Y+1, 1, ' '); | | 550 | mvwaddch(slot_w, Y+1, 1, ' '); |
550 | mvwaddch(slot_w, Y+1, 2, ' '); | | 551 | mvwaddch(slot_w, Y+1, 2, ' '); |
551 | wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]); | | 552 | wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]); |
552 | switch (winddir) { | | 553 | switch (winddir) { |
553 | case 1: | | 554 | case 1: |
554 | case 5: | | 555 | case 5: |
555 | waddch(slot_w, '|'); | | 556 | waddch(slot_w, '|'); |
556 | break; | | 557 | break; |
557 | case 2: | | 558 | case 2: |
558 | case 6: | | 559 | case 6: |
559 | waddch(slot_w, '/'); | | 560 | waddch(slot_w, '/'); |
560 | break; | | 561 | break; |
561 | case 3: | | 562 | case 3: |
562 | case 7: | | 563 | case 7: |
563 | waddch(slot_w, '-'); | | 564 | waddch(slot_w, '-'); |
564 | break; | | 565 | break; |
565 | case 4: | | 566 | case 4: |
566 | case 8: | | 567 | case 8: |
567 | waddch(slot_w, '\\'); | | 568 | waddch(slot_w, '\\'); |
568 | break; | | 569 | break; |
569 | } | | 570 | } |
570 | mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+'); | | 571 | mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+'); |
571 | wrefresh(slot_w); | | 572 | wrefresh(slot_w); |
572 | } | | 573 | } |
573 | | | 574 | |
574 | void | | 575 | void |
575 | draw_board(void) | | 576 | draw_board(void) |
576 | { | | 577 | { |
577 | int n; | | 578 | int n; |
578 | | | 579 | |
579 | erase(); | | 580 | erase(); |
580 | werase(view_w); | | 581 | werase(view_w); |
581 | werase(slot_w); | | 582 | werase(slot_w); |
582 | werase(scroll_w); | | 583 | werase(scroll_w); |
583 | werase(stat_w); | | 584 | werase(stat_w); |
584 | werase(turn_w); | | 585 | werase(turn_w); |
585 | | | 586 | |
586 | move(BOX_T, BOX_L); | | 587 | move(BOX_T, BOX_L); |
587 | for (n = 0; n < BOX_X; n++) | | 588 | for (n = 0; n < BOX_X; n++) |
588 | addch('-'); | | 589 | addch('-'); |
589 | move(BOX_B, BOX_L); | | 590 | move(BOX_B, BOX_L); |
590 | for (n = 0; n < BOX_X; n++) | | 591 | for (n = 0; n < BOX_X; n++) |
591 | addch('-'); | | 592 | addch('-'); |
592 | for (n = BOX_T+1; n < BOX_B; n++) { | | 593 | for (n = BOX_T+1; n < BOX_B; n++) { |
593 | mvaddch(n, BOX_L, '|'); | | 594 | mvaddch(n, BOX_L, '|'); |
594 | mvaddch(n, BOX_R, '|'); | | 595 | mvaddch(n, BOX_R, '|'); |
595 | } | | 596 | } |
596 | mvaddch(BOX_T, BOX_L, '+'); | | 597 | mvaddch(BOX_T, BOX_L, '+'); |
597 | mvaddch(BOX_T, BOX_R, '+'); | | 598 | mvaddch(BOX_T, BOX_R, '+'); |
598 | mvaddch(BOX_B, BOX_L, '+'); | | 599 | mvaddch(BOX_B, BOX_L, '+'); |
599 | mvaddch(BOX_B, BOX_R, '+'); | | 600 | mvaddch(BOX_B, BOX_R, '+'); |
600 | refresh(); | | 601 | refresh(); |
601 | | | 602 | |
602 | #if 0 | | 603 | #if 0 |
603 | #define WSaIM "Wooden Ships & Iron Men" | | 604 | #define WSaIM "Wooden Ships & Iron Men" |
604 | wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2); | | 605 | wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2); |
605 | waddstr(view_w, WSaIM); | | 606 | waddstr(view_w, WSaIM); |
606 | wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2); | | 607 | wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2); |
607 | waddstr(view_w, cc->name); | | 608 | waddstr(view_w, cc->name); |
608 | wrefresh(view_w); | | 609 | wrefresh(view_w); |
609 | #endif | | 610 | #endif |
610 | | | 611 | |
611 | move(LINE_T, LINE_L); | | 612 | move(LINE_T, LINE_L); |
612 | printw("Class %d %s (%d guns) '%s' (%c%c)", | | 613 | printw("Class %d %s (%d guns) '%s' (%c%c)", |
613 | mc->class, | | 614 | mc->class, |
614 | classname[mc->class], | | 615 | classname[mc->class], |
615 | mc->guns, | | 616 | mc->guns, |
616 | ms->shipname, | | 617 | ms->shipname, |
617 | colours(ms), | | 618 | colours(ms), |
618 | sterncolour(ms)); | | 619 | sterncolour(ms)); |
619 | refresh(); | | 620 | refresh(); |
620 | } | | 621 | } |
621 | | | 622 | |
622 | void | | 623 | void |
623 | display_set_obp(int which, bool show) | | 624 | display_set_obp(int which, bool show) |
624 | { | | 625 | { |
625 | obp[which] = show; | | 626 | obp[which] = show; |
626 | } | | 627 | } |
627 | | | 628 | |
628 | void | | 629 | void |
629 | display_set_dbp(int which, bool show) | | 630 | display_set_dbp(int which, bool show) |
630 | { | | 631 | { |
631 | dbp[which] = show; | | 632 | dbp[which] = show; |
632 | } | | 633 | } |
633 | | | 634 | |
634 | //////////////////////////////////////////////////////////// | | 635 | //////////////////////////////////////////////////////////// |
635 | // external actions on the display | | 636 | // external actions on the display |
636 | | | 637 | |
637 | void | | 638 | void |
638 | display_scroll_pageup(void) | | 639 | display_scroll_pageup(void) |
639 | { | | 640 | { |
640 | unsigned total_lines, visible_lines, limit; | | 641 | unsigned total_lines, visible_lines, limit; |
641 | unsigned pagesize = SCROLL_Y - 2; | | 642 | unsigned pagesize = SCROLL_Y - 2; |
642 | | | 643 | |
643 | total_lines = stringarray_num(sc_lines); | | 644 | total_lines = stringarray_num(sc_lines); |
644 | visible_lines = SCROLL_Y - 1; | | 645 | visible_lines = SCROLL_Y - 1; |
645 | limit = total_lines - visible_lines; | | 646 | limit = total_lines - visible_lines; |
646 | | | 647 | |
647 | sc_scrollup += pagesize; | | 648 | sc_scrollup += pagesize; |
648 | if (sc_scrollup > limit) { | | 649 | if (sc_scrollup > limit) { |
649 | sc_scrollup = limit; | | 650 | sc_scrollup = limit; |
650 | } | | 651 | } |
651 | } | | 652 | } |
652 | | | 653 | |
653 | void | | 654 | void |
654 | display_scroll_pagedown(void) | | 655 | display_scroll_pagedown(void) |
655 | { | | 656 | { |
656 | unsigned pagesize = SCROLL_Y - 2; | | 657 | unsigned pagesize = SCROLL_Y - 2; |
657 | | | 658 | |
658 | if (sc_scrollup < pagesize) { | | 659 | if (sc_scrollup < pagesize) { |
659 | sc_scrollup = 0; | | 660 | sc_scrollup = 0; |
660 | } else { | | 661 | } else { |
661 | sc_scrollup -= pagesize; | | 662 | sc_scrollup -= pagesize; |
662 | } | | 663 | } |
663 | } | | 664 | } |
664 | | | 665 | |
665 | void | | 666 | void |
666 | centerview(void) | | 667 | centerview(void) |
667 | { | | 668 | { |
668 | viewrow = mf->row - VIEW_Y / 2; | | 669 | viewrow = mf->row - VIEW_Y / 2; |
669 | viewcol = mf->col - VIEW_X / 2; | | 670 | viewcol = mf->col - VIEW_X / 2; |
670 | } | | 671 | } |
671 | | | 672 | |
672 | void | | 673 | void |
673 | upview(void) | | 674 | upview(void) |
674 | { | | 675 | { |
675 | viewrow -= VIEW_Y / 3; | | 676 | viewrow -= VIEW_Y / 3; |
676 | } | | 677 | } |
677 | | | 678 | |
678 | void | | 679 | void |
679 | downview(void) | | 680 | downview(void) |
680 | { | | 681 | { |
681 | viewrow += VIEW_Y / 3; | | 682 | viewrow += VIEW_Y / 3; |
682 | } | | 683 | } |
683 | | | 684 | |
684 | void | | 685 | void |
685 | leftview(void) | | 686 | leftview(void) |
686 | { | | 687 | { |
687 | viewcol -= VIEW_X / 5; | | 688 | viewcol -= VIEW_X / 5; |
688 | } | | 689 | } |
689 | | | 690 | |
690 | void | | 691 | void |
691 | rightview(void) | | 692 | rightview(void) |
692 | { | | 693 | { |
693 | viewcol += VIEW_X / 5; | | 694 | viewcol += VIEW_X / 5; |
694 | } | | 695 | } |
695 | | | 696 | |
696 | /* Called from newturn()... rename? */ | | 697 | /* Called from newturn()... rename? */ |
697 | void | | 698 | void |
698 | display_adjust_view(void) | | 699 | display_adjust_view(void) |
699 | { | | 700 | { |
700 | if (dont_adjust) | | 701 | if (dont_adjust) |
701 | return; | | 702 | return; |
702 | if (mf->row < viewrow + VIEW_Y/4) | | 703 | if (mf->row < viewrow + VIEW_Y/4) |
703 | viewrow = mf->row - (VIEW_Y - VIEW_Y/4); | | 704 | viewrow = mf->row - (VIEW_Y - VIEW_Y/4); |
704 | else if (mf->row > viewrow + (VIEW_Y - VIEW_Y/4)) | | 705 | else if (mf->row > viewrow + (VIEW_Y - VIEW_Y/4)) |
705 | viewrow = mf->row - VIEW_Y/4; | | 706 | viewrow = mf->row - VIEW_Y/4; |
706 | if (mf->col < viewcol + VIEW_X/8) | | 707 | if (mf->col < viewcol + VIEW_X/8) |
707 | viewcol = mf->col - (VIEW_X - VIEW_X/8); | | 708 | viewcol = mf->col - (VIEW_X - VIEW_X/8); |
708 | else if (mf->col > viewcol + (VIEW_X - VIEW_X/8)) | | 709 | else if (mf->col > viewcol + (VIEW_X - VIEW_X/8)) |
709 | viewcol = mf->col - VIEW_X/8; | | 710 | viewcol = mf->col - VIEW_X/8; |
710 | } | | 711 | } |