1 /* tok.c Larn is copyrighted 1986 by Noah Morgan. */
2 /* $FreeBSD: src/games/larn/tok.c,v 1.5 1999/11/16 02:57:25 billf Exp $ */
8 /* Keystrokes (roughly) between checkpoints */
9 #define CHECKPOINT_INTERVAL 400
11 static char lastok
= 0;
12 int yrepcount
= 0, dayplay
= 0;
16 static int flushno
= FLUSHNO
; /* input queue flushing threshold */
17 #define MAXUM 52 /* maximum number of user re-named monsters */
18 #define MAXMNAME 40 /* max length of a monster re-name */
19 static char usermonster
[MAXUM
][MAXMNAME
]; /* the user named monster name goes here */
20 static char usermpoint
= 0; /* the user monster pointer */
23 lexical analyzer for larn
43 } /* show where the player is */
47 /* check for periodic checkpointing */
49 if ((c
[BYTESIN
] % CHECKPOINT_INTERVAL
) == 0) {
53 wait(0); /* wait for other forks to finish */
63 lprcat("\nSorry, but it is now time for work. Your game has been saved.\n");
66 savegame(savefilename
);
71 #endif /* TIMECHECK */
74 do { /* if keyboard input buffer is too big, flush some of it */
75 ioctl(0, FIONREAD
, &ic
);
78 } while (ic
> flushno
);
80 if (read(0, &cc
, 1) != 1)
83 if (cc
== 'Y' - 64) { /* control Y -- shell escape */
85 clear(); /* scrolling region, home, clear, no attributes */
86 if ((ic
= fork()) == 0) { /* child */
89 execl("/bin/csh", "csh", NULL
);
93 if (ic
< 0) { /* error */
94 write(2, "Can't fork off a shell!\n", 25);
99 return (lastok
= 'L' - 64); /* redisplay screen */
102 if ((cc
<= '9') && (cc
>= '0')) {
103 yrepcount
= yrepcount
* 10 + cc
- '0';
107 return (lastok
= cc
);
113 * flushall() Function to flush all type-ahead in the input buffer
120 for (;;) { /* if keyboard input buffer is too big, flush some of it */
121 ioctl(0, FIONREAD
, &ic
);
127 } /* gobble up the byte */
132 function to set the desired hardness
133 enter with hard= -1 for default hardness, else any desired hardness
141 if (restorflag
== 0) { /* don't set c[HARDGAME] if restoring game */
145 c
[HARDGAME
] = j
; /* set c[HARDGAME] to proper value if restoring game */
147 if ((k
= c
[HARDGAME
]) != 0)
148 for (j
= 0; j
<= MAXMONST
+ 8; j
++) {
149 i
= ((6 + k
) * monster
[j
].hitpoints
+ 1) / 6;
150 monster
[j
].hitpoints
= (i
< 0) ? 32767 : i
;
151 i
= ((6 + k
) * monster
[j
].damage
+ 1) / 5;
152 monster
[j
].damage
= (i
> 127) ? 127 : i
;
153 i
= (10 * monster
[j
].gold
) / (10 + k
);
154 monster
[j
].gold
= (i
> 32767) ? 32767 : i
;
155 i
= monster
[j
].armorclass
- k
;
156 monster
[j
].armorclass
= (i
< -127) ? -127 : i
;
157 i
= (7 * monster
[j
].experience
) / (7 + k
) + 1;
158 monster
[j
].experience
= (i
<= 0) ? 1 : i
;
163 function to read and process the larn options file
172 flag
= 1; /* set to 0 if a name is specified */
173 if (lopen(optsfile
) < 0) {
174 strcpy(logname
, loginname
);
175 return; /* user name if no character name */
178 if ((i
= (char *)lgetw()) == NULL
)
179 break; /* check for EOF */
180 while ((*i
== ' ') || (*i
== '\t'))
181 i
++; /* eat leading whitespace */
184 if (strcmp(i
, "bold-objects") == 0)
189 if (strcmp(i
, "enable-checkpointing") == 0)
194 if (strcmp(i
, "inverse-objects") == 0)
199 if (strcmp(i
, "female") == 0)
200 sex
= 0; /* male or female */
204 if (strcmp(i
, "monster:") == 0) { /* name favorite monster */
205 if ((i
= lgetw()) == NULL
)
207 if (strlen(i
) >= MAXMNAME
)
209 strcpy(usermonster
[(int)usermpoint
], i
);
210 if (usermpoint
>= MAXUM
)
211 break; /* defined all of em */
212 if (isalpha(j
= usermonster
[(int)usermpoint
][0])) {
213 for (k
= 1; k
< MAXMONST
+ 8; k
++) /* find monster */
214 if (monstnamelist
[k
] == j
) {
215 monster
[k
].name
= &usermonster
[(int)usermpoint
++][0];
219 } else if (strcmp(i
, "male") == 0)
224 if (strcmp(i
, "name:") == 0) { /* defining players name */
225 if ((i
= lgetw()) == NULL
)
227 if (strlen(i
) >= LOGNAMESIZE
) i
[LOGNAMESIZE
- 1] = 0;
230 } else if (strcmp(i
, "no-introduction") == 0)
232 else if (strcmp(i
, "no-beep") == 0)
237 if (strcmp(i
, "process-name:") == 0) {
238 if ((i
= lgetw()) == NULL
)
240 if (strlen(i
) >= PSNAMESIZE
)
241 i
[PSNAMESIZE
- 1] = 0;
243 } else if (strcmp(i
, "play-day-play") == 0)
248 if (strcmp(i
, "savefile:") == 0) { /* defining savefilename */
249 if ((i
= lgetw()) == NULL
)
251 strcpy(savefilename
, i
);
258 strcpy(logname
, loginname
);