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 $ */
3 /* $DragonFly: src/games/larn/tok.c,v 1.5 2006/10/08 17:11:30 pavalos Exp $ */
9 /* Keystrokes (roughly) between checkpoints */
10 #define CHECKPOINT_INTERVAL 400
12 static char lastok
= 0;
13 int yrepcount
= 0, dayplay
= 0;
17 static int flushno
= FLUSHNO
; /* input queue flushing threshold */
18 #define MAXUM 52 /* maximum number of user re-named monsters */
19 #define MAXMNAME 40 /* max length of a monster re-name */
20 static char usermonster
[MAXUM
][MAXMNAME
]; /* the user named monster name goes here */
21 static char usermpoint
= 0; /* the user monster pointer */
24 lexical analyzer for larn
44 } /* show where the player is */
48 /* check for periodic checkpointing */
50 if ((c
[BYTESIN
] % CHECKPOINT_INTERVAL
) == 0) {
54 wait(0); /* wait for other forks to finish */
64 lprcat("\nSorry, but it is now time for work. Your game has been saved.\n");
67 savegame(savefilename
);
72 #endif /* TIMECHECK */
75 do { /* if keyboard input buffer is too big, flush some of it */
76 ioctl(0, FIONREAD
, &ic
);
79 } while (ic
> flushno
);
81 if (read(0, &cc
, 1) != 1)
84 if (cc
== 'Y' - 64) { /* control Y -- shell escape */
86 clear(); /* scrolling region, home, clear, no attributes */
87 if ((ic
= fork()) == 0) { /* child */
90 execl("/bin/csh", "csh", NULL
);
94 if (ic
< 0) { /* error */
95 write(2, "Can't fork off a shell!\n", 25);
100 return (lastok
= 'L' - 64); /* redisplay screen */
103 if ((cc
<= '9') && (cc
>= '0')) {
104 yrepcount
= yrepcount
* 10 + cc
- '0';
108 return (lastok
= cc
);
114 * flushall() Function to flush all type-ahead in the input buffer
121 for (;;) { /* if keyboard input buffer is too big, flush some of it */
122 ioctl(0, FIONREAD
, &ic
);
128 } /* gobble up the byte */
133 function to set the desired hardness
134 enter with hard= -1 for default hardness, else any desired hardness
142 if (restorflag
== 0) { /* don't set c[HARDGAME] if restoring game */
146 c
[HARDGAME
] = j
; /* set c[HARDGAME] to proper value if restoring game */
148 if ((k
= c
[HARDGAME
]) != 0)
149 for (j
= 0; j
<= MAXMONST
+ 8; j
++) {
150 i
= ((6 + k
) * monster
[j
].hitpoints
+ 1) / 6;
151 monster
[j
].hitpoints
= (i
< 0) ? 32767 : i
;
152 i
= ((6 + k
) * monster
[j
].damage
+ 1) / 5;
153 monster
[j
].damage
= (i
> 127) ? 127 : i
;
154 i
= (10 * monster
[j
].gold
) / (10 + k
);
155 monster
[j
].gold
= (i
> 32767) ? 32767 : i
;
156 i
= monster
[j
].armorclass
- k
;
157 monster
[j
].armorclass
= (i
< -127) ? -127 : i
;
158 i
= (7 * monster
[j
].experience
) / (7 + k
) + 1;
159 monster
[j
].experience
= (i
<= 0) ? 1 : i
;
164 function to read and process the larn options file
173 flag
= 1; /* set to 0 if a name is specified */
174 if (lopen(optsfile
) < 0) {
175 strcpy(logname
, loginname
);
176 return; /* user name if no character name */
179 if ((i
= (char *)lgetw()) == 0)
180 break; /* check for EOF */
181 while ((*i
== ' ') || (*i
== '\t'))
182 i
++; /* eat leading whitespace */
185 if (strcmp(i
, "bold-objects") == 0)
190 if (strcmp(i
, "enable-checkpointing") == 0)
195 if (strcmp(i
, "inverse-objects") == 0)
200 if (strcmp(i
, "female") == 0)
201 sex
= 0; /* male or female */
205 if (strcmp(i
, "monster:") == 0) { /* name favorite monster */
206 if ((i
= lgetw()) == 0)
208 if (strlen(i
) >= MAXMNAME
)
210 strcpy(usermonster
[(int)usermpoint
], i
);
211 if (usermpoint
>= MAXUM
)
212 break; /* defined all of em */
213 if (isalpha(j
= usermonster
[(int)usermpoint
][0])) {
214 for (k
= 1; k
< MAXMONST
+ 8; k
++) /* find monster */
215 if (monstnamelist
[k
] == j
) {
216 monster
[k
].name
= &usermonster
[(int)usermpoint
++][0];
220 } else if (strcmp(i
, "male") == 0)
225 if (strcmp(i
, "name:") == 0) { /* defining players name */
226 if ((i
= lgetw()) == 0)
228 if (strlen(i
) >= LOGNAMESIZE
) i
[LOGNAMESIZE
- 1] = 0;
231 } else if (strcmp(i
, "no-introduction") == 0)
233 else if (strcmp(i
, "no-beep") == 0)
238 if (strcmp(i
, "process-name:") == 0) {
239 if ((i
= lgetw()) == 0)
241 if (strlen(i
) >= PSNAMESIZE
)
242 i
[PSNAMESIZE
- 1] = 0;
244 } else if (strcmp(i
, "play-day-play") == 0)
249 if (strcmp(i
, "savefile:") == 0) { /* defining savefilename */
250 if ((i
= lgetw()) == 0)
252 strcpy(savefilename
, i
);
259 strcpy(logname
, loginname
);