-
Notifications
You must be signed in to change notification settings - Fork 2
/
tok.go
188 lines (175 loc) · 4.22 KB
/
tok.go
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package main
/* Keystrokes (roughly) between checkpoints */
const CHECKPOINT_INTERVAL = 400
var lastok = 0
var yrepcount = 0
const flushno = 5 /* input queue flushing threshold */
const MAXUM = 52 /* maximum number of user re-named monsters */
const MAXMNAME = 40 /* max length of a monster re-name */
var usermonster [MAXUM]string /* the user named monster name goes here */
var usermpoint byte = 0 /* the user monster pointer */
/*
lexical analyzer for larn
*/
func yylex() int {
if hit2flag {
hit2flag = false
yrepcount = 0
return ' '
}
if yrepcount > 0 {
yrepcount--
return lastok
} else {
yrepcount = 0
}
if yrepcount == 0 {
bottomdo()
showplayer()
} /* show where the player is */
lflush()
for {
c[BYTESIN]++
/* check for periodic checkpointing */
if ckpflag {
if (c[BYTESIN] % CHECKPOINT_INTERVAL) == 0 {
savegame(ckpfile)
}
}
var cc int
// TODO: need input buffer flushing at all?
//var ic int
/*
for { // if keyboard input buffer is too big, flush some of it
ioctl(0, FIONREAD, &ic);
if (ic > flushno)
read(0, &cc, 1);
if ic <= flushno {
break
}
}
*/
cc = ttgetch()
if cc <= '9' && cc >= '0' {
yrepcount = yrepcount*10 + cc - '0'
} else {
if yrepcount > 0 {
yrepcount--
}
lastok = cc
return lastok
}
}
panic("unreachable")
}
/*
* flushall() Function to flush all type-ahead in the input buffer
*/
func flushall() {
// TODO: implement flushall?
/*
char cc;
int ic;
for (;;) { // if keyboard input buffer is too big, flush some of it
ioctl(0, FIONREAD, &ic);
if (ic <= 0)
return;
while (ic > 0) {
read(0, &cc, 1);
--ic;
} // gobble up the byte
}
*/
}
/*
function to set the desired hardness
enter with hard= -1 for default hardness, else any desired hardness
*/
func sethard(hard int) {
j := c[HARDGAME]
hashewon()
if !restorflag { /* don't set c[HARDGAME] if restoring game */
if hard >= 0 {
c[HARDGAME] = hard
}
} else {
c[HARDGAME] = j /* set c[HARDGAME] to proper value if restoring game */
}
k := c[HARDGAME]
if k != 0 {
for j = 0; j <= MAXMONST+8; j++ {
mp := &monster[j]
i := ((6+k)*mp.hitpoints + 1) / 6
mp.hitpoints = icond(i < 0, 32767, i)
i = ((6+k)*mp.damage + 1) / 5
mp.damage = icond(i > 127, 127, i)
i = (10 * mp.gold) / (10 + k)
mp.gold = icond(i > 32767, 32767, i)
i = mp.armorclass - k
mp.armorclass = icond(i < -127, -127, i)
i = (7*mp.experience)/(7+k) + 1
mp.experience = icond(i <= 0, 1, i)
}
}
}
/*
function to read and process the larn options file
*/
func readopts() {
// TODO: implement readopts
/*
const char *i;
int j, k;
int flag;
flag = 1; // set to 0 if a name is specified
if !lopen(optsfile) {
strcpy(logname, loginname);
return; // user name if no character name
}
i = " ";
while (*i) {
if ((i = lgetw()) == NULL)
break; // check for EOF
while ((*i == ' ') || (*i == '\t'))
i++; // eat leading whitespace
if (strcmp(i, "bold-objects") == 0)
boldon = true
else if (strcmp(i, "enable-checkpointing") == 0)
ckpflag = true
else if (strcmp(i, "inverse-objects") == 0)
boldon = false
else if (strcmp(i, "monster:") == 0) { // name favorite monster
if ((i = lgetw()) == 0)
break;
strlcpy(usermonster[usermpoint], i, MAXMNAME);
if (usermpoint >= MAXUM)
continue; // defined all of em
if (isalpha(j = usermonster[usermpoint][0])) {
for (k = 1; k < MAXMONST + 8; k++) // find monster
if (monstnamelist[k] == j) {
monster[k].name = &usermonster[usermpoint++][0];
break;
}
}
else if (strcmp(i, "name:") == 0) { // defining players name
if ((i = lgetw()) == 0)
break;
strlcpy(logname, i, LOGNAMESIZE);
flag = 0;
} else if (strcmp(i, "no-introduction") == 0)
nowelcome = true
else if (strcmp(i, "no-beep") == 0)
nobeep = true
} else if (strcmp(i, "play-day-play") == 0) {
// bypass time restrictions: ignored
} else if (strcmp(i, "savefile:") == 0) { // defining savefilename
if ((i = lgetw()) == 0)
break;
strcpy(savefilename, i);
flag = 0;
}
}
if (flag)
strcpy(logname, loginname);
*/
}