-
Notifications
You must be signed in to change notification settings - Fork 0
/
FloppyDisk.cpp
2880 lines (2708 loc) · 99.6 KB
/
FloppyDisk.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 <ctype.h>
#include <stddef.h>
#include "Global.h"
#include "AttackType.h"
#include "Util.h"
#include "Object.h"
#include "Hero.h"
#include "FloppyDisk.h"
static shCompInterface
checkInterface (shObject *computer)
{
switch (computer->mIlkId) {
case kObjMiniComputer: return kIVisualVoice;
case kObjMegaComputer: return kIVisualVoice;
case kObjSatCom: return kIVisualOnly;
case kObjBioComputer: return kIUniversal;
default: return kNotAComputer;
}
}
static void
confusedComputingMessage (void)
{
if (Hero.isBlind ())
if (Hero.isMute ())
I->p ("You misexpress some of the commands in your confusion.");
else
I->p ("You mispronounce some of the commands in your confusion.");
else
I->p ("You make a few typos in your confusion.");
}
/* Checks whether hero can read map or object/monster locations printed
on screen. Alternatively nerve interface can be employed in which
case the image forms directly in the hero's brain.
returns:
0: hero cannot get displayed information with specified interface
1: hero managed to receive the information
*/
static int
visualDisplaySuccesful (shCompInterface interface) {
if (!Hero.isBlind ()) {
return 1; /* Silent, this is normal situation. */
} else if (interface != kIUniversal) {
I->p ("But you can't see the display!");
return 0;
} else {
I->p ("You receive information through your bio computer's hypodermic nerve interface.");
return 1;
}
}
static void
criticalError (shObject *disk)
{
I->p ("Critical error %d. Execution halted.", RNG (1, 500));
disk->setInfectedKnown ();
}
/* All that universally influences programming gets put here.
If knownOnly is true only modifiers known to the hero are counted.
*/
static int
hackingMods (shObject *computer, bool estimate)
{ /* Hacker's ninja skillz. */
int sk = Hero.getSkillModifier (kHacking);
/* Drunk coding is never good. */
int conf = Hero.is (kConfused) ? -5 : 0;
/* TODO: move this to general kHacking boost. */
/* It is said that programmers convert coffee to programs. :-) */
int coffee = Hero.getTimeOut (CAFFEINE) ? +2 : 0;
int os = 0, virus = 0;
/* Bonus from tools bundled with OS. */
if (!estimate or computer->isEnhancementKnown ())
os = computer->hackingModifier ();
/* Infected computer devotes some resources to resident virus. */
if (!estimate or computer->isInfectedKnown ())
virus = computer->isInfected () ? -2 : 0;
return sk + conf + coffee + os + virus;
}
int /* Not static, matter compiler also uses it. */
hackingRoll (shObject *computer)
{
return RNG (1, 20) + hackingMods (computer, false);
}
static int
programDifficulty (shObjId id, shObject *comp, shObject *disk, bool estimate)
{
if (id == kObjCorruptDisk) return 100;
shObjectIlk *ilk = &AllIlks[id];
int score = hackingMods (comp, estimate);
int req = 15 + ilk->mCost / 20;
if (!estimate or disk->isBugginessKnown ()) {
if (disk->isOptimized ()) {
score += 2;
} else if (disk->isBuggy ()) {
score -= 4;
}
}
if (ilk->mFlags & kIdentified) {
score += 4;
} else if (SoftwareEngineer != Hero.mProfession) {
score -= 4;
}
int chance = (score - req + 20) * 5;
if (chance < 0) chance = 0;
if (chance > 100) chance = 100;
if (id == kObjMatterCompiler) chance /= 2; /* Very hard to write. */
return chance;
}
/* Attempt to write a new program on a blank floppy disk. */
static shExecResult
doBlank (shObject *computer, shObject *disk)
{
const char *prompt = "What program do you want to write on it?";
char *buf = GetBuf ();
if (!disk->isKnown ()) {
disk->setKnown ();
I->p ("This disk is blank!");
I->pause ();
}
shObjId progid = kObjNothing; /* Chosen program type. */
/* You don't get to pick a program. */
if (Hero.is (kConfused)) {
I->p ("You type random things.");
if (RNG (2)) {
int confilk;
do {
confilk = RNG (kObjFirstFloppyDisk + 1, kObjLastFloppyDisk);
} while (confilk == kObjBlankDisk or confilk == kObjCorruptDisk);
progid = shObjId (confilk);
} else {
progid = kObjCorruptDisk;
}
} else { /* Present some choice to player. */
shMenu *program = I->newMenu (prompt, 0);
program->attachHelp ("programming.txt");
program->addHeader (" Name Chance");
char let = 'a';
for (int i = kObjFirstFloppyDisk; i <= kObjLastFloppyDisk; ++i) {
shObjectIlk *ilk = &AllIlks[i];
if (ilk->isAbstract ()) continue;
if (!(ilk->mFlags & kIdentified) and
Hero.mProfession != SoftwareEngineer)
continue;
const char *strptr = strstr (ilk->mReal.mName, " of ");
if (strptr) {
strptr += 4; /* Skip " of " and go right to program name. */
int dc = programDifficulty (shObjId (i), computer, disk, true);
sprintf (buf, "%-20s %3d%%", strptr, dc);
program->addIntItem (let++, buf, i);
if (let == 'z' + 1) let = 'A';
}
}
program->addIntItem (let, "other (specify)", -1);
int res;
if (!program->getIntResult (&res)) {
return kNoExpiry; /* Cancelling writing a blank disk is free. */
}
progid = shObjId (res);
}
int chance = -1; /* Undetermined yet. */
if (progid == -1) { /* Manually specify program name. */
extern shObjId consumeIlk (const char *);
char *buf2 = GetBuf ();
I->getStr (buf, SHBUFLEN, prompt);
/* Already good? */
progid = consumeIlk (buf2);
if (!progid) {
snprintf (buf2, SHBUFLEN, "floppy disk of %s", buf);
progid = consumeIlk (buf2);
}
if (!progid) {
snprintf (buf2, SHBUFLEN, "%s floppy disk", buf);
progid = consumeIlk (buf2);
}
if (progid == kObjNothing) {
I->p ("There is no such program!");
if (RNG (4)) {
return kNoExpiry;
} else { /* Prevent abuse by guessing. Players should either
get spoiled or be unable to bore themselves. */
return kDestruct;
}
} else if (progid == kObjCorruptDisk) {
I->p ("You happily mash the keyboard. Success!");
chance = 100;
} else if (progid == kObjBlankDisk) {
I->p ("Don't be ridiculous!");
return kNoExpiry;
}
}
if (chance == -1) /* Check hero's skill. */
chance = programDifficulty (progid, computer, disk, false);
if (RNG (100) < chance) { /* Hurrah! */
disk = Hero.removeOneObjectFromInventory (disk);
disk->mIlkId = progid;
if (!disk->isIlkKnown ()) /* Writing new programs. */
Hero.earnXP (Hero.mCLevel + (Hero.mProfession == SoftwareEngineer));
disk->setIlkKnown (); /* You just wrote it. */
disk->myIlk ()->mFlags |= kIdentified;
if (computer->isInfectedKnown ()) disk->setInfectedKnown ();
} else {
I->p ("Your hacking attempt was a failure.");
switch (RNG (20)) { /* Slim chance for not blowing up the disk. */
case 0:
disk = Hero.removeOneObjectFromInventory (disk);
disk->mIlkId = kObjCorruptDisk;
break;
case 1:
if (!disk->isBuggy ()) {
disk = Hero.removeOneObjectFromInventory (disk);
disk->setBuggy ();
break;
}
default:
return kDestruct;
}
}
/* Deliver to inventory. */
if (!Hero.addObjectToInventory (disk)) {
I->p ("The disk slips from your hands!"); /* FIXME: Xel'Naga */
Level->putObject (disk, Hero.mX, Hero.mY);
}
/* This applies regardless whether you succeed or not. */
if (progid == kObjOperatingSystem and !Hero.is (kConfused)) {
I->p ("That was a very exhausting task.");
Hero.sufferDamage (kAttHypnoDiskO);
}
return kNoExpiry;
}
void
identifyObjects (int howmany, int infected)
{
shObject *obj;
int didsomething = 0;
const char *prompt = "What do you want to identify?";
while (howmany) {
/* If 'howmany' is negative the identifying effect is unlimited. */
shMenu *idmenu = I->newMenu (prompt, shMenu::kCategorizeObjects |
(howmany < 0 ? shMenu::kMultiPick : 0));
shObjectVector v;
/* Infected disks reveal appearance. It is useful only for
zen games but still something to keep in mind. */
if (!infected) {
unselectObjectsByFunction (&v, Hero.mInventory,
&shObject::isIdentified);
} else {
unselectObjectsByFunction (&v, Hero.mInventory,
&shObject::isAppearanceKnown);
}
if (0 == v.count ()) {
I->p ("You have %s unidentified items.",
didsomething ? "no more" : "no");
break;
}
if (didsomething) {
I->pause ();
}
didsomething = 0;
for (int i = 0; i < v.count (); ++i) {
obj = v.get (i);
idmenu->addPtrItem (obj->mLetter, obj->inv (), obj, obj->mCount);
}
while (idmenu->getPtrResult ((const void **) &obj)) {
++didsomething;
--howmany;
if (!infected) {
obj->identify ();
} else {
obj->setAppearanceKnown ();
}
obj->announce ();
}
if (didsomething and howmany > 0) {
prompt = "What do you want to identify next?";
} else { /* Player wants to leave some things unidentified. */
break;
}
delete idmenu;
}
if (didsomething) Hero.reorganizeInventory ();
}
static shExecResult
doIdentify (shObject *computer, shObject *disk)
{
int howmany = disk->isOptimized () ? RNG (1, 5) : 1;
if (disk->isCracked () and disk->isCrackedKnown ())
howmany = -1;
if (!disk->isKnown ()) {
disk->setKnown ();
I->p ("This is an identify program.");
I->pause ();
}
identifyObjects (howmany, disk->isInfected ());
if (howmany > 1) disk->setBugginessKnown ();
return kNormal;
}
static shExecResult
doSpam (shObject *computer, shObject *disk)
{
disk->setKnown ();
/* Clerkbots on the level get to advertise their wares to you. */
if (Level->mFlags & shMapLevel::kHasShop and !disk->isBuggy ()) {
int ads = 0;
for (int i = 0; i < Level->mCrList.count (); ++i) {
shCreature *c = Level->mCrList.get (i);
if (c->isA (kMonClerkbot) and !c->isHostile () and c->isInShop ()) {
shMenu *list = I->newMenu ("For sale:", shMenu::kNoPick);
int stock = 0;
int sx = 0, sy = 0, ex = -1, ey = -1;
int room = Level->getRoomID (c->mX, c->mY);
Level->getRoomDimensions (room, &sx, &sy, &ex, &ey);
/* Reveal shop location. */
for (int x = sx; x <= ex; ++x)
for (int y = sy; y <= ey; ++y) {
if (disk->isInfected () and !RNG (3)) continue;
shSquare *s = Level->getSquare (x, y);
/* Show only the clerkbot. */
shCreature *dc = (x == c->mX and y == c->mY) ? c : NULL;
shObjectVector *v = Level->getObjects (x, y);
shObject *best = NULL;
if (v) {
for (int i = 0; i < v->count (); ++i) {
if (disk->isInfected () and !RNG (3)) continue;
shObject *obj = v->get(i);
if (obj->isUnpaid ()) {
best = obj;
obj->setAppearanceKnown ();
++stock;
list->addPtrItem (' ', obj->inv (), obj);
}
}
}
if (best) Level->remember (x, y, best->mIlkId);
Level->remember (x, y, s->mTerr);
I->draw (x, y, kNone, dc, NULL, best, NULL, s);
}
I->p ("Come visit %s!", Level->shopAd (room));
I->cursorAt (c->mX, c->mY);
if (stock and I->yn ("See items for sale?"))
list->finish ();
++ads;
}
}
if (ads) return kNormal;
}
static const char *spammsg [] = {
"Warning! Your warpspace connection is not optimized!",
"Make thousands of buckazoids per cycle from the comfort of your own pod!",
"Beautiful Arcturian babes are waiting to meet you!"
};
static const char *spamprompt [] = {
"Transmit %d buckazoids to Meta-Net Systems for an upgrade?",
"Upload $%d to Hyperpyramid Industries to buy business plan?",
"Beam over your Arcturian bride for only %d buckazoids?"
};
static const char *charitymsg [] = {
"Help feed starving %s babies from %s!",
"Please provide for the needs of elderly %s citizens of %s!",
"Aid poor %s patients at %s Planetary Clinic!"
};
static const char *charityprompt [] = {
"Donate %d buckazoids to %s %s Nursery?",
"Give $%d to %s Non-profit House of Serene Elder Life of %s?",
"Send %d buckazoids to %s Planetary Clinic?"
};
bool charity;
const char **message, **prompt;
if (disk->isBuggy () or (disk->isDebugged () and RNG (2))) {
charity = false;
message = spammsg;
prompt = spamprompt;
} else {
charity = true;
message = charitymsg;
prompt = charityprompt;
}
int idx = RNG (3);
int price = RNG (500) + 500;
int sucker = 0;
if (price > Hero.countMoney ()) {
price = Hero.countMoney ();
}
const char *randomWorld ();
const char *randomRace ();
const char *world = randomWorld (), *race = randomRace ();
I->p (message[idx], race, world);
if (price < 50) {
I->p ("Run this disk again when you've got some more buckazoids.");
return kNoExpiry;
}
if (disk->isBuggy ()) {
I->p ("Transmitting %d buckazoids through Zero-Click purchase plan...",
price);
disk->setBugginessKnown ();
sucker = 1;
} else {
int newidx = idx;
/* Give clue this disk is infected. */
if (disk->isInfected ()) {
/* Message and money receiver will not match. */
while (newidx == idx)
newidx = RNG (3);
}
if (I->yn (prompt[newidx], price, world, race)) {
sucker = 1;
} else {
disk->setKnown ();
}
}
if (sucker) {
Hero.loseMoney (price);
if (!charity) {
I->p ("Thank you for your order. "
"Please wait 4-6 orbit cycles for delivery.");
} else {
I->p ("Thank you for your most generous donation.");
}
} else if (!charity) {
I->p ("Perhaps you might be interested in some of our other products?");
}
return kNoExpiry;
}
static shExecResult
doCorrupt (shObject *computer, shObject *disk)
{
disk->setKnown ();
criticalError (disk);
return kNoExpiry;
}
static shExecResult
doHypnosis (shObject *computer, shObject *disk)
{
disk->setKnown ();
if (Hero.isBlind ()) {
I->p ("You listen to some %s trance music.",
disk->isInfected () ? "pitiful" : "excellent");
/* No revealing infectedness. This subtle change is easy to miss. */
} else {
I->p ("%s displays a %shypnotic screensaver!",
YOUR (computer), disk->isInfected () ? "sickening, " : "");
disk->setInfectedKnown ();
}
shAttackId aid = disk->isInfected () ? kAttHypnoDiskD : kAttSickHypnoDiskD;
Level->areaEffect (&Attacks[aid + disk->mBugginess],
NULL, Hero.mX, Hero.mY, kNoDirection, &Hero, 0, 0);
return kNormal;
}
/* Detection programs have realtively minor punishment for having
the disk infected. 1/3 chances for not reporting found item. */
static shExecResult
doDetectObject (shObject *computer, shObject *disk)
{
shCompInterface interface = checkInterface (computer);
disk->setKnown ();
I->p ("You scan the area for objects.");
int display = visualDisplaySuccesful (interface);
int stack = 0;
int objs = 0;
int constr = 0;
if (!display) I->p ("Getting objects list will have to suffice.");
if (!Hero.is (kConfused)) {
for (int y = 0; y < MAPMAXROWS; ++y) {
for (int x = 0; x < MAPMAXCOLUMNS; ++x) {
shObjectVector *v = Level->getObjects (x, y);
if (v) {
Level->forgetObject (x, y);
}
if (v and (!disk->isInfected () or RNG (3))) {
int besttype = kMaxObjectType;
shObject *bestobj = NULL;
for (int i = 0; i < v->count (); ++i) {
shObject *obj = v->get (i);
objs += obj->mCount;
if (disk->isOptimized ()) obj->setAppearanceKnown ();
if (obj->apparent ()->mType < besttype) {
besttype = v->get (i) -> apparent () -> mType;
bestobj = v->get (i);
}
}
++stack;
if (display) {
Level->remember (x, y, bestobj->mIlkId);
Level->drawSq (x, y);
}
}
shCreature *c = Level->getCreature (x, y);
if (c and (!disk->isInfected () or RNG (3))
and c->myIlk ()->mType == kConstruct)
{
++constr;
if (display) {
Level->remember (x, y, c->mIlkId);
Level->drawSq (x, y);
}
}
}
}
if (!disk->isBuggy ()) {
for (int i = 0; i < Hero.mInventory->count (); ++i)
if (!disk->isInfected () or RNG (3)) {
shObject *obj = Hero.mInventory->get (i);
obj->setAppearanceKnown ();
}
}
} else if (display) {
for (int i = 0; i < Level->mFeatures.count (); ++i) {
shFeature *f = Level->mFeatures.get (i);
if (!disk->isInfected () or RNG (3)) {
if (f->isTrap () and !f->isBerserkDoor ())
continue;
if ((f->mType == shFeature::kDoorHiddenVert or
f->mType == shFeature::kDoorHiddenHoriz))
{
if (disk->isBuggy ()) continue;
f->mType = shFeature::kDoorClosed;
f->mSportingChance = 0;
f->mTrapUnknown = 0;
}
if (f->isBerserkDoor () and disk->isOptimized ()) {
f->mTrapUnknown = 0;
}
Level->remember (f->mX, f->mY, f);
Level->drawSq (f->mX, f->mY);
}
}
}
I->pauseXY (Hero.mX, Hero.mY);
I->p ("%d object stack%s detected.",
stack, (stack == 0 or stack > 1) ? "s" : "");
I->p ("%d object%s detected.",
objs, (objs == 0 or objs > 1) ? "s" : "");
I->p ("%d construct%s detected.",
constr, (constr == 0 or constr > 1) ? "s" : "");
return kNormal;
}
/* Returns number of creatures of given type detected. */
static int
doDetectMonKind (shObject *computer, shObject *disk,
int (shCreature::*predicate) ())
{
shCompInterface interface = checkInterface (computer);
int canGetInfo = visualDisplaySuccesful (interface);
int cnt = 0;
/* FIXME: Loop through mCrList instead. This is slow! */
for (int y = 0; y < MAPMAXROWS; y++) {
for (int x = 0; x < MAPMAXCOLUMNS; x++) {
shCreature *c = Level->getCreature (x, y);
if (c and (c->*predicate) () and
(!disk->isInfected () or RNG (3)))
{
if (canGetInfo) {
I->drawMem (x, y, kNone, c, NULL, NULL, NULL);
}
cnt++;
}
}
}
I->pauseXY (Hero.mX, Hero.mY);
return cnt;
}
static shExecResult
doDetectLife (shObject *computer, shObject *disk)
{
disk->setKnown ();
if (Hero.is (kConfused)) {
I->p ("You scan the area for droids.");
if (disk->isBuggy ()) {
I->pause ();
I->p ("These aren't the droids you're looking for.");
return kNormal;
}
I->pauseXY (Hero.mX, Hero.mY);
int cnt = doDetectMonKind (computer, disk, &shCreature::isRobot);
I->p ("%d droid%s detected.", cnt, (cnt == 0 or cnt > 1) ? "s" : "");
} else {
I->p ("You scan the area for lifeforms.");
if (disk->isBuggy ()) { /* you detect yourself */
I->p ("1 lifeform detected.");
I->pauseXY (Hero.mX, Hero.mY);
return kNormal;
}
I->pauseXY (Hero.mX, Hero.mY);
int cnt = doDetectMonKind (computer, disk, &shCreature::isAlive);
I->p ("%d lifeform%s detected.", cnt, (cnt == 0 or cnt > 1) ? "s" : "");
}
return kNormal;
}
static shExecResult
doDetectTraps (shObject *computer, shObject *disk)
{
int cnt = 0;
int canGetInfo;
shCompInterface interface = checkInterface (computer);
I->p ("You scan the area for traps.");
canGetInfo = visualDisplaySuccesful (interface);
for (int i = 0; i < Level->mFeatures.count (); ++i) {
shFeature *f = Level->mFeatures.get (i);
if (f->isTrap () and (!disk->isInfected () or RNG (3))) {
if (f->isBerserkDoor ()) {
continue; /* not a trap, a malfunction */
}
if (canGetInfo) {
f->mTrapUnknown = 0;
Level->remember (f->mX, f->mY, f);
}
++cnt;
}
}
I->p ("%d trap%s detected.", cnt, (cnt == 0 or cnt > 1) ? "s" : "");
return kNormal;
}
static shExecResult
doDetectBugs (shObject *computer, shObject *disk)
{
shObject *obj;
int btotal = 0;
int i;
disk->setKnown ();
if (Hero.is (kConfused)) {
I->pauseXY (Hero.mX, Hero.mY);
I->p ("You scan the area for bugs.");
btotal = doDetectMonKind (computer, disk, &shCreature::isInsect);
} else if (disk->isBuggy ()) {
disk->setBugginessKnown ();
I->p ("This disk is buggy!");
Hero.reorganizeInventory ();
return kNormal;
} else {
I->p ("Scanning inventory for bugs...");
for (i = 0; i < Hero.mInventory->count (); i++) {
obj = Hero.mInventory->get (i);
/* One third chance to ignore item. */
if (!disk->isInfected () or RNG (3)) {
if (obj->isBuggy ()) {
obj->setBugginessKnown ();
btotal++;
} else if (disk->isOptimized ()) {
obj->setBugginessKnown ();
}
}
}
}
I->p ("%d bugs found.", btotal);
Hero.reorganizeInventory ();
return kNormal;
}
static shExecResult
doMapping (shObject *computer, shObject *disk)
{
shCompInterface interface = checkInterface (computer);
disk->setKnown ();
if (Hero.is (kConfused)) {
return doDetectTraps (computer, disk);
}
I->p ("A map appears on your screen!");
if (visualDisplaySuccesful (interface)) {
if (!disk->isInfected ()) {
Level->reveal (0);
} else {
Level->reveal (1);
I->p ("It seems to be missing some parts.");
disk->setInfectedKnown ();
}
}
if (computer->isA (kObjSatCom)) {
int aliens = doDetectMonKind (computer, disk, &shCreature::isAlien);
if (aliens) {
I->p ("%d worthy prey found.", aliens);
}
}
return kNormal;
}
static int
canBeOptimized (shObject *obj)
{
return !obj->isBugProof () and
(!obj->isOptimized () or !obj->isBugginessKnown ());
}
static shExecResult
doDebug (shObject *computer, shObject *disk)
{ /* May need to reorganize inventory because objects with new state
might be able to stack with others of its ilk. */
int objsChanged = 0;
shObject *obj;
shObjectVector v;
if (computer->isBuggy ()) {
computer->setDebugged ();
I->p ("%s seems to be working much better.", computer->your ());
disk->setKnown ();
computer->setBugginessKnown ();
return kNormal;
} else if (disk->isInfected () and
!computer->isBugginessKnown () and computer->isDebugged ()) {
/* Pretend to debug debugged computer. */
I->p ("%s seems to be working much better.", computer->your ());
disk->setKnown ();
computer->setBugginessKnown ();
return kNormal;
}
if (Hero.is (kConfused)) {
disk->setKnown ();
disk->resetBugginessKnown ();
if (disk->isBuggy ()) {
disk->setDebugged ();
I->p ("You patch some bugs in %s.", disk->your ());
objsChanged = 1;
} else if (disk->isOptimized ()) {
int i;
if (disk->isCracked () and disk->isInfected ())
selectObjectsByFunction (&v, Hero.mInventory, &shObject::isOptimized);
selectObjectsByFunction (&v, Hero.mInventory, &shObject::isBuggy);
for (i = 0; i < v.count (); i++) {
obj = v.get (i);
obj->setDebugged ();
if (disk->isInfected ()) obj->setInfected ();
if (obj->isA (kObjTorc) and obj->isWorn ()) Hero.torcCheck ();
}
I->p ("%d objects debugged.", i);
objsChanged = i;
} else {
disk->setOptimized ();
I->p ("You optimize %s.", disk->your ());
objsChanged = 1;
}
disk->setBugginessKnown ();
return kNormal;
} else if (disk->isOptimized ()) {
disk->setBugginessKnown ();
if (!disk->isKnown ()) {
disk->setKnown ();
I->p ("You have found a floppy disk of debugging!");
}
bool unrestricted = disk->isCracked () and disk->isCrackedKnown ();
shMenu *dbgmenu = I->newMenu ("What do you want to debug or optimize?",
shMenu::kCategorizeObjects |
(unrestricted ? shMenu::kMultiPick : 0));
shObjectVector v;
selectObjectsByCallback (&v, Hero.mInventory, canBeOptimized);
if (!v.count ()) {
I->p ("You have nothing to debug or optimize.");
return kNormal;
}
for (int i = 0; i < v.count (); ++i) {
obj = v.get (i);
dbgmenu->addPtrItem (obj->mLetter, obj->inv (), obj, obj->mCount);
}
while (dbgmenu->getPtrResult ((const void **) &obj)) {
if (obj->isBugProof ()) {
I->p ("%s %s not appear to be affected.", obj->your (),
obj->mCount > 1 ? "do" : "does");
return kNormal;
} else if (obj->isBuggy ()) {
obj->setDebugged ();
I->p ("You patch some bugs in %s.", obj->your ());
++objsChanged;
} else if (obj->isOptimized ()) {
I->p ("You verify that %s is fully optimized.", obj->your ());
} else {
if (disk->isInfected ()) {
I->p ("You verify that %s is debugged.", obj->your ());
disk->setInfectedKnown ();
} else {
obj->setOptimized ();
I->p ("You optimize %s.", obj->your ());
++objsChanged;
}
}
if (obj->isA (kObjTorc) and obj->isWorn ()) Hero.torcCheck ();
obj->setBugginessKnown ();
if (!unrestricted) break;
}
} else {
bool unrestricted = disk->isCracked () and disk->isCrackedKnown ();
shObjectVector v2;
selectObjectsByFunction (&v, Hero.mInventory, &shObject::isWorn);
selectObjectsByFunction (&v2, &v, &shObject::isBuggy);
if (Hero.mWeapon and Hero.mWeapon->isBuggy ()) {
v2.add (Hero.mWeapon);
}
if (v2.count ()) {
for (int i = 0; i < v2.count (); ++i) {
if (!unrestricted) {
obj = v2.get (RNG (v2.count ()));
} else {
obj = v2.get (i);
}
obj->resetBugginessKnown (); /* For prettier message. */
I->p ("Debugging %s.", obj->an ());
obj->setDebugged ();
obj->setBugginessKnown ();
if (obj->isA (kObjTorc) and obj->isWorn ()) Hero.torcCheck ();
++objsChanged;
if (!unrestricted) break;
}
} else {
I->p ("No showstopper bugs found.");
}
disk->setKnown ();
}
if (objsChanged) {
Hero.reorganizeInventory ();
Hero.computeIntrinsics ();
Hero.computeSkills ();
}
return kNormal;
}
static shExecResult
doEnhanceArmor (shObject *computer, shObject *disk)
{
shObject *obj;
shObjectVector v, w;
selectObjects (&v, Hero.mInventory, kArmor);
selectObjectsByFunction (&w, &v, &shObject::isWorn);
v.reset ();
if (!Hero.is (kConfused)) {
selectObjectsByFunction (&v, &w, &shObject::isEnhanceable);
} else {
selectObjectsByFunction (&v, &w, &shObject::isFooproofable);
}
if (0 == v.count ()) {
I->p ("Your skin tingles for a moment.");
disk->setKnown ();
return kNormal;
}
obj = v.get (RNG (v.count ()));
shObjectIlk *ilk = obj->myIlk ();
const char *your_armor = obj->your ();
int max_opt_enhc = ilk->mMaxEnhancement;
int max_dbg_enhc = ilk->mMaxEnhancement / 2 + ilk->mMaxEnhancement % 2;
if (Hero.is (kConfused)) {
if (kNoEnergy != obj->vulnerability ()) {
if (!obj->isFooproof ()) {
if (!disk->isInfected ()) {
obj->setFooproof ();
} else {
obj->resetFooproof ();
}
}
}
I->p ("%s vibrates.", your_armor);
disk->setKnown ();
if (obj->mDamage) {
if (!disk->isInfected ()) {
obj->mDamage = 0;
} else {
--obj->mDamage;
}
if (!Hero.isBlind ()) {
if (!obj->mDamage) {
I->p ("%s looks as good as new!", your_armor);
} else {
I->p ("%s looks only slightly better.", your_armor);
disk->setInfectedKnown ();
}
}
}
} else if (disk->isBuggy ()) {
if (obj->mEnhancement > -max_opt_enhc) {
if (!disk->isInfected () or RNG (3)) {
--obj->mEnhancement;
}
}
if (!disk->isInfected () or !RNG (3)) {
obj->setBuggy ();
}
disk->setKnown ();
if (!Hero.isBlind ()) {
I->p ("Blue smoke billows from %s.", your_armor);
} else {
I->p ("You smell smoke.");
}
} else if (disk->isOptimized ()) {
int bonus = (max_opt_enhc + 1 - obj->mEnhancement) / 2;
bonus = bonus <= 0 ? 0 : RNG (1, bonus);
if (bonus > 1 and disk->isInfected () and RNG (3))
bonus = 1;
obj->mEnhancement += bonus;
if (bonus >= 1) {
disk->setKnown ();
disk->setBugginessKnown ();
}
if (!obj->isOptimized ()) {
if (!disk->isInfected () or !RNG (3)) {
obj->setOptimized ();
}
}
I->p ("%s feels warm for %s.", your_armor, bonus > 1 ? "a while" :
bonus > 0 ? "a moment" : "an instant");
} else {
disk->setKnown ();
if (obj->mEnhancement < max_dbg_enhc) {
if (!disk->isInfected () or RNG (3)) {
++obj->mEnhancement;
}
I->p ("%s feels warm for a moment.", your_armor);
} else {
I->p ("%s feels warm for an instant.", your_armor);
disk->setBugginessKnown ();
}
if (obj->isBuggy ()) {
if (!disk->isInfected () or RNG (3)) {
obj->setDebugged ();
}
}
}
Hero.computeAC ();
return kNormal;
}
static shExecResult
doEnhanceImplant (shObject *computer, shObject *disk)
{
shObject *obj;
shObjectVector v, w;
disk->setKnown ();
selectObjects (&v, Hero.mInventory, kImplant);
selectObjectsByFunction (&w, &v, &shObject::isWorn);
v.reset ();
selectObjectsByFunction (&v, &w, &shObject::isEnhanceable);
if (0 == v.count ()) {
I->p ("Your brain throbs."); /* Ragnarok weird fume reference. */
return kNormal;
}
obj = v.get (RNG (v.count ()));
if (disk->isBuggy ()) {
I->p ("You feel a stinging sensation in your %s.",
describeImplantSite (obj->mImplantSite));