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