-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtok.c
157 lines (119 loc) · 2.7 KB
/
tok.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* tok.c */
/*
yylex()
flushall()
sethard()
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <fcntl.h>
#include "larncons.h"
#include "larndata.h"
#include "larnfunc.h"
# define CHKPTINT 400
static char lastok=0;
int yrepcount=0;
signed char move_no_pickup = FALSE ;
/*
* lexical analyzer for larn
*/
int yylex(void)
{
char cc;
char firsttime = TRUE;
if (hit2flag)
{
hit2flag=0;
yrepcount=0;
return(' ');
}
if (yrepcount>0)
{
--yrepcount;
return(lastok);
}
else
yrepcount=0;
if (yrepcount==0)
{
bottomdo();
showplayer(); /* show where the player is */
move_no_pickup = FALSE; /* clear 'm' flag */
}
lflush();
while (1)
{
c[BYTESIN]++;
cc = ttgetch();
/* get repeat count, showing to player
*/
if ((cc <= '9') && (cc >= '0'))
{
yrepcount = yrepcount*10 + cc - '0';
/* show count to player for feedback
*/
if ( yrepcount >= 10 )
{
cursors();
if (firsttime)
lprcat("\n");
lprintf("count: %d", (long)yrepcount );
firsttime=FALSE;
lflush(); /* show count */
}
}
else
{
/* check for multi-character commands and handle.
*/
if ( cc == 'm')
{
move_no_pickup = TRUE ;
cc = ttgetch();
}
if ( yrepcount > 0 )
--yrepcount;
return(lastok = cc);
}
}
}
/*
function to set the desired hardness
enter with hard= -1 for default hardness, else any desired hardness
*/
void sethard(int hard)
{
int j, k;
long i;
struct monst *mp;
j = c[HARDGAME];
hashewon();
/* don't set c[HARDGAME] if restoring game */
if (restorflag == 0) {
if (hard >= 0) {
c[HARDGAME] = hard;
}
} else {
/* set c[HARDGAME] to proper value if restoring game */
c[HARDGAME] = j;
}
k = c[HARDGAME];
if (k == 0) {
return;
}
for (j = 0; j <= MAXMONST + 8; j++) {
mp = &monster[j];
i = ((6 + k) * mp->hitpoints + 1) / 6;
mp->hitpoints = (i < 0) ? 32767 : i;
i = ((6 + k) * mp->damage + 1) / 5;
mp->damage = (i > 127) ? 127 : i;
i = (10 * mp->gold) / (10 + k);
mp->gold = (i > 32767) ? 32767 : i;
i = mp->armorclass - k;
mp->armorclass = (i < -127) ? -127 : i;
i = (7 * mp->experience) / (7 + k) + 1;
mp->experience = (i <= 0) ? 1 : i;
}
}