]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/tok.c
1 /* $NetBSD: tok.c,v 1.8 2008/02/03 20:01:24 dholland Exp $ */
3 /* tok.c Larn is copyrighted 1986 by Noah Morgan. */
6 __RCSID("$NetBSD: tok.c,v 1.8 2008/02/03 20:01:24 dholland Exp $");
11 #include <sys/ioctl.h>
18 static char lastok
= 0;
23 static int flushno
= FLUSHNO
; /* input queue flushing threshold */
24 #define MAXUM 52 /* maximum number of user re-named monsters */
25 #define MAXMNAME 40 /* max length of a monster re-name */
26 static char usermonster
[MAXUM
][MAXMNAME
]; /* the user named monster
28 static u_char usermpoint
= 0; /* the user monster pointer */
31 lexical analyzer for larn
51 } /* show where the player is */
56 if ((c
[BYTESIN
] % 400) == 0) { /* check for periodic
61 wait(0); /* wait for other forks to
69 do { /* if keyboard input buffer is too big, flush
71 ioctl(0, FIONREAD
, &ic
);
77 if (read(0, &cc
, 1) != 1)
80 if (cc
== 'Y' - 64) { /* control Y -- shell escape */
82 clear();/* scrolling region, home, clear, no
84 if ((ic
= fork()) == 0) { /* child */
85 execl("/bin/csh", "/bin/csh", NULL
);
89 if (ic
< 0) { /* error */
90 write(2, "Can't fork off a shell!\n", 25);
94 return (lastok
= 'L' - 64); /* redisplay screen */
96 if ((cc
<= '9') && (cc
>= '0')) {
97 yrepcount
= yrepcount
* 10 + cc
- '0';
101 return (lastok
= cc
);
107 * flushall() Function to flush all type-ahead in the input buffer
114 for (;;) { /* if keyboard input buffer is too big, flush
116 ioctl(0, FIONREAD
, &ic
);
122 } /* gobble up the byte */
127 function to set the desired hardness
128 enter with hard= -1 for default hardness, else any desired hardness
137 if (restorflag
== 0) { /* don't set c[HARDGAME] if restoring game */
141 c
[HARDGAME
] = j
;/* set c[HARDGAME] to proper value if
144 if ((k
= c
[HARDGAME
]) != 0)
145 for (j
= 0; j
<= MAXMONST
+ 8; j
++) {
146 i
= ((6 + k
) * monster
[j
].hitpoints
+ 1) / 6;
147 monster
[j
].hitpoints
= (i
< 0) ? 32767 : i
;
148 i
= ((6 + k
) * monster
[j
].damage
+ 1) / 5;
149 monster
[j
].damage
= (i
> 127) ? 127 : i
;
150 i
= (10 * monster
[j
].gold
) / (10 + k
);
151 monster
[j
].gold
= (i
> 32767) ? 32767 : i
;
152 i
= monster
[j
].armorclass
- k
;
153 monster
[j
].armorclass
= (i
< -127) ? -127 : i
;
154 i
= (7 * monster
[j
].experience
) / (7 + k
) + 1;
155 monster
[j
].experience
= (i
<= 0) ? 1 : i
;
160 function to read and process the larn options file
168 flag
= 1; /* set to 0 if he specifies a name for his
170 if (lopen(optsfile
) < 0) {
171 strcpy(logname
, loginname
);
172 return; /* user name if no character name */
176 if ((i
= lgetw()) == NULL
)
177 break; /* check for EOF */
178 while ((*i
== ' ') || (*i
== '\t'))
179 i
++; /* eat leading whitespace */
182 if (strcmp(i
, "bold-objects") == 0)
187 if (strcmp(i
, "enable-checkpointing") == 0)
192 if (strcmp(i
, "inverse-objects") == 0)
197 if (strcmp(i
, "female") == 0)
198 sex
= 0; /* male or female */
202 if (strcmp(i
, "monster:") == 0) { /* name favorite monster */
203 if ((i
= lgetw()) == 0)
205 strlcpy(usermonster
[usermpoint
], i
, MAXMNAME
);
206 if (usermpoint
>= MAXUM
)
207 break; /* defined all of em */
208 if (isalpha(j
= usermonster
[usermpoint
][0])) {
209 for (k
= 1; k
< MAXMONST
+ 8; k
++) /* find monster */
210 if (monstnamelist
[k
] == j
) {
211 monster
[k
].name
= &usermonster
[usermpoint
++][0];
215 } else if (strcmp(i
, "male") == 0)
220 if (strcmp(i
, "name:") == 0) { /* defining players name */
221 if ((i
= lgetw()) == 0)
223 strlcpy(logname
, i
, LOGNAMESIZE
);
225 } else if (strcmp(i
, "no-introduction") == 0)
227 else if (strcmp(i
, "no-beep") == 0)
232 if (strcmp(i
, "process-name:") == 0) {
233 if ((i
= lgetw()) == 0)
235 strlcpy(psname
, i
, PSNAMESIZE
);
236 } else if (strcmp(i
, "play-day-play") == 0) {
237 /* bypass time restrictions: ignored */
242 if (strcmp(i
, "savefile:") == 0) { /* defining savefilename */
243 if ((i
= lgetw()) == 0)
245 strcpy(savefilename
, i
);
252 strcpy(logname
, loginname
);