forked from devshane/zork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dso3.c
171 lines (152 loc) · 3.75 KB
/
dso3.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright (c) 1980, InfoCom Computers and Communications, Cambridge MA 02142
// All rights reserved, commercial usage strictly prohibited.
// Written by R. M. Supnik.
// Revisions Copyright (c) 2021, Darth Spectra (Lydia Marie Williamson).
#include "extern.h"
#include "common.h"
// Find exit from room
bool findxt(int dir, int rm) {
// System generated locals
bool ret_val;
// Local variables
int i, xi;
ret_val = true;
// !ASSUME WINS.
xi = rooms.rexit[rm - 1];
// !FIND FIRST ENTRY.
if (xi == 0) {
goto L1000;
}
// !NO EXITS?
L100:
i = exits.travel[xi - 1];
// !GET ENTRY.
curxt.xroom1 = i & xpars.xrmask;
// mask to 16-bits to get rid of sign extension problems with 32-bit ints
curxt.xtype = ((i & ~xpars.xlflag & 0xffff) / xpars.xfshft & xpars.xfmask) + 1;
switch (curxt.xtype) {
case 1:
goto L110;
case 2:
goto L120;
case 3:
goto L130;
case 4:
goto L130;
}
// !BRANCH ON ENTRY.
bug(10, curxt.xtype);
L130:
curxt.xobj = exits.travel[xi + 1] & xpars.xrmask;
curxt.xactio = exits.travel[xi + 1] / xpars.xashft;
L120:
curxt.xstrng = exits.travel[xi];
// !DOOR/CEXIT/NEXIT - STRING.
L110:
xi += xpars.xelnt[curxt.xtype - 1];
// !ADVANCE TO NEXT ENTRY.
if ((i & xpars.xdmask) == dir) {
return ret_val;
}
if ((i & xpars.xlflag) == 0) {
goto L100;
}
L1000:
ret_val = false;
// !YES, LOSE.
return ret_val;
}
// Find what I mean
int fwim(int f1, int f2, int rm, int con, int adv, bool nocare) {
// System generated locals
int ret_val, i__1, i__2;
// Local variables
int i, j;
ret_val = 0;
// !ASSUME NOTHING.
i__1 = objcts.olnt;
for (i = 1; i <= i__1; ++i) {
// !LOOP
if ((rm == 0 || objcts.oroom[i - 1] != rm) && (adv == 0 || objcts.oadv[i - 1] != adv) && (con == 0 || objcts.ocan[i - 1] != con)) {
goto L1000;
}
// OBJECT IS ON LIST... IS IT A MATCH?
if ((objcts.oflag1[i - 1] & VisiO) == 0) {
goto L1000;
}
// if ((~(nocare) & (objcts.oflag1[i - 1] & TakeO) == 0) || ⋯) {
if (!(nocare) && (objcts.oflag1[i - 1] & TakeO) == 0 || (objcts.oflag1[i - 1] & f1) == 0 && (objcts.oflag2[i - 1] & f2) == 0) {
goto L500;
}
if (ret_val == 0) {
goto L400;
}
// !ALREADY GOT SOMETHING?
ret_val = -ret_val;
// !YES, AMBIGUOUS.
return ret_val;
L400:
ret_val = i;
// !NOTE MATCH.
// DOES OBJECT CONTAIN A MATCH?
L500:
if ((objcts.oflag2[i - 1] & OpenO) == 0) {
goto L1000;
}
i__2 = objcts.olnt;
for (j = 1; j <= i__2; ++j) {
// !NO, SEARCH CONTENTS.
if (objcts.ocan[j - 1] != i || (objcts.oflag1[j - 1] & VisiO) == 0 || (objcts.oflag1[j - 1] & f1) == 0 && (objcts.oflag2[j - 1] & f2) == 0) {
goto L700;
}
if (ret_val == 0) {
goto L600;
}
ret_val = -ret_val;
return ret_val;
L600:
ret_val = j;
L700:
;
}
L1000:
;
}
return ret_val;
}
// Obtain yes/no answer
// Called as:
// YesIsTrue = yesno(Question, YesString, NoString);
bool yesno(int q, int y, int n) {
// System generated locals
bool ret_val;
// Local variables
char buf[100];
char ans;
L100:
rspeak(q), fflush(stdout);
// !ASK
more_input(buf, sizeof buf), ans = buf[0];
// !GET ANSWER
if (ans == 'Y' || ans == 'y') {
goto L200;
}
if (ans == 'N' || ans == 'n') {
goto L300;
}
rspeak(6);
// !SCOLD.
goto L100;
L200:
ret_val = true;
// !YES,
rspeak(y);
// !OUT WITH IT.
return ret_val;
L300:
ret_val = false;
// !NO,
rspeak(n);
// !LIKEWISE.
return ret_val;
}