Annotation of early-roguelike/rogue3/io.c, Revision 1.1.1.1
1.1 rubenllo 1: /*
2: * Various input/output functions
3: *
4: * @(#)io.c 3.10 (Berkeley) 6/15/81
5: *
6: * Rogue: Exploring the Dungeons of Doom
7: * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
8: * All rights reserved.
9: *
10: * See the file LICENSE.TXT for full copyright and licensing information.
11: */
12:
13: #include <stdlib.h>
14: #include "curses.h"
15: #include <ctype.h>
16: #include <stdarg.h>
17: #include <string.h>
18: #include "machdep.h"
19: #include "rogue.h"
20:
21: /*
22: * msg:
23: * Display a message at the top of the screen.
24: */
25:
26: static char msgbuf[BUFSIZ];
27: static int newpos = 0;
28:
29: /*VARARGS1*/
30: void
31: msg(char *fmt, ...)
32: {
33: va_list ap;
34: /*
35: * if the string is "", just clear the line
36: */
37: if (*fmt == '\0')
38: {
39: wmove(cw, 0, 0);
40: wclrtoeol(cw);
41: mpos = 0;
42: return;
43: }
44: /*
45: * otherwise add to the message and flush it out
46: */
47: va_start(ap, fmt);
48: doadd(fmt, ap);
49: va_end(ap);
50: endmsg();
51: }
52:
53: /*
54: * add things to the current message
55: */
56: void
57: addmsg(char *fmt, ...)
58: {
59: va_list ap;
60:
61: va_start(ap, fmt);
62: doadd(fmt, ap);
63: va_end(ap);
64: }
65:
66: /*
67: * Display a new msg (giving him a chance to see the previous one if it
68: * is up there with the --More--)
69: */
70: void
71: endmsg()
72: {
73: strncpy(huh, msgbuf, 80);
74: huh[79] = 0;
75:
76: if (mpos)
77: {
78: wmove(cw, 0, mpos);
79: waddstr(cw, "--More--");
80: draw(cw);
81: wait_for(cw,' ');
82: }
83: mvwaddstr(cw, 0, 0, msgbuf);
84: wclrtoeol(cw);
85: mpos = newpos;
86: newpos = 0;
87: draw(cw);
88: }
89:
90: void
91: doadd(char *fmt, va_list ap)
92: {
93: vsprintf(&msgbuf[newpos], fmt, ap);
94: newpos = (int) strlen(msgbuf);
95: }
96:
97: /*
98: * step_ok:
99: * returns true if it is ok to step on ch
100: */
101:
102: int
103: step_ok(int ch)
104: {
105: switch (ch)
106: {
107: case ' ':
108: case '|':
109: case '-':
110: case SECRETDOOR:
111: return FALSE;
112: default:
113: return (!isalpha(ch));
114: }
115: }
116:
117: /*
118: * readchar:
119: * flushes stdout so that screen is up to date and then returns
120: * getchar.
121: */
122:
123: int
124: readchar(WINDOW *win)
125: {
126: int ch;
127:
128: ch = md_readchar(win);
129:
130: if ((ch == 3) || (ch == 0))
131: {
132: quit(0);
133: return(27);
134: }
135:
136: return(ch);
137: }
138:
139: /*
140: * status:
141: * Display the important stats line. Keep the cursor where it was.
142: */
143:
144: void
145: status()
146: {
147: int oy, ox, temp;
148: char *pb;
149: static char buf[80];
150: static int hpwidth = 0, s_hungry = -1;
151: static int s_lvl = -1, s_pur, s_hp = -1, s_str, s_add, s_ac = 0;
152: static long s_exp = 0;
153:
154: /*
155: * If nothing has changed since the last status, don't
156: * bother.
157: */
158: if (s_hp == pstats.s_hpt && s_exp == pstats.s_exp && s_pur == purse
159: && s_ac == (cur_armor != NULL ? cur_armor->o_ac : pstats.s_arm)
160: && s_str == pstats.s_str.st_str && s_add == pstats.s_str.st_add
161: && s_lvl == level && s_hungry == hungry_state)
162: return;
163:
164: getyx(cw, oy, ox);
165: if (s_hp != max_hp)
166: {
167: temp = s_hp = max_hp;
168: for (hpwidth = 0; temp; hpwidth++)
169: temp /= 10;
170: }
171: sprintf(buf, "Level: %d Gold: %-5d Hp: %*d(%*d) Str: %-2d",
172: level, purse, hpwidth, pstats.s_hpt, hpwidth, max_hp,
173: pstats.s_str.st_str);
174: if (pstats.s_str.st_add != 0)
175: {
176: pb = &buf[strlen(buf)];
177: sprintf(pb, "/%d", pstats.s_str.st_add);
178: }
179: pb = &buf[strlen(buf)];
180: sprintf(pb, " Ac: %-2d Exp: %d/%d",
181: cur_armor != NULL ? cur_armor->o_ac : pstats.s_arm, pstats.s_lvl,
182: pstats.s_exp);
183: /*
184: * Save old status
185: */
186: s_lvl = level;
187: s_pur = purse;
188: s_hp = pstats.s_hpt;
189: s_str = pstats.s_str.st_str;
190: s_add = pstats.s_str.st_add;
191: s_exp = pstats.s_exp;
192: s_ac = (cur_armor != NULL ? cur_armor->o_ac : pstats.s_arm);
193: mvwaddstr(cw, LINES - 1, 0, buf);
194: switch (hungry_state)
195: {
196: case 0: ;
197: when 1:
198: waddstr(cw, " Hungry");
199: when 2:
200: waddstr(cw, " Weak");
201: when 3:
202: waddstr(cw, " Fainting");
203: }
204: wclrtoeol(cw);
205: s_hungry = hungry_state;
206: wmove(cw, oy, ox);
207: }
208:
209: /*
210: * wait_for
211: * Sit around until the guy types the right key
212: */
213:
214: void
215: wait_for(WINDOW *win, int ch)
216: {
217: int c;
218:
219: if (ch == '\n')
220: while ((c = readchar(win)) != '\n' && c != '\r')
221: continue;
222: else
223: while (readchar(win) != ch)
224: continue;
225: }
226:
227: /*
228: * show_win:
229: * function used to display a window and wait before returning
230: */
231:
232: void
233: show_win(WINDOW *scr, char *message)
234: {
235: mvwaddstr(scr, 0, 0, message);
236: touchwin(scr);
237: wmove(scr, hero.y, hero.x);
238: draw(scr);
239: wait_for(scr,' ');
240: clearok(cw, TRUE);
241: touchwin(cw);
242: }
243:
244: void
245: flush_type()
246: {
247: flushinp();
248: }
CVSweb