-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpart3.h
451 lines (397 loc) · 8.35 KB
/
part3.h
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#pragma once
void cantGoThatWay()
{
puts("I can't go that way.");
}
void cantDoThat()
{
const char* const responses[] =
{
"Huh?",
"Umm... huh?",
"You're nuts.",
"You can't be serious.",
"Not freakin' likely."
"I don't know how.",
"An interesting idea.",
"I can't do that."
};
puts(responses[getRandom(7)]);
}
void huh()
{
puts("Huh?");
}
void dontKnowThatWord()
{
puts("I don't think I know that word.");
}
void findMeOne()
{
const char* const responses[] =
{
"Find me one.",
"I don't see one here.",
"Can't find it here.",
"You'd have to find it first."
};
puts(responses[getRandom(4)]);
}
void dontHaveIt()
{
puts("I don't have it.");
}
void alreadyHaveIt()
{
puts("I already have it.");
}
void seeNothingSpecial()
{
puts("I see nothing special.");
}
void seeSomething(objects object, const char* message)
{
if (state.objectPlace[object] == nowhere)
{
puts("Oh! I see something!");
state.objectPlace[object] = state.yourPlace;
}
else if (message == NULL)
seeNothingSpecial();
else
puts(message);
}
void maybeLater()
{
puts("Maybe not just yet.");
}
void noMoney()
{
puts("Sorry, no money.");
}
bool objectIsHere(objects object)
{
if (object >= noObject) return false;
return state.objectPlace[object] == state.yourPlace;
}
bool objectIsCarried(objects object)
{
return state.objectPlace[object] == youHaveIt;
}
bool objectCanBeTaken(objects object)
{
const objects them[] = {
newspaper, ring, whiskey, beer, hammer, garbage, flowers,
appleCore, seeds, candy, pills, plant, passcard, radio, knife,
magazine, rubber, wine, wallet, doll, apple, pitcher, stool,
rope, rack, mushroom, controlUnit, water
};
for (int i = 0; i < 28; i++)
if (them[i] == object)
return true;
return false;
}
bool placeIsPublic(places place)
{
const places there[] = {
bStreet, cStreet, cCasino, c21Room, cLobby, cHtDesk, dStreet, dEntrance
};
for (int i = 0; i < 8; i++)
if (there[i] == place)
return true;
return false;
}
bool youAreIn(places place)
{
return state.yourPlace == place;
}
void initNewGame()
{
clearScreen();
//putw("Hello there! I'm Kawa and I welcome you to Fact Hunt-- I mean, to Softporn Adventure! If all went well, this line should've been automatically word-wrapped at \"adventure\".");
puts("\n\n\n\n\n\n\n\n\n\n");
writeHeader(0, NULL, NULL);
setColor(BOLDCOLOR);
puts("Welcome to SOFTPORN ADVENTURE!\n");
setColor(REGULARCOLOR);
puts("Do you need instructions?");
putchar('>');
char yesNo = getOneOf('Y', 'N', 0);
if (yesNo == 'Y')
giveHelp();
else
puts("");
memset((void*)&state, 0, sizeof(gameState));
int i;
for (i = 0; i < 69; i++)
state.objectPlace[i] = origObjectPlace[i];
for (i = 0; i < 32; i++)
{
state.placeVisited[i] = false;
for (int j = 0; j < 6; j++)
state.path[i][j] = origPath[i][j];
}
state.yourPlace = bBar;
state.money = 10; //$1000
}
void lookAround()
{
char status[80];
sprintf(status, "Score: %d/3", state.score);
writeHeader(0, placeHeaders[state.yourPlace], status);
if (!noImAt)
{
setColor(BOLDCOLOR);
printf("\n>> %s\n", placeHeaders[state.yourPlace]);
setColor(REGULARCOLOR);
if (!state.placeVisited[state.yourPlace])
{
writeLongMessage(state.yourPlace + 1);
puts("");
}
}
if (youAreIn(pPntPch) && state.called5550439)
{
if (!state.telephoneAnswered && getRandom(4) == 2)
state.telephoneRinging = true;
if (state.telephoneRinging)
puts("The telephone rings.");
puts("");
}
int statusLine = 1;
{
strcpy(status, "Things here: ");
int ct = 0;
int i;
for (i = 0; i < 70; i++)
{
if (objectIsHere((objects)i))
{
if (ct)
strcat(status, ", ");
ct++;
if (strlen(status) + strlen(objectNames[i]) > COLS - 1)
{
writeHeader(statusLine, status, NULL);
strcpy(status, " ");
statusLine++;
}
strcat(status, objectNames[i]);
}
}
if (ct == 0)
strcat(status, "Nothing interesting.");
writeHeader(statusLine, status, NULL);
statusLine++;
strcpy(status, "Exits: ");
ct = 0;
for (i = 0; i < 6; i++)
{
if (state.path[state.yourPlace][i] != nowhere)
ct++;
}
int exits = ct;
if (exits == 0)
strcat(status, "By magic!");
else
{
for (int i = 0; i < 6; i++)
{
if (state.path[state.yourPlace][i] != nowhere)
{
if (ct < exits)
{
if (ct > 1)
strcat(status, ", ");
else if (exits > 1)
strcat(status, " and ");
}
ct--;
strcat(status, directionNames[i]);
}
}
}
writeHeader(statusLine, status, NULL);
}
state.placeVisited[state.yourPlace] = true;
noImAt = false;
}
/*
procedure take_inventory;
(*=====================*)
var objcount : integer;
obj : objects;
begin
with game_position do
begin
writeln;
writeln( 'I''m carrying: ');
objcount := 0;
for obj := first_object to last_object do
begin
if is_carried(obj) then
begin
objcount := objcount + 1;
writeln(object_name[obj]);
end;
end;
if objcount=0 then writeln('Nothing') else writeln;
end;
end; { take_inventory }
*/
bool verbIsStandalone(verbs verb)
{
const verbs verbs[] =
{
look, jump, dance, help, quit, showScore, save, restore
};
for (int i = 0; i < 8; i++)
if (verbs[i] == verb)
return true;
return false;
}
bool verbIsSpecial(verbs verb)
{
const verbs verbs[] =
{
take /*inven*/, hail /*taxi*/, call /*number*/, play /*slot/21*/, buy, save, restore
};
for (int i = 0; i < 7; i++)
if (verbs[i] == verb)
return true;
return false;
}
char* trimWhiteSpace(char* str)
{
char *end;
int startSpaces = 0;
unsigned int i;
int len = strlen(str);
for (i = 0; i < len; i++)
{
if (isspace(str[i]))
startSpaces++;
else
break;
}
strcpy(str, str + startSpaces);
if (*str == 0)
return str;
end = str + strlen(str) - 1;
while (end > str && isspace((unsigned char)*end)) end--;
end[1] = '\0';
len = strlen(str);
for (i = 1; i < len; i++)
{
while (isspace(str[i]) && isspace(str[i - 1]))
{
strcpy(str + i, str + i + 1);
//for (int j = i; j < strlen(str); j++)
// str[i] = str[i + 1];
}
}
return str;
}
extern void parse(char*);
extern int results[];
bool agiParse(char* str)
{
for (unsigned int i = 0; i < strlen(str); i++)
str[i] = (char)tolower(str[i]);
if (strlen(str) == 1)
{
switch (str[0])
{
case 'i': strcpy(str, "take inventory"); break;
case 'n': strcpy(str, "north"); break;
case 's': strcpy(str, "s"); break;
case 'e': strcpy(str, "east"); break;
case 'w': strcpy(str, "west"); break;
case 'u': strcpy(str, "up"); break;
case 'd': strcpy(str, "down"); break;
}
}
parse(str);
if (results[0] == -1)
{
puts("I didn't catch that.");
return false;
}
if (results[0] == 2) //taek
{
puts("Learn to spell, numbnut!");
return false;
}
else if (results[1] == 3) //lady
{
puts("That's no lady, that's my sister!");
return false;
}
if (results[0] == 264)
{
//take inventory
results[0] = 302;
results[1] = 264;
}
else if (results[0] >= 100 && results[0] <= 199)
{
//go _____
results[1] = results[0];
results[0] = 300;
}
haveNoVerb = true;
haveNoObject = true;
haveNoDirection = true;
if (results[0] >= 300 && results[0] <= 399)
{
haveNoVerb = false;
state.verb = (verbs)(results[0] - 300);
}
if (results[1] >= 200 && results[1] <= 299)
{
haveNoObject = false;
state.noun = (objects)(results[1] - 200);
}
if (haveNoObject && results[1] >= 100 && results[1] <= 199)
{
haveNoDirection = false;
state.direction = (directions)(results[1] - 100);
}
haveVerbOnly = !haveNoVerb && (haveNoObject && haveNoDirection);
return true;
}
void readAndParseCommand()
{
bool commandOK = false;
places prevPlace = (places)-1;
char score[40];
int len;
sprintf(score, "Score: %d/3", state.score);
do
{
do
{
if (state.yourPlace != prevPlace)
lookAround();
prevPlace = state.yourPlace;
do
{
writeHeader(0, placeHeaders[state.yourPlace], score);
putchar('>');
getString(lineFromKbd, 256);
if (lineFromKbd[0] == '\0')
puts("Beg your pardon?");
} while (lineFromKbd[0] == '\0');
len = strlen(lineFromKbd);
for (unsigned int i = 0; i < len; i++)
{
if (ispunct(lineFromKbd[i]))
lineFromKbd[i] = ' ';
trimWhiteSpace(lineFromKbd);
}
} while (lineFromKbd[0] == '\0');
char command[257];
strcpy(command, lineFromKbd);
commandOK = agiParse(command);
} while (!commandOK);
}