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 $ */
10 int yrepcount
=0,dayplay
=0;
14 static int flushno
=FLUSHNO
; /* input queue flushing threshold */
15 #define MAXUM 52 /* maximum number of user re-named monsters */
16 #define MAXMNAME 40 /* max length of a monster re-name */
17 static char usermonster
[MAXUM
][MAXMNAME
]; /* the user named monster name goes here */
18 static char usermpoint
=0; /* the user monster pointer */
21 lexical analyzer for larn
28 if (hit2flag
) { hit2flag
=0; yrepcount
=0; return(' '); }
29 if (yrepcount
>0) { --yrepcount
; return(lastok
); } else yrepcount
=0;
30 if (yrepcount
==0) { bottomdo(); showplayer(); } /* show where the player is */
36 if ((c
[BYTESIN
] % 400) == 0) /* check for periodic checkpointing */
41 wait(0); /* wait for other forks to finish */
42 if (fork() == 0) { savegame(ckpfile
); exit(0); }
51 lprcat("\nSorry, but it is now time for work. Your game has been saved.\n"); beep();
52 lflush(); savegame(savefilename
); wizard
=nomove
=1; sleep(4);
55 #endif /* TIMECHECK */
59 do /* if keyboard input buffer is too big, flush some of it */
61 ioctl(0,FIONREAD
,&ic
);
62 if (ic
>flushno
) read(0,&cc
,1);
66 if (read(0,&cc
,1) != 1) return(lastok
= -1);
68 if (cc
== 'Y'-64) /* control Y -- shell escape */
70 resetscroll(); clear(); /* scrolling region, home, clear, no attributes */
71 if ((ic
=fork())==0) /* child */
75 execl("/bin/csh", "csh", NULL
); exit(1);
80 write(2,"Can't fork off a shell!\n",25); sleep(2);
84 return(lastok
= 'L'-64); /* redisplay screen */
87 if ((cc
<= '9') && (cc
>= '0'))
88 { yrepcount
= yrepcount
*10 + cc
- '0'; }
89 else { if (yrepcount
>0) --yrepcount
; return(lastok
= cc
); }
94 * flushall() Function to flush all type-ahead in the input buffer
101 for (;;) /* if keyboard input buffer is too big, flush some of it */
103 ioctl(0,FIONREAD
,&ic
);
105 while (ic
>0) { read(0,&cc
,1); --ic
; } /* gobble up the byte */
110 function to set the desired hardness
111 enter with hard= -1 for default hardness, else any desired hardness
117 j
=c
[HARDGAME
]; hashewon();
118 if (restorflag
==0) /* don't set c[HARDGAME] if restoring game */
120 if (hard
>= 0) c
[HARDGAME
]= hard
;
122 else c
[HARDGAME
]=j
; /* set c[HARDGAME] to proper value if restoring game */
125 for (j
=0; j
<=MAXMONST
+8; j
++)
127 i
= ((6+k
)*monster
[j
].hitpoints
+1)/6;
128 monster
[j
].hitpoints
= (i
<0) ? 32767 : i
;
129 i
= ((6+k
)*monster
[j
].damage
+1)/5;
130 monster
[j
].damage
= (i
>127) ? 127 : i
;
131 i
= (10*monster
[j
].gold
)/(10+k
);
132 monster
[j
].gold
= (i
>32767) ? 32767 : i
;
133 i
= monster
[j
].armorclass
- k
;
134 monster
[j
].armorclass
= (i
< -127) ? -127 : i
;
135 i
= (7*monster
[j
].experience
)/(7+k
) + 1;
136 monster
[j
].experience
= (i
<=0) ? 1 : i
;
141 function to read and process the larn options file
149 flag
=1; /* set to 0 if he specifies a name for his character */
150 if (lopen(optsfile
) < 0)
152 strcpy(logname
,loginname
); return; /* user name if no character name */
156 if ((i
=(char *)lgetw()) == 0) break; /* check for EOF */
157 while ((*i
==' ') || (*i
=='\t')) i
++; /* eat leading whitespace */
160 case 'b': if (strcmp(i
,"bold-objects") == 0) boldon
=1;
163 case 'e': if (strcmp(i
,"enable-checkpointing") == 0) ckpflag
=1;
166 case 'i': if (strcmp(i
,"inverse-objects") == 0) boldon
=0;
169 case 'f': if (strcmp(i
,"female") == 0) sex
=0; /* male or female */
172 case 'm': if (strcmp(i
,"monster:")== 0) /* name favorite monster */
174 if ((i
=lgetw())==0) break;
175 if (strlen(i
)>=MAXMNAME
) i
[MAXMNAME
-1]=0;
176 strcpy(usermonster
[(int)usermpoint
],i
);
177 if (usermpoint
>= MAXUM
) break; /* defined all of em */
178 if (isalpha(j
=usermonster
[(int)usermpoint
][0]))
180 for (k
=1; k
<MAXMONST
+8; k
++) /* find monster */
181 if (monstnamelist
[k
] == j
)
183 monster
[k
].name
= &usermonster
[(int)usermpoint
++][0];
188 else if (strcmp(i
,"male") == 0) sex
=1;
191 case 'n': if (strcmp(i
,"name:") == 0) /* defining players name */
193 if ((i
=lgetw())==0) break;
194 if (strlen(i
)>=LOGNAMESIZE
) i
[LOGNAMESIZE
-1]=0;
195 strcpy(logname
,i
); flag
=0;
197 else if (strcmp(i
,"no-introduction") == 0) nowelcome
=1;
198 else if (strcmp(i
,"no-beep") == 0) nobeep
=1;
201 case 'p': if (strcmp(i
,"process-name:")== 0)
203 if ((i
=lgetw())==0) break;
204 if (strlen(i
)>=PSNAMESIZE
) i
[PSNAMESIZE
-1]=0;
207 else if (strcmp(i
,"play-day-play") == 0) dayplay
=1;
210 case 's': if (strcmp(i
,"savefile:") == 0) /* defining savefilename */
212 if ((i
=lgetw())==0) break;
213 strcpy(savefilename
,i
); flag
=0;
218 if (flag
) strcpy(logname
,loginname
);