]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/tok.c
1 /* $NetBSD: tok.c,v 1.5 1997/10/18 20:03:54 christos Exp $ */
3 /* tok.c Larn is copyrighted 1986 by Noah Morgan. */
6 __RCSID("$NetBSD: tok.c,v 1.5 1997/10/18 20:03:54 christos Exp $");
11 #include <sys/ioctl.h>
18 static char lastok
= 0;
19 int yrepcount
= 0, dayplay
= 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
74 lprcat("\nSorry, but it is now time for work. Your game has been saved.\n");
77 savegame(savefilename
);
82 #endif /* TIMECHECK */
85 do { /* if keyboard input buffer is too big, flush
87 ioctl(0, FIONREAD
, &ic
);
93 if (read(0, &cc
, 1) != 1)
96 if (cc
== 'Y' - 64) { /* control Y -- shell escape */
98 clear();/* scrolling region, home, clear, no
100 if ((ic
= fork()) == 0) { /* child */
101 execl("/bin/csh", 0);
105 if (ic
< 0) { /* error */
106 write(2, "Can't fork off a shell!\n", 25);
110 return (lastok
= 'L' - 64); /* redisplay screen */
112 if ((cc
<= '9') && (cc
>= '0')) {
113 yrepcount
= yrepcount
* 10 + cc
- '0';
117 return (lastok
= cc
);
123 * flushall() Function to flush all type-ahead in the input buffer
130 for (;;) { /* if keyboard input buffer is too big, flush
132 ioctl(0, FIONREAD
, &ic
);
138 } /* gobble up the byte */
143 function to set the desired hardness
144 enter with hard= -1 for default hardness, else any desired hardness
153 if (restorflag
== 0) { /* don't set c[HARDGAME] if restoring game */
157 c
[HARDGAME
] = j
;/* set c[HARDGAME] to proper value if
160 if ((k
= c
[HARDGAME
]) != 0)
161 for (j
= 0; j
<= MAXMONST
+ 8; j
++) {
162 i
= ((6 + k
) * monster
[j
].hitpoints
+ 1) / 6;
163 monster
[j
].hitpoints
= (i
< 0) ? 32767 : i
;
164 i
= ((6 + k
) * monster
[j
].damage
+ 1) / 5;
165 monster
[j
].damage
= (i
> 127) ? 127 : i
;
166 i
= (10 * monster
[j
].gold
) / (10 + k
);
167 monster
[j
].gold
= (i
> 32767) ? 32767 : i
;
168 i
= monster
[j
].armorclass
- k
;
169 monster
[j
].armorclass
= (i
< -127) ? -127 : i
;
170 i
= (7 * monster
[j
].experience
) / (7 + k
) + 1;
171 monster
[j
].experience
= (i
<= 0) ? 1 : i
;
176 function to read and process the larn options file
184 flag
= 1; /* set to 0 if he specifies a name for his
186 if (lopen(optsfile
) < 0) {
187 strcpy(logname
, loginname
);
188 return; /* user name if no character name */
192 if ((i
= (char *) lgetw()) == 0)
193 break; /* check for EOF */
194 while ((*i
== ' ') || (*i
== '\t'))
195 i
++; /* eat leading whitespace */
198 if (strcmp(i
, "bold-objects") == 0)
203 if (strcmp(i
, "enable-checkpointing") == 0)
208 if (strcmp(i
, "inverse-objects") == 0)
213 if (strcmp(i
, "female") == 0)
214 sex
= 0; /* male or female */
218 if (strcmp(i
, "monster:") == 0) { /* name favorite monster */
219 if ((i
= lgetw()) == 0)
221 if (strlen(i
) >= MAXMNAME
)
223 strcpy(usermonster
[usermpoint
], i
);
224 if (usermpoint
>= MAXUM
)
225 break; /* defined all of em */
226 if (isalpha(j
= usermonster
[usermpoint
][0])) {
227 for (k
= 1; k
< MAXMONST
+ 8; k
++) /* find monster */
228 if (monstnamelist
[k
] == j
) {
229 monster
[k
].name
= &usermonster
[usermpoint
++][0];
233 } else if (strcmp(i
, "male") == 0)
238 if (strcmp(i
, "name:") == 0) { /* defining players name */
239 if ((i
= lgetw()) == 0)
241 if (strlen(i
) >= LOGNAMESIZE
)
242 i
[LOGNAMESIZE
- 1] = 0;
245 } else if (strcmp(i
, "no-introduction") == 0)
247 else if (strcmp(i
, "no-beep") == 0)
252 if (strcmp(i
, "process-name:") == 0) {
253 if ((i
= lgetw()) == 0)
255 if (strlen(i
) >= PSNAMESIZE
)
256 i
[PSNAMESIZE
- 1] = 0;
258 } else if (strcmp(i
, "play-day-play") == 0)
263 if (strcmp(i
, "savefile:") == 0) { /* defining savefilename */
264 if ((i
= lgetw()) == 0)
266 strcpy(savefilename
, i
);
273 strcpy(logname
, loginname
);