-
Notifications
You must be signed in to change notification settings - Fork 10
/
act4.cpp
1825 lines (1710 loc) · 48 KB
/
act4.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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include <numeric>
#include "defs.h"
#include "funcs.h"
#include "dung.h"
#include "adv.h"
#include "parser.h"
#include "memq.h"
#include "zstring.h"
#include "util.h"
#include "act1.h"
#include "act3.h"
#include "act4.h"
#include "objfns.h"
std::vector<QuestionP> qvec;
int mdir = 270;
namespace
{
int pnumb = 1; // cell pointed at
int lcell = 1; // cell in slot
int nqatt = 0;
bool incant_ok = false;
int poleup = 0;
const char* wood_closes = "The pine wall closes quietly.";
std::array nqvecb = { QuestionP(), QuestionP(), QuestionP() };
Iterator<decltype(nqvecb)> nqvec(nqvecb);
std::string spell_flag;
}
namespace
{
const std::string_view mrestr(" E");
const std::string_view mrwstr("MBRW");
}
bool eg_infested(const RoomP &r)
{
auto &m = sfind_room("MRG");
_ASSERT(m);
return (r == m ||
(mloc == m && r == sfind_room("INMIR")) ||
r == sfind_room("MRGE") ||
r == sfind_room("MRGW"));
}
bool follow::operator()() const
{
const AdvP &win = *winner;
auto mastp = sfind_obj("MASTE")->oactor();
_ASSERT(mastp);
const AdvP &mast = *mastp;
const RoomP mroom = mast->aroom();
if (verbq("C-INT"))
{
if (here == mroom)
{
}
else if (here != sfind_room("CELL") && here != sfind_room("PCELL"))
{
if (memq(mast->aobj(), mroom->robjs()))
{
splice_out_in_place(mast->aobj(), mroom->robjs());
}
mast->aroom(here);
flags[FlagId::folflag] = true;
insert_object(mast->aobj(), here);
tell(memq(here, mroom->rexits()) ? "The dungeon master follows you." : "The dungeon master catches up to you.");
}
else if (flags[FlagId::folflag])
{
tell("You notice that the dungeon master does not follow.");
flags[FlagId::folflag] = false;
}
}
else if (win == mast)
{
clock_int(folin, -1);
tell("The dungeon master answers, 'I will follow.'");
}
else if (!is_empty(prsvec[1]))
{
if (ObjectP prso = ::prso(); trnn(prso, Bits::villain))
{
tell("The ", 1, prso->odesc2(), " eludes you.");
}
else
{
tell("I don't enjoy leading crazies through the dungeon.");
}
}
else
{
tell("Ok.");
}
return true;
}
const RoomP &go_e_w(const RoomP &rm, direction dir)
{
const std::string &spr = rm->rid();
std::string str = std::string((dir != direction::Ne && dir != direction::Se) ? mrwstr : mrestr);
return find_room(substruc(spr, 0, 3, str));
}
bool member(const std::string &s1, const std::vector<QuestionValue> &qv)
{
auto i = std::find_if(qv.begin(), qv.end(), [&s1](const QuestionValue &q)
{
const std::string_view *s;
return ((s = std::get_if<std::string_view>(&q)) && *s == s1);
});
return i != qv.end();
}
bool correct(Iterator<ParseContV> ans, const std::vector<QuestionValue> &correct)
{
const QuestionValue &onecorr = correct[0];
const auto &words = words_pobl;
const auto &actions = actions_pobl;
const ObjectPobl &object_obl = object_pobl();
while (1)
{
if (empty(ans))
break;
std::string a;
WordP w;
if (!(a = ans[0]->s1).empty() &&
(w = plookup(a, words)) &&
typeid(*w.get()) == typeid(buzz))
{
ans = rest(ans);
}
else
break;
}
bool rv = false;
if (std::holds_alternative<std::string_view>(onecorr))
{
return member(ans[0]->s1, correct);
}
else
{
Iterator<ParseContV> lv = ans;
AdjectiveP adj;
while (1)
{
ObjList o;
std::string str;
if ((str = lv[0]->s1).empty())
{
rv = false;
break;
}
if (ActionP act = plookup(str, actions))
{
const ActionP *qact = std::get_if<ActionP>(&onecorr);
return qact && *qact == act;
}
else if (WordP w = plookup(str, words))
{
adj = std::dynamic_pointer_cast<adjective>(w);
}
else if (!(o = plookup(str, object_obl)).empty())
{
ObjectP obj;
if (obj = search_list(str, inqobjs, adj).first)
{
const ObjectP *qo = std::get_if<ObjectP>(&onecorr);
return qo && *qo == obj;
}
}
lv = rest(lv);
}
}
return false;
}
bool answer::operator()() const
{
Iterator<ParseContV> lv = lexv;
auto m = member("", lv);
if (m && here == sfind_room("RIDDL") && !flags[FlagId::riddle_flag])
{
Iterator<ParseContV> nv;
if (nv = member("", rest(m)))
{
int len = length(nv);
if (len > 1 && !nv[1]->s1.empty())
{
parse_cont = rest(nv, 1);
}
}
if (correct(rest(m, 1), std::vector<QuestionValue>({ "WELL" })))
{
flags[FlagId::riddle_flag] = true;
tell("There is a clap of thunder and the east door opens.");
parse_cont.clear();
}
}
else if (m && flags[FlagId::end_game_flag] && here == sfind_room("FDOOR"))
{
inquisitor()(rest(m, 1));
}
else
{
tell("No one seems to be listening.");
}
return true;
}
bool enter_end_game()
{
const ObjectP &lamp = sfind_obj("LAMP");
const ObjectP &sword = sfind_obj("SWORD");
const AdvP &w = *winner;
clock_disable(egher);
tro(lamp, Bits::lightbit);
trz(lamp, Bits::onbit);
const OlintP &c = lamp->olint();
c->val(0);
c->ev()->ctick(350);
c->ev()->cflag(false);
sword_demon->haction(sword_glow());
robber_demon->haction(nullptr);
// Disable all active events in the adventurer's possession.
for (const ObjectP& o : w->aobjs())
{
if (o->olint())
clock_disable(o->olint()->ev());
}
tro(lamp, Bits::touchbit);
tro(sword, Bits::touchbit);
lamp->oroom(nullptr).ocan(nullptr);
sword->oroom(nullptr).ocan(nullptr);
//w->aobjs().swap(ObjList{ lamp, sword });
w->aobjs() = { lamp, sword };
flags[FlagId::end_game_flag] = true;
score_room(sfind_room("CRYPT"));
goto_(sfind_room("TSTRS"));
room_desc()();
return true;
}
ObjectP beam_stopped()
{
const ObjectP &beam = sfind_obj("BEAM");
auto &rp = sfind_room("MREYE");
for (auto& o : rp->robjs())
{
if (o != beam)
return o;
}
return ObjectP();
}
ObjList movies(const RoomP &rm)
{
ObjList list;
const ObjList &co = cobjs;
for (const ObjectP &o : rm->robjs())
{
if (!memq(o, co))
{
list.push_back(o);
}
}
return list;
}
void stuff(const RoomP &r, const ObjList &l1, const ObjList &l2)
{
// Combines l1 and l2 into r->robjs.
r->robjs() = l1;
r->robjs().insert(r->robjs().end(), l2.begin(), l2.end());
for (const ObjectP &o : r->robjs())
{
o->oroom(r);
}
}
void cell_move()
{
int new_ = pnumb;
int old = lcell;
const ObjectP &d = sfind_obj("ODOOR");
const AdvP &me = player();
dclose(sfind_obj("CDOOR"));
dclose(d);
if (new_ != old)
{
const RoomP& cell = sfind_room("CELL");
const RoomP& ncell = sfind_room("NCELL");
const RoomP& pcell = sfind_room("PCELL");
const ObjList &po = cells[old-1] = movies(cell);
stuff(cell, cells[new_ - 1], cobjs);
cells[new_-1].clear();
if (old == 4)
{
stuff(ncell, po, nobjs);
}
else
{
stuff(pcell, po, pobjs);
}
if (new_ == 4)
tro(d, Bits::ovison);
else
trz(d, Bits::ovison);
if (me->aroom() == cell)
{
goto_(old == 4 ? (tro(d, Bits::ovison), ncell) : pcell, me);
}
lcell = new_;
}
}
std::string_view dpr(const ObjectP &obj)
{
return trnn(obj, Bits::openbit) ? "open."sv : "closed."sv;
}
namespace
{
std::array swu = { 0, 0, 0, 0, 0 };
std::array kwu = { 0, 0, 0, 0, 0 };
std::string str(" ");
}
std::string pw(SIterator unm, SIterator key)
{
auto su = Iterator(swu);
auto ku = Iterator(kwu);
SIterator str = ::str;
int usum;
auto fn = [&](SIterator s, Iterator<decltype(swu)> su, SIterator k, Iterator<decltype(kwu)> ku) -> bool
{
while (1)
{
if (empty(su))
return true;
if (empty(k))
k = key;
if (empty(s))
s = unm;
su[0] = s[0] - 64;
ku[0] = k[0] - 64;
k = rest(k);
s = rest(s);
su = rest(su);
ku = rest(ku);
}
return true;
};
fn(unm, su, key, ku);
// usum is the sum of all items in su % 8 + 8 * (sum of all items in ku % 8)
usum = (std::accumulate(su.begin(), su.end(), 0) % 8) +
(std::accumulate(ku.begin(), ku.end(), 0) * 8) * 8;
std::fill(str.begin(), str.end(), 0);
auto fn2 = [&usum](Iterator<decltype(swu)> su, Iterator<decltype(kwu)> ku, SIterator str)
{
_ASSERT(su.size() == ku.size());
_ASSERT(su.size() == str.size());
for (; !empty(su); su = rest(su), ku = rest(ku), str = rest(str))
{
int s = su[0], k = ku[0];
s = ((s ^ k) ^ usum) & 31;
usum = (usum + 1) % 32;
if (s > 26)
s = s % 26;
if (s == 0)
s = 1;
str[0] = (char)(s + 64);
}
};
fn2(su, ku, str);
return str;
}
bool incantation(Iterator<ParseContV> lv)
{
std::string w1, w2;
std::string unm = username();
if (!spell_flag.empty() || rtrnn(sfind_room("MRANT"), RoomBit::rseenbit))
{
tell("Incantations are useless once you have gotten this far.");
}
else if (length(lv) < 2 || (w1 = lv[0]->s1).empty())
{
tell("That incantation seems to have been a failure.");
}
else if ((w2 = lv[1]->s1).empty())
{
if (!spell_flag.empty() && w1 != spell_flag)
{
tell("Sorry, only one incantation to a customer.");
}
else if (incant_ok && flags[FlagId::end_game_flag])
{
w2 = pw(SIterator(unm), SIterator(w1));
tell("A hollow voice replies: \"", 0, w1, " ");
tell(w2, 1, "\".");
spell_flag.swap(w1);
}
else
{
tell("That spell has no obvious effect.");
}
}
else if (w1 == pw(SIterator(unm), SIterator(w2)) ||
w2 == pw(SIterator(unm), SIterator(w1)))
{
tell("As the last syllable of your spell fades into silence, darkness\n"
"envelops you, and the earth shakes briefly. Then all is quiet.");
spell_flag.swap(w1);
enter_end_game();
}
else
tell("That spell doesn't appear to have done anything useful.");
return true;
}
bool incant::operator()() const
{
auto m = member("", lexv);
if (m)
{
incantation(rest(m, 1));
}
return true;
}
void select(std::vector<QuestionP> from, Iterator<std::array<QuestionP, 3>> to)
{
// This is only used in one place, and is used to
// fill to with random elements from "from". It uses
// the username and some other things to do the
// selection. To make it simpler, this just copies
// the from list to the to list, does a shuffle, and
// returns the required number of elements.
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(from.begin(), from.end(), g);
std::copy(from.begin(), from.begin() + to.size(), to.begin());
}
bool inqstart()
{
const auto &qv = qvec;
auto &nqv = nqvec;
if (!flags[FlagId::inqstartflag])
{
clock_enable(clock_int(inqin, 2));
tell(quiz_rules, long_tell1);
flags[FlagId::inqstartflag] = true;
select(qv, nqv);
tell("The booming voice asks:\n'", 1, nqv[0]->qstr(), "'");
}
else
{
tell("The dungeon master gazes at you impatiently, and says, 'My conditions\n"
"have been stated, abide by them or depart!'");
}
return true;
}
bool inquisitor::operator()(Iterator<ParseContV> ans) const
{
Iterator<std::array<QuestionP, 3>> nqv = nqvec;
const QuestionP &ques = nqv[0];
if (verbq("C-INT"))
{
tell("The booming voice asks:\n'", 1, ques->qstr(), "'");
clock_int(inqin, 2);
}
else if(ans && flags[FlagId::inqstartflag] && nqatt < 5)
{
if (correct(ans, ques->qans()))
{
tell("The dungeon master says 'Excellent.'");
if (empty(nqv = rest(nqv)))
{
tell(quiz_win, long_tell1);
dopen(sfind_obj("QDOOR"));
clock_disable(inqin);
}
else
{
nqatt = 0;
nqvec = nqv;
tell("The booming voice asks:\n'", 1, nqv[0]->qstr(), "'");
clock_int(inqin, 2);
}
}
else
{
tell("The dungeon master says 'You are wrong.", 0);
if (++nqatt == 5)
{
tell(inq_lose, long_tell1);
clock_disable(inqin);
}
else
{
tell(" You have ", 1, nums[5 - nqatt - 1], " more chance", nqatt == 4 ? ".'" : "s.'");
}
}
}
else
{
tell("There is no reply.");
}
return true;
}
bool n_s(int dir)
{
return dir % 180 == 0;
}
std::optional<int> mirror_dir(direction dir, const RoomP &rm)
{
auto mex = memq(direction::North, rm->rexits());
const CExitPtr *m = nullptr;
if (mex)
{
if (!(m = std::get_if<CExitPtr>(&std::get<1>(**mex))))
return std::optional<int>();
}
if (m && mloc == (*m)->cxroom())
{
if ((dir == direction::North && mdir > 180 && mdir < 360) ||
dir == direction::South && mdir > 0 && mdir < 180)
{
return 1;
}
else
return 2;
}
return std::optional<int>();
}
bool look_to(std::string_view nstr,
std::string_view sstr,
LookToVal ntell,
LookToVal stell,
bool htell)
{
bool mir;
bool m1 = false;
std::string_view dir;
RoomP nrm(nstr.empty() ? nullptr : find_room(nstr));
RoomP srm(sstr.empty() ? nullptr : find_room(sstr));
if (htell)
tell(hallway, long_tell1);
auto tell_fn = [](std::string_view prefix, LookToVal lv)
{
std::visit(overload{
[prefix](bool b) { if (b) tell(prefix, long_tell1, guardstr); },
[](const char* s) { tell(s); },
[](auto unused) {}
}, lv);
};
tell_fn("Somewhat to the north", ntell);
tell_fn("Somewhat to the south", stell);
bool north = false;
auto prog = [&]() ->bool
{
bool rv = true;
if (mloc == nrm)
{
ntell = north = true;
dir = "north";
}
else if (mloc == srm)
{
north = false;
stell = true;
dir = "south";
}
else
rv = false;
return rv;
};
if (prog())
{
mir = (((north && mdir > 180 && mdir < 359) || (!north && mdir > 0 && mdir < 179)) && (m1 = true)) ? flags[FlagId::mr1] : flags[FlagId::mr2];
if (n_s(mdir))
{
tell("The ", 0, dir, " side of the room is divided by a wooden wall into small\nhallways to the ");
tell(dir, 0, "east and ");
tell(dir, 1, "west.");
}
else
{
tell(mir ? "A large mirror fills the " : "A large panel filles the ", 1, dir, " side of the hallyway.");
m1 && flags[FlagId::mirror_open] && tell(mir ? miropen : panopen, long_tell1);
mir || tell("The shattered pieces of a mirror cover the floor.");
}
}
if (htell)
{
bool nm = is_empty(ntell);
bool sm = is_empty(stell);
if (nm && sm)
{
tell("The corridor continues north and south."sv);
}
else if (nm)
{
tell("The corridor continues north."sv);
}
else if (sm)
{
tell("The corridor continues south."sv);
}
}
return true;
}
RoomP mirew()
{
std::string new_rm = std::string(mdir == 0 ? mrwstr : mrestr);
new_rm.replace(0, 3, mloc->rid());
return find_room(new_rm);
}
bool mirmove(bool northq, const RoomP &rm)
{
using namespace std::string_view_literals;
const RoomP &mrg = sfind_room("MRG");
bool pu = poleup != 0;
tell(pu ? "The structure wobbles " : "The structure slides ", 1, northq ? "north" : "south", " and stops over another compass rose.");
mloc = rm;
if (rm == mrg &&
here == sfind_room("INMIR"))
{
bool dead = true;
if (pu)
tell("The structure wobbles as it moves, alerting the Guardians.");
else if (!flags[FlagId::mr1] || !flags[FlagId::mr2])
{
tell("A Guardian notices a wooden structure creeping by, and his\n"
"suspicions are aroused.");
}
else if (flags[FlagId::mirror_open] || flags[FlagId::wood_open])
{
tell("A Guardian notices the open side of the structure, and his suspicions\n"
"are aroused.");
}
else
dead = false;
if (dead)
jigs_up(guardkill1);
}
return true;
}
RoomP mirns(bool northq, bool exitq)
{
RoomP rv;
const RoomP &mloc = ::mloc;
const std::vector<Ex> &rex = mloc->rexits();
if (!exitq &&
((northq && mloc == northend) || (!northq && mloc == southend)))
{
// Do nothing
}
else if (auto m = memq(northq ? direction::North : direction::South, rex))
{
ExitType exit = std::get<1>(**m);
rv = std::visit(overload{
[](const CExitPtr& ep) { return ep->cxroom(); },
[](const RoomP& rp) { return rp; },
[](const std::string& s) { return sfind_room(s); },
[](auto p) { return RoomP(); }
}, exit);
}
return rv;
}
bool mirblock(direction dir, int mdir)
{
if (dir == direction::South)
{
mdir = (mdir + 180) % 360;
}
const char *msg = (mdir == 270 && !flags[FlagId::mr1]) || (mdir == 90 && !flags[FlagId::mr2]) ?
"There is a large broken mirror blocking your way." :
"There is a large mirror blocking your way.";
return tell(msg);
}
std::optional<int> mirror_here(RoomP rm)
{
std::optional<int> rv;
const std::string &sp = rm->rid();
int mdir = ::mdir;
if (sp.size() == 4)
{
if (mdir + (sp[3] == 'E' ? 0 : 180) == 180)
rv = 1;
else
rv = 2;
}
else if (n_s(mdir))
{
// Returns empty
}
else if (rv = mirror_dir(direction::North, rm))
{
}
else
rv = mirror_dir(direction::South, rm);
return rv;
}
bool start_end::operator()() const
{
bool rv = false;
RoomP here = ::here;
if (here == sfind_room("CRYPT"))
{
rv = true;
if (lit(here))
{
clock_int(strte, 3);
}
else
{
tell(pass_word_inst, long_tell1);
incant_ok = true;
enter_end_game();
}
}
return rv;
}
bool stats::operator()() const
{
tell("Room count: ", post_crlf, rooms().size());
tell("Object count: ", post_crlf, object_pobl().size());
tell("Max score: ", post_crlf, score_max(), ", endgame max score ", eg_score_max);
tell("Verbs: ", post_crlf, actions_pobl.size());
return true;
}
bool stay::operator()() const
{
bool rv = true;
if (winner == sfind_obj("MASTE")->oactor())
{
clock_int(folin, 0);
tell("The dungeon master says, 'I will stay.'"sv);
}
else if (*winner == player())
{
tell("You will be lost without me."sv);
}
else
rv = false;
return rv;
}
bool turnto::operator()() const
{
return object_action() ? true : tell("That cannot be turned.");
}
namespace obj_funcs
{
bool locked_door::operator()() const
{
bool rv = false;
if (verbq("OPEN"))
{
rv = tell("The door is securely fastened.");
}
return rv;
}
bool take_five::operator()() const
{
if (verbq("TAKE"))
{
return perform(wait_(), find_verb("WAIT"));
}
return false;
}
bool panel_function::operator()() const
{
bool rv = true;
std::optional<int> mirror = mirror_here(here);
if (!mirror.has_value())
{
tell("I can't see a panel here."sv);
}
else if (verbq("OPEN", "MOVE" ))
{
tell("I don't see a way to open the panel here."sv);
}
else if (verbq( "POKE", "MUNG" ))
{
if (mirror == 1)
{
if (flags[FlagId::mr1])
{
tell(panelbreak, long_tell1);
}
else
{
tell(panelbroke, long_tell1);
}
}
else if (flags[FlagId::mr2])
{
tell(panelbreak, long_tell1);
}
else
{
tell(panelbroke, long_tell1);
}
}
else if (verbq("PUSH"))
{
if (mirror == 1)
{
tell("The wooden panel moves slightly inward as you push, and back out\n"
"when you let go."sv);
}
else
{
tell("The panel is unyielding."sv);
}
}
else
rv = false;
return rv;
}
bool beam_function::operator()() const
{
ObjectP prso = ::prso();
ObjectP prsi = ::prsi();
const ObjectP &beam = sfind_obj("BEAM");
bool rv = true;
if (verbq( "PUT", "POKE", "MUNG" ))
{
if (verbq("PUT"))
{
std::swap(prsi, prso);
}
if (!prsi || prso != beam)
return false;
if (drop_if(prsi))
{
insert_object(prsi, here);
tell("The beam is now interrupted by a ", 1, prsi->odesc2(), " lying on the floor.");
}
else if (memq(prsi, here->robjs()))
{
tell("The ", 1, prsi->odesc2(), " already breaks the beam.");
}
else
{
tell("You can't break the beam with a ", 1, prsi->odesc2(), ".");
}
}
else if (verbq("TAKE") && beam == prso)
{
tell("No doubt you have a bottle of moonbeams as well.");
}
else
rv = false;
return rv;
}
bool crypt_object::operator()() const
{
bool rv = false;
bool eg = flags[FlagId::end_game_flag];
const ObjectP &c = sfind_obj("TOMB");
if (!eg && (rv = obj_funcs::head_function()()))
{
}
else if (eg && verbq("OPEN"))
{
rv = true;
if (!trnn(c, Bits::openbit))
{
dopen(c);
tell("The door of the crypt is extremely heavy, but it opens easily.");
}
else
{
tell("The crypt is already open.");
}
}
else if (eg && verbq("CLOSE"))
{
rv = true;
if (trnn(c, Bits::openbit))
{
dclose(c);
tell("The crypt is closed.");
}
else
{
tell("The crypt is already closed.");
}
if (here == sfind_room("CRYPT"))
{
clock_int(strte, 3);
}
}
return rv;
}
bool bronze_door::operator()() const
{
bool rv = false;
RoomP here = ::here;
bool ncell = here == sfind_room("NCELL");
if (verbq( "OPEN", "CLOSE" ))
{
rv = true;
if (ncell || lcell == 4 && (here == sfind_room("CELL") || here == sfind_room("SCORR")))
{
open_close(sfind_obj("ODOOR"), "The bronze door opens.", "The bronze door closes.");
if (ncell && verbq("OPEN"))
{
tell("On the other side of the door is a narrow passage which opens out\n"
"into a larger area.");
}
}
else
{
tell("I see no bronze door here.");
}
}
return rv;
}
bool dialbutton::operator()() const
{
bool rv = false;
bool cdoor = trnn(sfind_obj("CDOOR"), Bits::openbit);
if (verbq("PUSH"))
{
rv = true;
cell_move();
tell("The button depresses with a slight click, and pops back.");
cdoor && tell("The cell door is now closed.");
}
return rv;
}
bool dial::operator()() const
{
bool rv = true;
if (verbq( "SET", "PUT", "MOVE", "TRNTO" ))
{
if (ObjectP prsio = prsi(); !empty(prsio))
{
auto n = memq(prsio, numobjs);
if (n)
{
pnumb = (*n)->second;