comparison srogue/io.c @ 36:2128c7dc8a40

Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 25 Nov 2010 12:21:41 +0000
parents
children 3aa87373c908
comparison
equal deleted inserted replaced
35:05018c63a721 36:2128c7dc8a40
1 /*
2 * Various input/output functions
3 *
4 * @(#)io.c 9.0 (rdk) 7/17/84
5 *
6 * Super-Rogue
7 * Copyright (C) 1984 Robert D. Kindelberger
8 * All rights reserved.
9 *
10 * Based on "Rogue: Exploring the Dungeons of Doom"
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
12 * All rights reserved.
13 *
14 * See the file LICENSE.TXT for full copyright and licensing information.
15 */
16
17 #include <stdarg.h>
18 #include <ctype.h>
19 #include "rogue.h"
20 #include "rogue.ext"
21
22 /*
23 * msg:
24 * Display a message at the top of the screen.
25 */
26 static char msgbuf[BUFSIZ];
27 static int newpos = 0;
28
29 msg(char *fmt, ...)
30 {
31 va_list ap;
32 /*
33 * if the string is "", just clear the line
34 */
35 if (*fmt == '\0') {
36 wmove(cw, 0, 0);
37 wclrtoeol(cw);
38 mpos = 0;
39 return;
40 }
41 /*
42 * otherwise add to the message and flush it out
43 */
44 va_start(ap, fmt);
45 doadd(fmt, ap);
46 va_end(ap);
47 endmsg();
48 }
49
50 /*
51 * addmsg:
52 * Add things to the current message
53 */
54 addmsg(char *fmt, ...)
55 {
56 va_list ap;
57
58 va_start(ap, fmt);
59 doadd(fmt, ap);
60 va_end(ap);
61 }
62
63 /*
64 * endmsg:
65 * Display a new msg, giving him a chance to see the
66 * previous one if it is up there with the --More--
67 */
68 endmsg()
69 {
70 strcpy(huh, msgbuf);
71 if (mpos > 0) {
72 wmove(cw, 0, mpos);
73 waddstr(cw, morestr);
74 draw(cw);
75 wait_for(cw, ' ');
76 }
77 mvwaddstr(cw, 0, 0, msgbuf);
78 wclrtoeol(cw);
79 mpos = newpos;
80 newpos = 0;
81 draw(cw);
82 }
83
84 /*
85 * doadd:
86 * Perform a printf into a buffer
87 */
88 doadd(char *fmt, va_list ap)
89 {
90 vsprintf(&msgbuf[newpos], fmt, ap);
91 newpos = strlen(msgbuf);
92 }
93
94 /*
95 * step_ok:
96 * Returns TRUE if it is ok to step on ch
97 */
98 step_ok(ch)
99 unsigned char ch;
100 {
101 if (dead_end(ch))
102 return FALSE;
103 else if (ch >= 32 && ch <= 127 && !isalpha(ch))
104 return TRUE;
105 return FALSE;
106 }
107
108
109 /*
110 * dead_end:
111 * Returns TRUE if you cant walk through that character
112 */
113 dead_end(ch)
114 char ch;
115 {
116 if (ch == '-' || ch == '|' || ch == ' ' || ch == SECRETDOOR)
117 return TRUE;
118 else
119 return FALSE;
120 }
121
122
123 /*
124 * readchar:
125 * flushes stdout so that screen is up to date and then returns
126 * getchar.
127 */
128
129 readchar()
130 {
131 char c;
132
133 fflush(stdout);
134 return( wgetch(cw) );
135 }
136
137 char *hungstr[] = {
138 "",
139 " HUNGRY",
140 " STARVING",
141 " FAINTING",
142 };
143
144 /*
145 * status:
146 * Display the important stats line. Keep the cursor where it was.
147 */
148 status(fromfuse)
149 int fromfuse;
150 {
151 reg int totwght, carwght;
152 reg struct real *stef, *stre, *stmx;
153 reg char *pb;
154 int oy, ox, ch;
155 static char buf[LINLEN];
156 static char hwidth[] = { "%2d(%2d)" };
157
158 /*
159 * If nothing has changed since the last time, then done
160 */
161 if (nochange)
162 return;
163 nochange = TRUE;
164 updpack(); /* get all weight info */
165 stef = &player.t_stats.s_ef;
166 stre = &player.t_stats.s_re;
167 stmx = &max_stats.s_re;
168 totwght = him->s_carry / 10;
169 carwght = him->s_pack / 10;
170 getyx(cw, oy, ox);
171 if (him->s_maxhp >= 100) {
172 hwidth[1] = '3'; /* if hit point >= 100 */
173 hwidth[5] = '3'; /* change %2d to %3d */
174 }
175 if (stre->a_str < stmx->a_str)
176 ch = '*';
177 else
178 ch = ' ';
179 sprintf(buf, "Str: %2d(%c%2d)", stef->a_str, ch, stre->a_str);
180 pb = &buf[strlen(buf)];
181 if (stre->a_dex < stmx->a_dex)
182 ch = '*';
183 else
184 ch = ' ';
185 sprintf(pb, " Dex: %2d(%c%2d)", stef->a_dex, ch, stre->a_dex);
186 pb = &buf[strlen(buf)];
187 if (stre->a_wis < stmx->a_wis)
188 ch = '*';
189 else
190 ch = ' ';
191 sprintf(pb, " Wis: %2d(%c%2d)", stef->a_wis, ch, stre->a_wis);
192 pb = &buf[strlen(buf)];
193 if (stre->a_con < stmx->a_con)
194 ch = '*';
195 else
196 ch = ' ';
197 sprintf(pb, " Con: %2d(%c%2d)", stef->a_con, ch, stre->a_con);
198 pb = &buf[strlen(buf)];
199 sprintf(pb, " Carry: %3d(%3d)", carwght, totwght);
200 mvwaddstr(cw, LINES - 1, 0, buf);
201 sprintf(buf, "Level: %d Gold: %5d Hp: ",level, purse);
202 pb = &buf[strlen(buf)];
203 sprintf(pb, hwidth, him->s_hpt, him->s_maxhp);
204 pb = &buf[strlen(buf)];
205 sprintf(pb," Ac: %-2d Exp: %d/%ld",cur_armor == NULL ? him->s_arm :
206 cur_armor->o_ac, him->s_lvl, him->s_exp);
207 carwght = (packvol * 100) / V_PACK;
208 pb = &buf[strlen(buf)];
209 sprintf(pb, " Vol: %3d%%", carwght);
210 mvwaddstr(cw, LINES - 2, 0, buf);
211 waddstr(cw, hungstr[hungry_state]);
212 wclrtoeol(cw);
213 wmove(cw, oy, ox);
214 }
215
216 /*
217 * dispmax:
218 * Display the hero's maximum status
219 */
220 dispmax()
221 {
222 reg struct real *hmax;
223
224 hmax = &max_stats.s_re;
225 msg("Maximums: Str = %d Dex = %d Wis = %d Con = %d",
226 hmax->a_str, hmax->a_dex, hmax->a_wis, hmax->a_con);
227 }
228
229 /*
230 * illeg_ch:
231 * Returns TRUE if a char shouldn't show on the screen
232 */
233 illeg_ch(ch)
234 unsigned char ch;
235 {
236 if (ch < 32 || ch > 127)
237 return TRUE;
238 if (ch >= '0' && ch <= '9')
239 return TRUE;
240 return FALSE;
241 }
242
243 /*
244 * wait_for:
245 * Sit around until the guy types the right key
246 */
247 wait_for(win,ch)
248 WINDOW *win;
249 char ch;
250 {
251 register char c;
252
253 if (ch == '\n')
254 while ((c = wgetch(win)) != '\n' && c != '\r')
255 continue;
256 else
257 while (wgetch(win) != ch)
258 continue;
259 }
260
261 #ifdef NEED_GETTIME
262 #include <stdio.h>
263 #include <pwd.h>
264
265 /*
266 * gettime:
267 * This routine returns the current time as a string
268 */
269 #ifdef ATT
270 #include <time.h>
271 #endif
272 #ifdef BSD
273 #include <sys/time.h>
274 #endif
275
276 char *
277 gettime()
278 {
279 register char *timeptr;
280 char *ctime();
281 long int now, time();
282
283 time(&now); /* get current time */
284 timeptr = ctime(&now); /* convert to string */
285 return timeptr; /* return the string */
286 }
287 #endif
288
289
290 /*
291 * dbotline:
292 * Displays message on bottom line and waits for a space to return
293 */
294 dbotline(scr,message)
295 WINDOW *scr;
296 char *message;
297 {
298 mvwaddstr(scr,LINES-1,0,message);
299 draw(scr);
300 wait_for(scr,' ');
301 }
302
303
304 /*
305 * restscr:
306 * Restores the screen to the terminal
307 */
308 restscr(scr)
309 WINDOW *scr;
310 {
311 clearok(scr,TRUE);
312 touchwin(scr);
313 }
314
315 /*
316 * npch:
317 * Get the next char in line for inventories
318 */
319 npch(ch)
320 char ch;
321 {
322 reg char nch;
323 if (ch >= 'z')
324 nch = 'A';
325 else
326 nch = ch + 1;
327 return nch;
328 }