]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/tok.c
2 static char rcsid
[] = "$NetBSD: tok.c,v 1.4 1995/04/24 12:24:14 cgd Exp $";
5 /* tok.c Larn is copyrighted 1986 by Noah Morgan. */
11 #include <sys/ioctl.h>
17 int yrepcount
=0,dayplay
=0;
21 static int flushno
=FLUSHNO
; /* input queue flushing threshold */
22 #define MAXUM 52 /* maximum number of user re-named monsters */
23 #define MAXMNAME 40 /* max length of a monster re-name */
24 static char usermonster
[MAXUM
][MAXMNAME
]; /* the user named monster name goes here */
25 static char usermpoint
=0; /* the user monster pointer */
28 lexical analyzer for larn
34 if (hit2flag
) { hit2flag
=0; yrepcount
=0; return(' '); }
35 if (yrepcount
>0) { --yrepcount
; return(lastok
); } else yrepcount
=0;
36 if (yrepcount
==0) { bottomdo(); showplayer(); } /* show where the player is */
42 if ((c
[BYTESIN
] % 400) == 0) /* check for periodic checkpointing */
47 wait(0); /* wait for other forks to finish */
48 if (fork() == 0) { savegame(ckpfile
); exit(); }
57 lprcat("\nSorry, but it is now time for work. Your game has been saved.\n"); beep();
58 lflush(); savegame(savefilename
); wizard
=nomove
=1; sleep(4);
65 do /* if keyboard input buffer is too big, flush some of it */
67 ioctl(0,FIONREAD
,&ic
);
68 if (ic
>flushno
) read(0,&cc
,1);
72 if (read(0,&cc
,1) != 1) return(lastok
= -1);
74 if (cc
== 'Y'-64) /* control Y -- shell escape */
76 resetscroll(); clear(); /* scrolling region, home, clear, no attributes */
77 if ((ic
=fork())==0) /* child */
79 execl("/bin/csh",0); exit();
84 write(2,"Can't fork off a shell!\n",25); sleep(2);
88 return(lastok
= 'L'-64); /* redisplay screen */
91 if ((cc
<= '9') && (cc
>= '0'))
92 { yrepcount
= yrepcount
*10 + cc
- '0'; }
93 else { if (yrepcount
>0) --yrepcount
; return(lastok
= cc
); }
98 * flushall() Function to flush all type-ahead in the input buffer
104 for (;;) /* if keyboard input buffer is too big, flush some of it */
106 ioctl(0,FIONREAD
,&ic
);
108 while (ic
>0) { read(0,&cc
,1); --ic
; } /* gobble up the byte */
113 function to set the desired hardness
114 enter with hard= -1 for default hardness, else any desired hardness
120 j
=c
[HARDGAME
]; hashewon();
121 if (restorflag
==0) /* don't set c[HARDGAME] if restoring game */
123 if (hard
>= 0) c
[HARDGAME
]= hard
;
125 else c
[HARDGAME
]=j
; /* set c[HARDGAME] to proper value if restoring game */
128 for (j
=0; j
<=MAXMONST
+8; j
++)
130 i
= ((6+k
)*monster
[j
].hitpoints
+1)/6;
131 monster
[j
].hitpoints
= (i
<0) ? 32767 : i
;
132 i
= ((6+k
)*monster
[j
].damage
+1)/5;
133 monster
[j
].damage
= (i
>127) ? 127 : i
;
134 i
= (10*monster
[j
].gold
)/(10+k
);
135 monster
[j
].gold
= (i
>32767) ? 32767 : i
;
136 i
= monster
[j
].armorclass
- k
;
137 monster
[j
].armorclass
= (i
< -127) ? -127 : i
;
138 i
= (7*monster
[j
].experience
)/(7+k
) + 1;
139 monster
[j
].experience
= (i
<=0) ? 1 : i
;
144 function to read and process the larn options file
151 flag
=1; /* set to 0 if he specifies a name for his character */
152 if (lopen(optsfile
) < 0)
154 strcpy(logname
,loginname
); return; /* user name if no character name */
159 if ((i
=(char *)lgetw()) == 0) break; /* check for EOF */
160 while ((*i
==' ') || (*i
=='\t')) i
++; /* eat leading whitespace */
163 case 'b': if (strcmp(i
,"bold-objects") == 0) boldon
=1;
166 case 'e': if (strcmp(i
,"enable-checkpointing") == 0) ckpflag
=1;
169 case 'i': if (strcmp(i
,"inverse-objects") == 0) boldon
=0;
172 case 'f': if (strcmp(i
,"female") == 0) sex
=0; /* male or female */
175 case 'm': if (strcmp(i
,"monster:")== 0) /* name favorite monster */
177 if ((i
=lgetw())==0) break;
178 if (strlen(i
)>=MAXMNAME
) i
[MAXMNAME
-1]=0;
179 strcpy(usermonster
[usermpoint
],i
);
180 if (usermpoint
>= MAXUM
) break; /* defined all of em */
181 if (isalpha(j
=usermonster
[usermpoint
][0]))
183 for (k
=1; k
<MAXMONST
+8; k
++) /* find monster */
184 if (monstnamelist
[k
] == j
)
186 monster
[k
].name
= &usermonster
[usermpoint
++][0];
191 else if (strcmp(i
,"male") == 0) sex
=1;
194 case 'n': if (strcmp(i
,"name:") == 0) /* defining players name */
196 if ((i
=lgetw())==0) break;
197 if (strlen(i
)>=LOGNAMESIZE
) i
[LOGNAMESIZE
-1]=0;
198 strcpy(logname
,i
); flag
=0;
200 else if (strcmp(i
,"no-introduction") == 0) nowelcome
=1;
201 else if (strcmp(i
,"no-beep") == 0) nobeep
=1;
204 case 'p': if (strcmp(i
,"process-name:")== 0)
206 if ((i
=lgetw())==0) break;
207 if (strlen(i
)>=PSNAMESIZE
) i
[PSNAMESIZE
-1]=0;
210 else if (strcmp(i
,"play-day-play") == 0) dayplay
=1;
213 case 's': if (strcmp(i
,"savefile:") == 0) /* defining savefilename */
215 if ((i
=lgetw())==0) break;
216 strcpy(savefilename
,i
); flag
=0;
221 if (flag
) strcpy(logname
,loginname
);