-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mutant.cpp
1372 lines (1261 loc) · 41.5 KB
/
Mutant.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
/*******************************
Mutant Power Code
how to add a mutant power:
1. edit shMutantPower enum in Global.h
2. edit the little table in Mutant.h, and make sure the order is consistent
with the enum!
3. write a usePower function, or startPower/stopPower functions
4. possibly write shCreature::Power function if you want monsters to use it too
5. add the appropriate skill to the Psion and maybe other character classes
********************************/
#include "Global.h"
#include "Util.h"
#include "Object.h"
#include "Hero.h"
#include "Interface.h"
#include "Mutant.h"
#define MUTPOWER_CURSOR 3 /* Tile number in kRowCursor for targeting powers. */
static int
shortRange (shCreature *c)
{
return 5 + c->mCLevel / 4;
}
int
shCreature::getPsionicDC (int powerlevel)
{
return 10 + powerlevel + ABILITY_MODIFIER (getPsi () + mPsiDrain);
}
/* roll to save against the psionic attack
returns: 0 if save failed, true if made
*/
int
shCreature::willSave (int DC)
{
int modifier = mWillSaveBonus + ABILITY_MODIFIER (getPsi () + mPsiDrain);
int result = RNG (1, 20) + modifier;
if (Hero.isLucky ()) {
if (isHero () or isPet ()) {
result += RNG (1, 3);
}
}
debug.log ("Rolled will save %d+%d=%d, dc %d",
result - modifier, modifier, result, DC);
return result >= DC;
}
/* Returns: 1 if defender has better torc otherwise 0. */
static int /* Prints message if psionic attack was deflected. */
torcComparison (shCreature *attacker, shCreature *defender)
{
int result = attacker->mImplants[shObjectIlk::kNeck] and
defender->mImplants[shObjectIlk::kNeck] and
defender->mImplants[shObjectIlk::kNeck]->mBugginess >
attacker->mImplants[shObjectIlk::kNeck]->mBugginess;
if (result) {
if (attacker->isHero ()) {
I->p ("%s prevents you from making a psionic attack against %s.",
YOUR (attacker->mImplants[shObjectIlk::kNeck]), THE (defender));
} else if (defender->isHero ()) {
I->p ("Circuitry of %s prevents a psionic assault against you.",
YOUR (defender->mImplants[shObjectIlk::kNeck]));
//TODO: reveal creature
//Level->drawSqCreature (attacker->mX, attacker->mY);
}
}
return result;
}
int
shCreature::digestion (shObject *obj)
{ /* No screwing yourself over a miskeypress. */
if ((obj->isA (kObjTheOrgasmatron) or
obj->isA (kObjFakeOrgasmatron1) or
obj->isA (kObjFakeOrgasmatron2) or
obj->isA (kObjFakeOrgasmatron3) or
obj->isA (kObjFakeOrgasmatron4) or
obj->isA (kObjFakeOrgasmatron5)) and
!obj->isAppearanceKnown ()) {
I->p ("Dude, it *might* be the Bizarro Orgasmatron. You may need *that* to win!");
I->p ("Go lose the game some other (and more creative) way.");
return 0;
}
if (obj->isA (kObjTheOrgasmatron)) {
I->p ("Dude, this is the Bizarro Orgasmatron! You need *that* to win!");
I->p ("Go lose the game some other (and more creative) way.");
return 0;
} /* Knowingly eating other Orgasmatrons is fine. */
if (isHero ()) {
shObject *stack = NULL;
if (obj->mCount > 1) {
stack = obj;
obj = removeOneObjectFromInventory (obj);
} else {
removeObjectFromInventory (obj);
}
I->p ("You devour %s.", YOUR (obj));
if (obj->isInfected () and !Hero.mResistances[kSickening]) {
Hero.inflict (kSickened, RNG (15, 40) * FULLTURN);
if (stack) {
stack->setInfectedKnown ();
stack->announce ();
}
}
} else {
abort ();
}
delete obj;
return FULLTURN;
}
int
shCreature::telepathy (int on)
{
if (on) {
mInnateIntrinsics |= kTelepathy;
} else {
mInnateIntrinsics &= ~kTelepathy;
}
Hero.computeIntrinsics ();
return FULLTURN;
}
int
shCreature::tremorsense (int on)
{
if (on) {
mInnateIntrinsics |= kTremorsense;
} else {
mInnateIntrinsics &= ~kTremorsense;
}
Hero.computeIntrinsics ();
return FULLTURN;
}
int
shCreature::hypnosis (shDirection dir)
{
int x = mX;
int y = mY;
shCreature *target;
if (mLevel->moveForward (dir, &x, &y) and
(target = mLevel->getCreature (x, y)))
{
if (torcComparison (this, target)) return HALFTURN;
int saved = target->hasBrainShield () or
target->willSave (getPsionicDC (1));
if (target->isHero ()) {
if (!Hero.canSee (this)) {
/* You can't see the hypnotic gaze. */
} else if (saved) {
I->p ("You blink.");
} else { /* Message handled by sufferDamage. */
target->sufferDamage (kAttHypnoGaze);
}
} else {
const char *t_buf;
if (Hero.canSee (target)) {
t_buf = THE (target);
} else {
t_buf = "it";
}
if (!target->canSee (this)) {
I->p ("%s doesn't seem to notice your gaze.", t_buf);
} else if (!target->hasMind ()) {
I->p ("%s is unaffected.", t_buf);
} else if (saved) {
I->p ("%s resists!", t_buf);
} else {
target->sufferDamage (kAttHypnoGaze);
}
}
}
return HALFTURN;
}
int
shCreature::shootWeb (shDirection dir)
{
int x, y, r;
int maxrange = shortRange (this);
int elapsed = QUICKTURN;
int attackmod;
shSkill *skill = getSkill (kMutantPower, kShootWebs);
shAttack *WebAttack = &Attacks[kAttShootWeb];
WebAttack->mDamage[0].mLow = 1 + mCLevel / 2 + (skill ? skill->mRanks / 2 : 0);
WebAttack->mDamage[0].mHigh = 6 + (skill ? skill->mRanks : 0) + mCLevel / 2;
attackmod = mToHitModifier + getSkillModifier (kMutantPower, kShootWebs);
if (kUp == dir) {
return elapsed;
} else if (kDown == dir or kOrigin == dir) {
resolveRangedAttack (WebAttack, NULL, attackmod, this);
return elapsed;
}
x = mX; y = mY;
bool immediate = true;
while (maxrange--) {
if (!Level->moveForward (dir, &x, &y)) {
Level->moveForward (uTurn (dir), &x, &y);
return elapsed;
}
if (Level->isOccupied (x, y)) {
shCreature *c = Level->getCreature (x, y);
/* May sail overhead unless web was shot from adjacent position. */
if (c->mZ < 0 and RNG (2) and !immediate) {
continue;
}
r = resolveRangedAttack (WebAttack, NULL, attackmod, c);
if (r >= 0)
return elapsed;
}
if (Level->isObstacle (x, y)) return elapsed;
immediate = false;
}
return elapsed;
}
int
shCreature::opticBlast (shDirection dir)
{
//int maxrange = shortRange (this);
int elapsed = QUICKTURN;
shAttack *OpticBlast = &Attacks[kAttOpticBlast];
// FIXME: kludge
OpticBlast->mDamage[0].mLow = mCLevel;
OpticBlast->mDamage[0].mHigh = mCLevel * 6;
if (kUp == dir) {
/* TODO: maybe loosen debris from the ceiling? */
return elapsed;
} else if (kDown == dir) {
return elapsed;
}
int attackmod = getSkillModifier (kMutantPower, kOpticBlast)
+ mToHitModifier;
int foo = Level->areaEffect (OpticBlast, NULL, mX, mY,
dir, this, attackmod);
if (foo < 0)
return foo;
return elapsed;
}
int
shCreature::xRayVision (int on)
{
assert (isHero ());
if (on) {
if (!hasXRayVision () and
hasPerilSensing () and
mGoggles->isToggled ())
{
I->p ("You can see through your darkened goggles now.");
}
mInnateIntrinsics |= kXRayVision;
} else {
mInnateIntrinsics &= ~kXRayVision;
if (isHero () and
hasPerilSensing () and
mGoggles->isToggled ())
{
I->p ("You can no longer see through your darkened goggles.");
}
}
Hero.computeIntrinsics ();
return HALFTURN;
}
int
shCreature::mentalBlast (int x, int y)
{
shCreature *c = mLevel->getCreature (x, y);
int elapsed = SLOWTURN;
int shielded;
if (!c) {
return elapsed;
}
shielded = c->hasBrainShield ();
const char *t_buf = THE (c);
const char *an_buf = AN (c);
if (c->isHero ()) {
if (isHero ()) {
I->p ("You blast yourself with psionic energy!");
shielded = 0;
} else {
if (torcComparison (this, c)) {
I->p ("%s tingles briefly.", YOUR (mImplants[shObjectIlk::kNeck]));
return elapsed;
}
if (shielded) {
I->p ("Your scalp tingles.");
return elapsed;
}
I->p ("You are blasted by a wave of psionic energy!");
if (!Hero.canSee (this)) {
I->drawMem (mX, mY, kNone, this, NULL, NULL, NULL);
I->refreshScreen ();
I->pauseXY (mX, mY, 0, 0);
if (isSessile ()) {
Level->remember (mX, mY, mIlkId);
}
}
}
} else if (isHero ()) {
if (torcComparison (this, c)) return HALFTURN;
if (c->hasMind ()) {
if (!canSee (c) and !Hero.canHearThoughts (c)) {
/* Make sure the creature is referred to by its actual name
because by making contact with creature's mind hero now
knows what it is. For a brief moment at least.*/
Level->setVisible (x, y, 1);
an_buf = AN (c);
t_buf = THE (c);
Level->setVisible (x, y, 0);
I->drawMem (mX, mY, kNone, this, NULL, NULL, NULL);
I->refreshScreen ();
I->p ("You blast %s with a wave of psionic energy.", an_buf);
I->pauseXY (x, y);
} else {
I->p ("You blast %s with a wave of psionic energy.", t_buf);
}
c->newEnemy (this);
} else if (!canSee (x, y)) {
return elapsed;
}
}
if (!c->hasMind () or c->hasBrainShield ()) {
if (Hero.canSee (c)) {
I->p ("%s is not affected.", t_buf);
} else if (Hero.canHearThoughts (c)) {
I->p ("You sense no effect.");
}
return elapsed;
} else if (c->isHero ()) {
I->p ("Ow!");
}
shAttack *atk;
if (c->willSave (getPsionicDC (3))) {
atk = &Attacks[kAttResistedMentalBlast];
atk->mDamage[0].mLow = (mCLevel + 1) / 2;
atk->mDamage[0].mHigh = atk->mDamage[0].mLow * 3;
} else { /* confused if save not made */
atk = &Attacks[kAttMentalBlast];
atk->mDamage[0].mLow = (mCLevel + 1) / 2;
atk->mDamage[0].mHigh = atk->mDamage[0].mLow * 6;
}
if (c->sufferDamage (atk, this, NULL, 1, 1)) {
if (isHero () or Hero.canSee (c)) {
I->p ("%s %s killed!", t_buf, c->isHero () ? "are" : "is");
}
c->die (kKilled, this, NULL, atk, "a mental blast");
}
return elapsed;
}
int
shCreature::regeneration ()
{
if (isHero () and mHP == mMaxHP and Hero.getStoryFlag ("lost tail")) {
Hero.resetStoryFlag ("lost tail");
Hero.myIlk ()->mAttacks[3].mAttId = kAttXNTail;
Hero.myIlk ()->mAttacks[3].mProb = 1;
Hero.myIlk ()->mAttackSum += 1;
I->p ("You regrow your tail!");
return FULLTURN;
}
mHP += NDX (mCLevel, 4);
if (mHP > mMaxHP) {
mHP = mMaxHP;
}
return FULLTURN;
}
/* Is this balanced? Trade -4 cha for +4 str - is awesome for non-psions! */
int
shCreature::adrenalineControl (int on)
{
mAbil.mStr += on ? 4 : -4;
mMaxAbil.mStr += on ? 4 : -4;
computeIntrinsics ();
return FULLTURN;
}
int
shCreature::haste (int on)
{ /* Implemented in shCreature::computeIntrinsics () */
if (on) {
if (isHero ()) {
I->p ("Your actions accelerate.");
} else if (Hero.canSee (this)) {
I->p ("%s speeds up!", the ());
}
} else {
if (isHero ()) {
I->p ("Your actions decelerate.");
} else if (Hero.canSee (this)) {
I->p ("%s slows down!", the ());
}
}
computeIntrinsics ();
return FULLTURN;
}
int
shCreature::psionicStorm (int x, int y)
{
if (isHero ()) {
I->p ("You invoke psionic storm ...");
}
mLevel->areaEffect (kAttPsionicStorm, NULL, x, y, kNoDirection, this, 0);
return SLOWTURN;
}
extern void pacifyMelnorme (shMonster *); /* Services.cpp */
int
shCreature::theVoice (int x, int y)
{
const int elapsed = SLOWTURN;
static const struct shVoiceEffect
{
const char *command;
shCondition effect;
} voiceData[] =
{
{"%s %s%s: \"%s will not read the Nam-Shub!\"", kUnableCompute},
{"%s %s%s: \"%s will not indulge %s mutant nature!\"", kUnableUsePsi},
{"%s %s%s: \"%s will not show belligerence!\"", kUnableAttack},
{"%s %s%s: \"%s will not feast upon the poor!\"", kGenerous}
};
shCreature *c = Level->getCreature (x, y);
if (!c) {
if (isHero ()) I->p ("There is no one here.");
return 0;
}
if (!Level->existsLOS (mX, mY, x, y)) {
if (isHero ()) I->p ("%s cannot hear you.", THE (c));
return 0;
}
if (c->mType != kHumanoid and c->mType != kMutant and
c->mType != kOutsider and c->mType != kCyborg)
{
if (isHero ()) I->p ("The Voice has no effect.");
return elapsed;
}
/* Determine exact The Voice command to use. */
int choice, options;
if (c->isA (kMonMelnorme) and c->isHostile ()) {
I->p ("You speak: \"You will not bear petty grudges!\"");
shMonster *m = (shMonster *) c;
pacifyMelnorme (m);
I->p ("%s complies.", THE (c));
return elapsed;
} else {
int possible[3];
options = 0;
if (!c->is (kUnableCompute) and
(c->isHero () or c->isA (kMonUsenetTroll) or c->isA (kMonBOFH)))
{
possible[options++] = 0;
}
if (!c->is (kUnableUsePsi)) {
int haspowers = 0;
if (c->isHero ()) {
for (int i = kNoMutantPower + 1; i < kMaxHeroPower; ++i) {
if (c->mMutantPowers[i]) {
haspowers = 1;
break;
}
}
} else {
for (int i = kNoMutantPower + 1; i < kMaxMutantPower; ++i) {
if (c->myIlk ()->mPowers[i]) {
haspowers = 1;
break;
}
}
}
if (haspowers) possible[options++] = 1;
}
if (!c->is (kUnableAttack)) {
possible[options++] = 2;
}
if ((c->isA (kMonLawyer) or c->isA (kMonMelnorme))
and !c->is (kGenerous))
{
possible[options++] = 2;
if (RNG (3) or !c->isHostile ()) {
possible[0] = 3;
choice = 3;
options = 1;
}
}
if (options) choice = possible[RNG (options)];
}
if (!options) {
if (isHero ()) {
I->p ("You have fully used The Voice against %s already.",
c == this ? "yourself" : THE (c));
}
return elapsed;
}
bool self = this == c;
I->p (voiceData[choice].command, the (), self ? "vow" : "speak",
isHero () ? "" : "s", self ? "I" : "you", self ? "my" : "your");
c->inflict (voiceData[choice].effect, FULLTURN * RNG (3, 13));
return elapsed;
}
static int
useDigestion (shHero *h)
{
if (Hero.getStoryFlag ("superglued tongue")) {
I->p ("You can't eat anything with this stupid canister "
"glued to your mouth!");
return 0;
}
shObject *obj =
h->quickPickItem (h->mInventory, "eat", shMenu::kCategorizeObjects);
if (obj) {
/* objects on your head can't be eaten conveniently, but otherwise
we'll assume that digestion comes along with super flexibility
required to eat belts, boots, armor, etc.
*/
if (obj->isA (kImplant) and obj->isWorn () and !obj->isA (kObjTorc)) {
I->p ("You'll have to uninstall that first.");
} else if (h->mHelmet == obj or h->mGoggles == obj) {
I->p ("You'll have to take it off first.");
} else {
return h->digestion (obj);
}
} else {
I->nevermind ();
}
return 0;
}
static int
useAdrenalineControl (shHero *h)
{
return h->adrenalineControl (1);
}
static int
stopAdrenalineControl (shHero *h)
{
return h->adrenalineControl (0);
}
static int
useHaste (shHero *h)
{
return h->haste (1);
}
static int
stopHaste (shHero *h)
{
return h->haste (0);
}
static int
useTelepathy (shHero *h)
{
I->p ("You extend the outer layers of your mind.");
return h->telepathy (1);
}
static int
stopTelepathy (shHero *h)
{
I->p ("Your consciousness contracts.");
return h->telepathy (0);
}
static int
useTremorsense (shHero *h)
{
return h->tremorsense (1);
}
static int
stopTremorsense (shHero *h)
{
return h->tremorsense (0);
}
static int
useOpticBlast (shHero *h)
{
if ((h->hasPerilSensing () and h->mGoggles->isToggled ()) or
(h->mGoggles and h->mGoggles->isA (kObjBlindfold)))
{
if (!h->mGoggles->isFooproof ()) {
I->p ("You incinerate %s!", YOUR (h->mGoggles));
if (h->sufferDamage (kAttBurningGoggles)) {
h->shCreature::die (kMisc, "Burned his face off");
}
h->removeObjectFromInventory (h->mGoggles);
} else {
I->p ("You try to ignite %s without result.", YOUR (h->mGoggles));
}
return FULLTURN;
} else if (h->isBlind ()) {
I->p ("But you are blind!");
return 0;
}
shDirection dir = I->getDirection ();
if (kNoDirection == dir) {
return 0;
} else {
return h->opticBlast (dir);
}
}
static int
useRegeneration (shHero *h)
{
return h->regeneration ();
}
static int
useRestoration (shHero *h)
{ /* TODO: Factor in skill. */
return h->restoration (RNG (1, 2));
}
static int
useHypnosis (shHero *h)
{
shDirection dir = I->getDirection ();
if (kNoDirection == dir) {
return 0;
} else if (kOrigin == dir) {
I->p ("You need a mirror for that.");
return 0;
} else {
return h->hypnosis (dir);
}
}
static int
useXRayVision (shHero *h)
{
return h->xRayVision (1);
}
static int
stopXRayVision (shHero *h)
{
return h->xRayVision (0);
}
/* Returns how much psi ability points using/sustaning given */
static int /* power 'power' costs while autolysis is active. */
autolysisCost (int power)
{
if (MutantPowers[power].mOffFunc) {
return maxi (0, mini (MutantPowers[power].mLevel - 2,
MutantPowers[power].mLevel / 2));
}
return MutantPowers[power].mLevel / 2;
}
static int
useAutolysis (shHero *h)
{
/* Difference of Psi points for each continuous power is given back. */
for (int i = kNoMutantPower; i <= kMaxHeroPower; i++) {
if (i == kAutolysis) continue;
if (h->mMutantPowers[i] > 1) {
h->mPsiDrain += MutantPowers[i].mLevel - autolysisCost (i);
h->mMaxAbil.mPsi += MutantPowers[i].mLevel - autolysisCost (i);
}
}
return FULLTURN;
}
static int
stopAutolysis (shHero *h)
{
int need = 0; /* Psi points needed to sustain powers without autolysis. */
int powercost = MutantPowers[kAutolysis].mLevel;
int pool = h->getPsi () + h->mPsiDrain - 1;
for (int i = kNoMutantPower; i <= kMaxHeroPower; i++) {
if (i == kAutolysis) continue;
if (h->mMutantPowers[i] > 1) {
need += MutantPowers[i].mLevel - autolysisCost (i);
}
}
if (need <= powercost) { /* Not full Psi cost of autolysis regained. */
h->mMaxAbil.mPsi -= need;
h->mPsiDrain -= need;
return FULLTURN;
} else if (need <= pool) { /* Additional Psi cost incurred. */
h->mMaxAbil.mPsi -= need;
h->mAbil.mPsi -= need - powercost;
h->mPsiDrain -= powercost;
return FULLTURN;
} /* Else not enough Psi. Drop continuous powers. */
for (int i = kNoMutantPower; i <= kMaxHeroPower; i++) {
if (i == kAutolysis) continue;
if (h->mMutantPowers[i] > 1) {
h->mPsiDrain += autolysisCost (i);
h->mMutantPowers[i] = 1;
MutantPowers[i].mOffFunc (h);
}
}
I->p ("You will need to reactivate your continuous powers.");
return FULLTURN;
}
static int
useTeleport (shHero *h)
{
int x, y;
Level->findSquare (&x, &y);
h->transport (x, y, 100, 1);
return HALFTURN;
}
static int
useIllumination (shHero *h)
{
int skill = h->getSkillModifier (kMutantPower, kIllumination);
int radius = 4 + (skill / 3);
for (int x = h->mX - radius; x <= h->mX + radius; x++) {
for (int y = h->mY - radius; y <= h->mY + radius; y++) {
if (Level->isInBounds (x, y) and Level->isInLOS (x, y)
and distance (x, y, h->mX, h->mY) < radius * 5)
{
Level->setLit (x, y, 1, 1, 1, 1);
}
}
}
return HALFTURN;
}
static int
useWeb (shHero *h)
{
shDirection dir = I->getDirection ();
if (kNoDirection == dir) {
return 0;
} else {
return h->shootWeb (dir);
}
}
/* The two below are pretty similar. When third of ilk appears */
static int /* try joining them into one. */
useMentalBlast (shHero *h)
{
int x = -1, y = -1;
if (0 == I->getSquare ("What do you want to blast? (select a location)",
&x, &y, shortRange (h), 0, MUTPOWER_CURSOR))
{
return 0;
} else {
return h->mentalBlast (x, y);
}
}
static int
useTheVoice (shHero *h)
{
int x = -1, y = -1;
if (0 == I->getSquare ("Who do you want to command? (select a location)",
&x, &y, shortRange (h), 0, MUTPOWER_CURSOR))
{
return 0;
} else {
return h->theVoice (x, y);
}
}
static int
usePsionicStorm (shHero *h)
{
int x = -1, y = -1;
if (0 == I->getSquare ("Where do you want to invoke the storm?"
" (select a location)", &x, &y, 100, 0, MUTPOWER_CURSOR))
{
return 0;
} else {
int success = h->psionicStorm (x, y);
if (success) { /* This is costly power. */
int drain = --Hero.mAbil.mPsi - 1;
if (h->mMutantPowers[kAutolysis] == 2) drain /= 2;
Hero.mAbil.mPsi -= drain;
Hero.mPsiDrain += drain;
Hero.mPsionicStormFatigue += 2;
}
return success;
}
}
/* make sure these agree with the enum def in Global.h: */
MutantPower MutantPowers[kMaxAllPower] =
{ { 0, ' ', "empty", NULL, NULL },
{ 1, 'i', "Illumination", useIllumination, NULL },
{ 1, 'd', "Digestion", useDigestion, NULL },
{ 1, 'h', "Hypnosis", useHypnosis, NULL },
{ 1, 'r', "Regeneration", useRegeneration, NULL },
{ 2, 'o', "Optic Blast", useOpticBlast, NULL },
{ 2, 'H', "Haste", useHaste, stopHaste },
{ 2, 'T', "Telepathy", useTelepathy, stopTelepathy },
{ 2, 'R', "Tremorsense", useTremorsense, stopTremorsense },
{ 2, 'w', "Web", useWeb, NULL },
{ 3, 'm', "Mental Blast", useMentalBlast, NULL},
{ 3, 's', "Restoration", useRestoration, NULL },
{ 4, 'A', "Adrenaline Control", useAdrenalineControl, stopAdrenalineControl },
{ 4, 'X', "X-Ray Vision", useXRayVision, stopXRayVision },
{ 4, 'v', "The Voice", useTheVoice, NULL },
{ 5, 't', "Teleport", useTeleport, NULL },
{ 6, 'L', "Autolysis", useAutolysis, stopAutolysis },
{ 8, 'p', "Psionic Storm", usePsionicStorm, NULL }
};
const char *
getMutantPowerName (shMutantPower id)
{
return MutantPowers[id].mName;
}
int
shHero::getMutantPowerChance (int power)
{
int chance =
(getSkillModifier (kMutantPower, (shMutantPower) power) +
+ mini (mCLevel, 10) /* At higher levels anyone could use any power. */
+ mPsiModifier + 15 - 2 * MutantPowers[power].mLevel) * 5;
if (MutantPowers[power].mLevel * 2 > mCLevel + 1) chance -= 20;
if (power == kPsionicStorm) chance -= 5 * mPsionicStormFatigue;
if (Psion == mProfession) chance += mCLevel * 5;
if (chance > 100) chance = 100;
if (chance < 0) chance = 0;
return chance;
}
int
shHero::stopMutantPower (shMutantPower id)
{
int autolysis = mMutantPowers[kAutolysis] == 2;
if (kAutolysis == id or !autolysis) {
mMaxAbil.mPsi += MutantPowers[id].mLevel;
mPsiDrain += MutantPowers[id].mLevel;
} else {
mMaxAbil.mPsi += autolysisCost (id);
mPsiDrain += autolysisCost (id);
}
mMutantPowers[id] = 1;
return MutantPowers[id].mOffFunc (this);
}
/* returns: elapsed time */
int
shHero::useMutantPower ()
{
shMenu *menu = I->newMenu ("Use which mutant power?", 0);
menu->attachHelp ("mutpowers.txt");
int n = 0;
char buf[50];
if (is (kUnableUsePsi)) {
I->p ("Mere thought of this seems disguisting to you.");
return 0;
}
menu->addHeader (" Power Level Chance");
for (int i = kNoMutantPower; i <= kMaxHeroPower; i++) {
if (mMutantPowers[i]) {
int l;
int chance = getMutantPowerChance (i);
l = snprintf (buf, 50, "%-19s %d ",
MutantPowers[i].mName, MutantPowers[i].mLevel);
if (mMutantPowers[i] > 1) {
/* persistant power that's already toggled */
snprintf (&buf[l], 10, "(on)");
} else {
snprintf (&buf[l], 10, "%3d%%", chance);
}
menu->addIntItem (MutantPowers[i].mLetter, buf, i, 1);
++n;
}
}
if (0 == n) {
I->p ("You don't have any mutant powers.");
return 0;
}
int i = 0;
int autolysis = mMutantPowers[kAutolysis] == 2;
menu->getIntResult (&i, NULL);
delete menu;
if (i) {
/* Deactivating a power, always succeed. */
if (mMutantPowers[i] > 1) {
return stopMutantPower ((shMutantPower) i);
}
int cost = autolysis ? autolysisCost (i) : MutantPowers[i].mLevel;
int pool = MutantPowers[i].mOffFunc ? mAbil.mPsi + mPsiDrain : mAbil.mPsi;
if (pool <= cost) {
I->p ("You are too weak to use that power.");
return 200;
}
int chance = getMutantPowerChance (i);
if (chance == 0) {
I->p ("No point in trying this.");
return 0;
}
if (i == kRegeneration and is (kSickened)) {
I->p ("Your organism is busy fighting sickness.");
return 0;
}
int roll = RNG (100);
debug.log ("mutant power attempt: rolled %d %s %d.",
roll, roll < chance ? "<" : ">=", chance);
mAbil.mPsi -= cost;
if (autolysis) {
int level = MutantPowers[i].mLevel;
int hp_loss = maxi (level, level * mHP / 10);
if (hp_loss >= mHP) {
shCreature::die (kMisc, "Went out with a bang");
return 0;
} else {
mHP -= hp_loss;
}
}
if (roll < chance) {
if (MutantPowers[i].isPersistant ()) {
mMaxAbil.mPsi -= cost;
mMutantPowers[i] = 2;
} else {
mPsiDrain += cost;
}
return MutantPowers[i].mFunc (this);
} else {
mPsiDrain += cost;
I->p ("You fail to use your power successfully.");
return HALFTURN;
}
}
return 0;
}
/* Certain distractions (such as getting stunned) may cause your */
void /* concentration to falter and powers to be stopped. */
shCreature::checkConcentration ()
{
int failed = 0;
int basesk = Hero.getSkillModifier (kConcentration);
if (!isHero ()) {
return;
}
for (int i = kNoMutantPower; i <= kMaxHeroPower; i++) {
int sk = basesk + RNG (1, 20);
if (mMutantPowers[i] > 1 and sk < 15) {