1 /* $NetBSD: message.c,v 1.13 2008/01/14 03:50:01 dholland Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)message.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: message.c,v 1.13 2008/01/14 03:50:01 dholland Exp $");
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
60 #include "pathnames.h"
62 static char msgs
[NMESSAGES
][DCOLS
] = {"", "", "", "", ""};
63 static short msg_col
= 0, imsg
= -1;
64 static boolean rmsg
= 0;
66 boolean msg_cleared
= 1;
67 char hunger_str
[HUNGER_STR_LEN
] = "";
68 const char *more
= "-more-";
70 static void save_screen(void);
74 message(const char *msg
, boolean intrpt
)
78 if (!save_is_interactive
) {
87 mvaddstr(MIN_ROW
-1, msg_col
, more
);
93 imsg
= (imsg
+ 1) % NMESSAGES
;
94 (void)strlcpy(msgs
[imsg
], msg
, sizeof(msgs
[imsg
]));
96 mvaddstr(MIN_ROW
-1, 0, msg
);
100 msg_col
= strlen(msg
);
111 messagef(boolean intrpt
, const char *fmt
, ...)
117 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
120 message(buf
, intrpt
);
132 message(msgs
[((imsg
- c
) % NMESSAGES
)], 0);
134 move(rogue
.row
, rogue
.col
);
152 get_input_line(const char *prompt
, const char *insert
,
153 char *buf
, size_t buflen
,
154 const char *if_cancelled
,
155 boolean add_blank
, boolean do_echo
)
164 mvaddstr(0, n
+ 1, insert
);
165 (void)strlcpy(buf
, insert
, buflen
);
167 move(0, (n
+ i
+ 1));
171 while (((ch
= rgetchar()) != '\r') && (ch
!= '\n') && (ch
!= CANCEL
)) {
172 if ((ch
>= ' ') && (ch
<= '~') && (i
< buflen
-2)) {
173 if ((ch
!= ' ') || (i
> 0)) {
180 if ((ch
== '\b') && (i
> 0)) {
182 mvaddch(0, i
+ n
, ' ');
183 move(MIN_ROW
-1, i
+n
);
193 while ((i
> 0) && (buf
[i
-1] == ' ')) {
200 if ((ch
== CANCEL
) || (i
== 0) || ((i
== 1) && add_blank
)) {
202 message(if_cancelled
, 0);
218 case '\022': /* ^R */
222 case '\032': /* ^Z */
238 Level: 99 Gold: 999999 Hp: 999(999) Str: 99(99) Arm: 99 Exp: 21/10000000 Hungry
239 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5
243 print_stats(int stat_mask
)
249 label
= (stat_mask
& STAT_LABEL
) ? 1 : 0;
251 if (stat_mask
& STAT_LEVEL
) {
253 mvaddstr(row
, 0, "Level: ");
255 /* max level taken care of in make_level() */
256 mvprintw(row
, 7, "%-2d", cur_level
);
258 if (stat_mask
& STAT_GOLD
) {
260 mvaddstr(row
, 10, "Gold: ");
262 if (rogue
.gold
> MAX_GOLD
) {
263 rogue
.gold
= MAX_GOLD
;
265 mvprintw(row
, 16, "%-6ld", rogue
.gold
);
267 if (stat_mask
& STAT_HP
) {
269 mvaddstr(row
, 23, "Hp: ");
271 if (rogue
.hp_max
> MAX_HP
) {
272 rogue
.hp_current
-= (rogue
.hp_max
- MAX_HP
);
273 rogue
.hp_max
= MAX_HP
;
275 snprintf(buf
, sizeof(buf
), "%d(%d)",
276 rogue
.hp_current
, rogue
.hp_max
);
277 mvprintw(row
, 27, "%-8s", buf
);
279 if (stat_mask
& STAT_STRENGTH
) {
281 mvaddstr(row
, 36, "Str: ");
283 if (rogue
.str_max
> MAX_STRENGTH
) {
284 rogue
.str_current
-= (rogue
.str_max
- MAX_STRENGTH
);
285 rogue
.str_max
= MAX_STRENGTH
;
287 snprintf(buf
, sizeof(buf
), "%d(%d)",
288 (rogue
.str_current
+ add_strength
), rogue
.str_max
);
289 mvprintw(row
, 41, "%-6s", buf
);
291 if (stat_mask
& STAT_ARMOR
) {
293 mvaddstr(row
, 48, "Arm: ");
295 if (rogue
.armor
&& (rogue
.armor
->d_enchant
> MAX_ARMOR
)) {
296 rogue
.armor
->d_enchant
= MAX_ARMOR
;
298 mvprintw(row
, 53, "%-2d", get_armor_class(rogue
.armor
));
300 if (stat_mask
& STAT_EXP
) {
302 mvaddstr(row
, 56, "Exp: ");
304 if (rogue
.exp_points
> MAX_EXP
) {
305 rogue
.exp_points
= MAX_EXP
;
307 if (rogue
.exp
> MAX_EXP_LEVEL
) {
308 rogue
.exp
= MAX_EXP_LEVEL
;
310 snprintf(buf
, sizeof(buf
), "%d/%ld",
311 rogue
.exp
, rogue
.exp_points
);
312 mvprintw(row
, 61, "%-11s", buf
);
314 if (stat_mask
& STAT_HUNGER
) {
315 mvaddstr(row
, 73, hunger_str
);
328 if ((fp
= fopen(_PATH_SCREENDUMP
, "w")) != NULL
) {
329 for (i
= 0; i
< DROWS
; i
++) {
330 for (j
=0; j
<DCOLS
; j
++) {
331 buf
[j
] = mvinch(i
, j
);
333 /*buf[DCOLS] = 0; -- redundant */
334 for (j
=DCOLS
; j
>0 && buf
[j
-1]==' '; j
--);
356 return((ch
>= '0') && (ch
<= '9'));
360 r_index(const char *str
, int ch
, boolean last
)
365 for (i
= strlen(str
) - 1; i
>= 0; i
--) {
371 for (i
= 0; str
[i
]; i
++) {