]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/tok.c
1 /* tok.c Larn is copyrighted 1986 by Noah Morgan. */
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
29 if (hit2flag
) { hit2flag
=0; yrepcount
=0; return(' '); }
30 if (yrepcount
>0) { --yrepcount
; return(lastok
); } else yrepcount
=0;
31 if (yrepcount
==0) { bottomdo(); showplayer(); } /* show where the player is */
37 if ((c
[BYTESIN
] % 400) == 0) /* check for periodic checkpointing */
42 wait(0); /* wait for other forks to finish */
43 if (fork() == 0) { savegame(ckpfile
); exit(); }
52 lprcat("\nSorry, but it is now time for work. Your game has been saved.\n"); beep();
53 lflush(); savegame(savefilename
); wizard
=nomove
=1; sleep(4);
60 do /* if keyboard input buffer is too big, flush some of it */
62 ioctl(0,FIONREAD
,&ic
);
63 if (ic
>flushno
) read(0,&cc
,1);
67 if (read(0,&cc
,1) != 1) return(lastok
= -1);
69 if (cc
== 'Y'-64) /* control Y -- shell escape */
71 resetscroll(); clear(); /* scrolling region, home, clear, no attributes */
72 if ((ic
=fork())==0) /* child */
74 execl("/bin/csh",0); exit();
79 write(2,"Can't fork off a shell!\n",25); sleep(2);
83 return(lastok
= 'L'-64); /* redisplay screen */
86 if ((cc
<= '9') && (cc
>= '0'))
87 { yrepcount
= yrepcount
*10 + cc
- '0'; }
88 else { if (yrepcount
>0) --yrepcount
; return(lastok
= cc
); }
93 * flushall() Function to flush all type-ahead in the input buffer
99 for (;;) /* if keyboard input buffer is too big, flush some of it */
101 ioctl(0,FIONREAD
,&ic
);
103 while (ic
>0) { read(0,&cc
,1); --ic
; } /* gobble up the byte */
108 function to set the desired hardness
109 enter with hard= -1 for default hardness, else any desired hardness
115 j
=c
[HARDGAME
]; hashewon();
116 if (restorflag
==0) /* don't set c[HARDGAME] if restoring game */
118 if (hard
>= 0) c
[HARDGAME
]= hard
;
120 else c
[HARDGAME
]=j
; /* set c[HARDGAME] to proper value if restoring game */
123 for (j
=0; j
<=MAXMONST
+8; j
++)
125 i
= ((6+k
)*monster
[j
].hitpoints
+1)/6;
126 monster
[j
].hitpoints
= (i
<0) ? 32767 : i
;
127 i
= ((6+k
)*monster
[j
].damage
+1)/5;
128 monster
[j
].damage
= (i
>127) ? 127 : i
;
129 i
= (10*monster
[j
].gold
)/(10+k
);
130 monster
[j
].gold
= (i
>32767) ? 32767 : i
;
131 i
= monster
[j
].armorclass
- k
;
132 monster
[j
].armorclass
= (i
< -127) ? -127 : i
;
133 i
= (7*monster
[j
].experience
)/(7+k
) + 1;
134 monster
[j
].experience
= (i
<=0) ? 1 : i
;
139 function to read and process the larn options file
146 flag
=1; /* set to 0 if he specifies a name for his character */
147 if (lopen(optsfile
) < 0)
149 strcpy(logname
,loginname
); return; /* user name if no character name */
154 if ((i
=(char *)lgetw()) == 0) break; /* check for EOF */
155 while ((*i
==' ') || (*i
=='\t')) i
++; /* eat leading whitespace */
158 case 'b': if (strcmp(i
,"bold-objects") == 0) boldon
=1;
161 case 'e': if (strcmp(i
,"enable-checkpointing") == 0) ckpflag
=1;
164 case 'i': if (strcmp(i
,"inverse-objects") == 0) boldon
=0;
167 case 'f': if (strcmp(i
,"female") == 0) sex
=0; /* male or female */
170 case 'm': if (strcmp(i
,"monster:")== 0) /* name favorite monster */
172 if ((i
=lgetw())==0) break;
173 if (strlen(i
)>=MAXMNAME
) i
[MAXMNAME
-1]=0;
174 strcpy(usermonster
[usermpoint
],i
);
175 if (usermpoint
>= MAXUM
) break; /* defined all of em */
176 if (isalpha(j
=usermonster
[usermpoint
][0]))
178 for (k
=1; k
<MAXMONST
+8; k
++) /* find monster */
179 if (monstnamelist
[k
] == j
)
181 monster
[k
].name
= &usermonster
[usermpoint
++][0];
186 else if (strcmp(i
,"male") == 0) sex
=1;
189 case 'n': if (strcmp(i
,"name:") == 0) /* defining players name */
191 if ((i
=lgetw())==0) break;
192 if (strlen(i
)>=LOGNAMESIZE
) i
[LOGNAMESIZE
-1]=0;
193 strcpy(logname
,i
); flag
=0;
195 else if (strcmp(i
,"no-introduction") == 0) nowelcome
=1;
196 else if (strcmp(i
,"no-beep") == 0) nobeep
=1;
199 case 'p': if (strcmp(i
,"process-name:")== 0)
201 if ((i
=lgetw())==0) break;
202 if (strlen(i
)>=PSNAMESIZE
) i
[PSNAMESIZE
-1]=0;
205 else if (strcmp(i
,"play-day-play") == 0) dayplay
=1;
208 case 's': if (strcmp(i
,"savefile:") == 0) /* defining savefilename */
210 if ((i
=lgetw())==0) break;
211 strcpy(savefilename
,i
); flag
=0;
216 if (flag
) strcpy(logname
,loginname
);