-
Notifications
You must be signed in to change notification settings - Fork 2
/
FLArgParsing.cpp
executable file
·564 lines (546 loc) · 17.1 KB
/
FLArgParsing.cpp
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
/* Copyright 2017 Gibbon aka 'atsb'
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "FLHelp.hpp"
#include "FLInventory.hpp"
#include "FLTermCapIO.hpp"
#include "FLScores.hpp"
#include "FLFuncs.hpp"
#include "FLStore.hpp"
#include "../config/FLIncludeData.hpp"
#include "../lexical/FLTok.hpp"
#include "../dungeon/FLDungeon.hpp"
#include "../terminal/FLTerminal.hpp"
#include "../player/FLPlayerActions.hpp"
#include "../player/FLRegenerate.hpp"
#include "../save/FLSave.hpp"
#include "../player/FLHunger.hpp"
#include "../terminal/FLGetChar.hpp"
#include "../templates/FLTTerm.hpp"
extern char viewflag;
const char* FL_BUILD_VERSION = "GNOME";
static const char* FL_APACHE2_NOTICE = "FreeLarn is Free Software distributed under the Apache 2.0 License";
bool FL_WIZARD_MODE_ENABLED = false;
extern int (*get_final_char_keyboard)(void);
void
parse(void) {
FLCoreFuncs CoreFuncs;
FLStore Store;
int i, j, k, flag;
Save save;
for (;;) {
k = yylex();
switch (k) { /* get the token from the input and switch on it */
case 'h': moveplayer(4); return; /* west */
case 'H': run(4); return; /* west */
case 'l': moveplayer(2); return; /* east */
case 'L': run(2); return; /* east */
case 'j': moveplayer(1); return; /* south */
case 'J': run(1); return; /* south */
case 'k': moveplayer(3); return; /* north */
case 'K': run(3); return; /* north */
case 'u': moveplayer(5); return; /* northeast */
case 'U': run(5); return; /* northeast */
case 'y': moveplayer(6); return; /* northwest */
case 'Y': run(6); return; /* northwest */
case 'n': moveplayer(7); return; /* southeast */
case 'N': run(7); return; /* southeast */
case 'b': moveplayer(8); return; /* southwest */
case 'B': run(8); return; /* southwest */
case '.': /* stay here */
if (y_larn_rep) {
viewflag = 1;
}
return;
case 'c':
y_larn_rep = 0;
fl_cast_a_spell();
return; /* cast a spell */
case 'd':
y_larn_rep = 0;
if (cdesc[FL_TIMESTOP] == 0) {
dropobj();
}
return; /* to drop an object */
case 'e':
y_larn_rep = 0;
if (cdesc[FL_TIMESTOP] == 0)
if (!floor_consume(OCOOKIE, "eat")) {
consume(OCOOKIE, "eat");
if (cdesc[FL_HUNGER] < cdesc[FL_HUNGERMAX]) {
cdesc[FL_HUNGER] += 10;
} else {
fl_display_message("\nIt has no affect on your appetite.");
}
}
return;
case 'g':
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
lprintf("\nThe stuff you are carrying presently weighs %d pounds",
(int) packweight());
break;
case 'i': /* inventory */
y_larn_rep = 0;
nomove = 1;
showstr(0);
return;
case 'p': /* pray at an altar */
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (object_identification[player_horizontal_position][player_vertical_position] != OALTAR) {
fl_display_message("\nI see no altar to pray at here!");
} else {
fl_a_give_donation();
}
prayed = 1;
return;
case '~':
TClearAndResetScreen(FL_CLEAR);
enable_scroll = 0;
showscores(0); /* if we updated the scoreboard */
fl_termcap_cursor_position(1, 24);
fl_display_message("\nPress any key to exit. ");
get_final_char_keyboard = ansiterm_getch;
ttgetch();
enable_scroll = 1;
drawscreen();
return;
case 'q': /* quaff a potion */
y_larn_rep = 0;
if (cdesc[FL_TIMESTOP] == 0)
if (!floor_consume(OPOTION, "quaff")) {
consume(OPOTION, "quaff");
}
return;
case 'r':
y_larn_rep = 0;
if (cdesc[FL_BLINDCOUNT]) {
fl_termcap_cursor_position(1, 24);
fl_display_message("\nYou can't read anything when you're blind!");
} else if (cdesc[FL_TIMESTOP] == 0)
if (!floor_consume(OSCROLL, "read"))
if (!floor_consume(OBOOK, "read"))
if (!floor_consume(OPRAYERBOOK, "read")) {
consume(OSCROLL, "read");
}
return; /* to read a scroll */
case 's':
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (object_identification[player_horizontal_position][player_vertical_position] == OTHRONE) {
fl_a_sit_on_throne(0);
} else if ((object_identification[player_horizontal_position][player_vertical_position] == OTHRONE2) ||
(object_identification[player_horizontal_position][player_vertical_position] == ODEADTHRONE)) {
fl_a_sit_on_throne(1);
} else {
fl_display_message("\nI see no throne to sit on here!");
}
return;
case 't': /* Tidy up at fountain */
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (object_identification[player_horizontal_position][player_vertical_position] == ODEADFOUNTAIN) {
fl_display_message("\nThere is no water to wash in!");
} else if (object_identification[player_horizontal_position][player_vertical_position] != OFOUNTAIN) {
fl_display_message("\nI see no fountain to wash at here!");
} else {
fl_a_wash_in_fountain();
}
return;
case 'v':
y_larn_rep = 0;
nomove = 1;
fl_termcap_cursor_position(1, 24);
lprintf("\nVersion: %s", FL_BUILD_VERSION);
lprintf("\n%s", FL_APACHE2_NOTICE);
if (wizard) {
fl_display_message(" Wizard");
}
if (cheat) {
fl_display_message(" Cheater");
}
return;
case 'w': /* wield a weapon */
y_larn_rep = 0;
wield();
return;
case 'A':
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (object_identification[player_horizontal_position][player_vertical_position] == OALTAR) {
fl_a_desecrate_an_altar();
} else {
fl_display_message("\nI see no altar to desecrate here!");
}
return;
case 'C': /* Close something */
y_larn_rep = 0;
fl_close_an_object();
return;
case 'D': /* Drink at fountain */
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (object_identification[player_horizontal_position][player_vertical_position] == ODEADFOUNTAIN) {
fl_display_message("\nThere is no water to drink!");
} else if (object_identification[player_horizontal_position][player_vertical_position] != OFOUNTAIN) {
fl_display_message("\nI see no fountain to drink from here!");
} else {
fl_a_drink_from_fountain();
}
return;
case '?':
y_larn_rep = 0;
display_help_text();
nomove = 1;
return; /*give the help screen*/
case 'E': /* Enter a building */
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
switch (object_identification[player_horizontal_position][player_vertical_position]) {
case OBANK:
banktitle(" Welcome to the First National Bank of Larn.");
break;
case OBANK2:
banktitle("Welcome to the 5th level branch office of "
"the First National Bank of Larn.");
/* because we state the level in the title, clear the '?' in the
level display at the bottom, if the user teleported.
*/
cdesc[FL_TELEPORT_FLAG] = 0;
break;
case ODNDSTORE:
Store.DNDStore();
break;
case OENTRANCE:
/* place player in front of entrance on level 1. fl_generate_a_new_dungeon_level()
prevents player from landing on a monster/object.
*/
player_horizontal_position = 33;
player_vertical_position = FL_MAX_VERTICAL_POSITION - 2;
fl_generate_a_new_dungeon_level(1);
been_here_before[33][FL_MAX_VERTICAL_POSITION - 1] = KNOWALL;
monster_identification[33][FL_MAX_VERTICAL_POSITION - 1] = 0;
draws(0, FL_MAX_HORIZONTAL_POSITION, 0, FL_MAX_VERTICAL_POSITION);
showcell(player_horizontal_position, player_vertical_position); /* to show around player */
bot_linex();
break;
case OTRADEPOST:
Store.TradingPost();
break;
case OLRS:
Store.TaxOffice();
break;
case OHOME:
fl_player_home();
break;
case FL_OBJECT_TEMPLE_IN:
fl_a_enter_the_temple();
break;
case FL_OBJECT_TEMPLE_OUT:
fl_a_exit_the_temple();
break;
default:
fl_display_message("\nThere is no place to enter here!\n");
break;
}
break;
case 'I': /* list spells and scrolls */
y_larn_rep = 0;
seemagic(0);
nomove = 1;
return;
case 'O': /* Open something */
y_larn_rep = 0;
fl_open_an_object();
return;
case 'P':
fl_termcap_cursor_position(1, 24);
y_larn_rep = 0;
nomove = 1;
if (outstanding_taxes > 0)
lprintf("\nYou presently owe %d gp in taxes.",
(int) outstanding_taxes);
else {
fl_display_message("\nYou do not owe any taxes.");
}
return;
case 'Q': /* quit */
y_larn_rep = 0;
fl_exit_the_game();
nomove = 1;
return;
case 'R': /* remove gems from a throne */
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (object_identification[player_horizontal_position][player_vertical_position] == ODEADTHRONE) {
fl_display_message("\nThere are no gems to remove!");
} else if (object_identification[player_horizontal_position][player_vertical_position] == OTHRONE) {
fl_a_remove_the_gems(0);
} else if (object_identification[player_horizontal_position][player_vertical_position] == OTHRONE2) {
fl_a_remove_the_gems(1);
} else {
fl_display_message("\nI see no throne here to remove gems from!");
}
return;
case 'S':
/*
Added the save stuff
It's much better now!
~Gibbon
*/
fl_termcap_cursor_position(1, 24);
fl_output_buffer_flush();
save_mode = 1;
save.savegame(savefilename);
fl_clear_terminal();
get_final_char_keyboard = ansiterm_getch;
exit(EXIT_SUCCESS);
break;
case 'T':
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (cdesc[FL_SHIELD] != -1) {
cdesc[FL_SHIELD] = -1;
fl_display_message("\nYour shield is off");
bottomline();
} else if (cdesc[FL_WEAR] != -1) {
cdesc[FL_WEAR] = -1;
fl_display_message("\nYour armor is off");
bottomline();
} else {
fl_display_message("\nYou aren't wearing anything");
}
return;
case 'W':
y_larn_rep = 0;
wear();
return; /* wear armor */
case 'Z':
y_larn_rep = 0;
if (cdesc[FL_LEVEL] > 9) {
fl_teleport(1);
return;
}
fl_termcap_cursor_position(1, 24);
fl_display_message
("\nAs yet, you don't have enough experience to use teleportation");
return; /* teleport yourself */
case ' ':
y_larn_rep = 0;
nomove = 1;
return;
case 'L' - 64:
y_larn_rep = 0;
drawscreen();
nomove = 1;
return; /* look */
case '<': /* Go up stairs or vol shaft */
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (object_identification[player_horizontal_position][player_vertical_position] == OSTAIRSDOWN) {
fl_display_message("\nThe stairs don't go up!");
} else if (object_identification[player_horizontal_position][player_vertical_position] != OSTAIRSUP) {
fl_display_message("\nI see no way to go up here!");
} else {
fl_a_travel_up_stairs();
}
return;
case '>': /* Go down stairs or vol shaft */
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
if (object_identification[player_horizontal_position][player_vertical_position] == OSTAIRSUP) {
fl_display_message("\nThe stairs don't go down!");
} else if (object_identification[player_horizontal_position][player_vertical_position] != OSTAIRSDOWN) {
fl_display_message("\nI see no way to go down here!");
} else {
fl_a_travel_down_stairs();
}
return;
case ',': /* pick up an object_identification */
y_larn_rep = 0;
/* pickup, don't identify or prompt for action */
fl_look_for_an_object_and_give_options(0, 1, 0);
return;
case ':': /* look at object */
y_larn_rep = 0;
/* identify, don't pick up or prompt for action */
fl_look_for_an_object_and_give_options(1, 0, 0);
nomove = 1; /* assumes look takes no time */
return;
case '/': /* identify object/monster */
fl_termcap_cursor_position(1, 24);
fl_display_message("\nIdentify unknown object by cursor [ynq]?");
for (;;) {
switch (ttgetch()) {
case '\33':
case 'q':
return;
case 'y':
case 'Y':
specify_obj_cursor();
return;
case 'n':
case 'N':
specify_obj_nocurs();
return;
}
}
nomove = 1;
y_larn_rep = 0;
return;
case '^': /* identify traps */
flag = y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
fl_output_single_byte_to_output_buffer('\n');
for (j = player_vertical_position - 1; j < player_vertical_position + 2; j++) {
if (j < 0) {
j = 0;
}
if (j >= FL_MAX_VERTICAL_POSITION) {
break;
}
for (i = player_horizontal_position - 1; i < player_horizontal_position + 2; i++) {
if (i < 0) {
i = 0;
}
if (i >= FL_MAX_HORIZONTAL_POSITION) {
break;
}
switch (object_identification[i][j]) {
case OTRAPDOOR:
case ODARTRAP:
case OTRAPARROW:
case OTELEPORTER:
case OPIT:
fl_display_message("\nIts ");
fl_display_message(objectname[object_identification[i][j]]);
flag++;
};
}
}
if (flag == 0) {
fl_display_message("\nNo traps are visible");
}
return;
if (FL_WIZARD_MODE_ENABLED == true) {
case '_': /* this is the fudge player password for wizard mode */
y_larn_rep = 0;
fl_termcap_cursor_position(1, 24);
nomove = 1;
wizard = 1; /* disable to easily test win condition */
get_final_char_keyboard = ansiterm_getch; /* system("stty -echo cbreak"); */
for (i = 0; i < 6; i++) {
cdesc[i] = 70;
}
iven[0] = iven[1] = 0;
/* give the ring a little boost. ~Gibbon */
take(OPROTRING, 51);
/* lets nerf it a little bit.
~Gibbon */
take(OGREATSWORD, 24);
cdesc[FL_WIELD] = 1;
cdesc[FL_GREAT_SWORD_OF_DEATH] = 1;
CoreFuncs.IncreaseExperience(6000000L);
cdesc[FL_AWARENESS] += 25000;
{
for (i = 0; i < FL_MAX_VERTICAL_POSITION; i++)
for (j = 0; j < FL_MAX_HORIZONTAL_POSITION; j++) {
been_here_before[j][i] = KNOWALL;
}
for (i = 0; i < FL_MAX_SPELLS_IN_GAME; i++) {
spelknow[i] = 1;
}
for (i = 0; i < MAXSCROLL; i++) {
scrollname[i][0] = ' ';
}
for (i = 0; i < MAXPOTION; i++) {
potionname[i][0] = ' ';
}
}
for (i = 0; i < MAXSCROLL; i++)
/* no null items */
if (strlen(scrollname[i]) > 2) {
object_identification[i][0] = OSCROLL;
object_argument[i][0] = i;
}
for (i = FL_MAX_HORIZONTAL_POSITION - 1; i > FL_MAX_HORIZONTAL_POSITION - 1 - MAXPOTION; i--)
/* no null items */
if (strlen(potionname[i - FL_MAX_HORIZONTAL_POSITION + MAXPOTION]) > 2) {
object_identification[i][0] = OPOTION;
object_argument[i][0] = i - FL_MAX_HORIZONTAL_POSITION + MAXPOTION;
}
for (i = 1; i < FL_MAX_VERTICAL_POSITION; i++) {
object_identification[0][i] = i;
object_argument[0][i] = 0;
}
for (i = FL_MAX_VERTICAL_POSITION; i < FL_MAX_VERTICAL_POSITION + FL_MAX_HORIZONTAL_POSITION; i++) {
object_identification[i - FL_MAX_VERTICAL_POSITION][FL_MAX_VERTICAL_POSITION - 1] = i;
object_argument[i - FL_MAX_VERTICAL_POSITION][FL_MAX_VERTICAL_POSITION - 1] = 0;
}
for (i = FL_MAX_HORIZONTAL_POSITION + FL_MAX_VERTICAL_POSITION; i < MAXOBJECT; i++) {
object_identification[FL_MAX_HORIZONTAL_POSITION - 1][i - FL_MAX_HORIZONTAL_POSITION - FL_MAX_VERTICAL_POSITION] = i;
object_argument[FL_MAX_HORIZONTAL_POSITION - 1][i - FL_MAX_HORIZONTAL_POSITION - FL_MAX_VERTICAL_POSITION] = 0;
}
cdesc[FL_GOLD] += 250000;
drawscreen();
return;
}
};
}
}
void
run(int dir)
{
int i;
i = 1;
while (i)
{
i = moveplayer(dir);
if (i > 0)
{
if (cdesc[FL_HASTEMONST])
{
fl_move_a_monster();
}
fl_move_a_monster();
random_monster_creation = 120 - (level << 2);
fl_regen_hp_and_spells();
}
if (hitflag)
{
i = 0;
}
if (i != 0)
{
showcell(player_horizontal_position, player_vertical_position);
}
gtime++;
}
}
void
parse2(void) {
FLHunger FLHunger;
/* move the monsters */
if (cdesc[FL_HASTEMONST]) {
fl_move_a_monster();
}
fl_move_a_monster();
if (cdesc[FL_TIMESTOP]) {
return;
}
if (--random_monster_creation <= 0) {
random_monster_creation = 120 - (level << 2);
fl_fill_dungeon_with_monsters(fl_create_monster(level));
}
fl_regen_hp_and_spells();
FLHunger.HungerLose();
}