-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpiety.cpp
More file actions
1609 lines (1353 loc) · 33.5 KB
/
piety.cpp
File metadata and controls
1609 lines (1353 loc) · 33.5 KB
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
/*
* PROPRIETARY INFORMATION. This software is proprietary to POWDER
* Development, and is not to be reproduced, transmitted, or disclosed
* in any way without written permission.
*
* Produced by: Jeff Lait
*
* POWDER Development
*
* NAME: piety.cpp ( POWDER Library, C++ )
*
* COMMENTS:
* This implements all the piety handling code.
*/
#include "glbdef.h"
#include "assert.h"
#include <stdio.h>
#include "creature.h"
#include "piety.h"
#include "sramstream.h"
#include "item.h"
#include "itemstack.h"
#include "msg.h"
#include "map.h"
#include "encyc_support.h"
//
// This stores our total piety & total action points.
//
s16 glbPiety[NUM_GODS];
s16 glbGodPoints[NUM_GODS];
GOD_NAMES glbChosenGod = GOD_AGNOSTIC;
GOD_NAMES glbWhimOfXOM;
u8 glbWhimOfXOMTimer;
u8 glbFlameStrikeTimer;
GOD_NAMES glbFlameGod;
//
// Global Piety Functions
//
GOD_NAMES
piety_randomnonxomgod()
{
int god;
while (1)
{
god = rand_choice(NUM_GODS);
if (god == GOD_AGNOSTIC || god == GOD_CULTIST)
continue;
break;
}
return (GOD_NAMES) god;
}
void
piety_init()
{
GOD_NAMES god;
FOREACH_GOD(god)
{
glbPiety[god] = 0;
glbGodPoints[god] = 0;
}
// We do not set our god here as it was set in the god selection
// stage
// glbChosenGod = GOD_AGNOSTIC;
glbWhimOfXOM = piety_randomnonxomgod();
glbWhimOfXOMTimer = rand_range(100, 200);
glbFlameStrikeTimer = 0;
glbFlameGod = GOD_AGNOSTIC;
}
GOD_NAMES
piety_chosengod()
{
return glbChosenGod;
}
int
piety_chosengodspiety()
{
GOD_NAMES god = piety_chosengod();
if (god == GOD_AGNOSTIC)
return 0;
return glbPiety[god];
}
void
piety_setgod(GOD_NAMES god)
{
glbChosenGod = god;
}
void
piety_load(SRAMSTREAM &is)
{
int val;
GOD_NAMES god;
FOREACH_GOD(god)
{
is.read(val, 16);
glbPiety[god] = val;
is.read(val, 16);
glbGodPoints[god] = val;
}
is.read(val, 8);
glbChosenGod = (GOD_NAMES) val;
is.read(val, 8);
glbWhimOfXOM = (GOD_NAMES) val;
is.read(val, 8);
glbWhimOfXOMTimer = val;
is.read(val, 8);
glbFlameStrikeTimer = val;
is.read(val, 8);
glbFlameGod = (GOD_NAMES) val;
}
void
piety_save(SRAMSTREAM &os)
{
GOD_NAMES god;
FOREACH_GOD(god)
{
os.write(glbPiety[god], 16);
os.write(glbGodPoints[god], 16);
}
os.write(glbChosenGod, 8);
os.write(glbWhimOfXOM, 8);
os.write(glbWhimOfXOMTimer, 8);
os.write(glbFlameStrikeTimer, 8);
os.write(glbFlameGod, 8);
}
//
// MOB::piety Functions
//
void
MOB::pietyKill(MOB *mob, ATTACKSTYLE_NAMES attackstyle)
{
int val;
// Check to see if we are a slave. If so, grant the piety
// to our master as well.
MOB *master;
master = getMaster();
if (master)
{
master->pietyKill(mob, ATTACKSTYLE_MINION);
}
val = mob->getExpLevel();
if (val < getExpLevel() - 5)
val = 1;
else if (val < getExpLevel() + 2)
val = 2;
else
val = 3;
if (attackstyle != ATTACKSTYLE_SPELL)
pietyGrant(GOD_FIGHTER, val * 2);
if (attackstyle == ATTACKSTYLE_MELEE)
pietyGrant(GOD_BARB, val);
else
pietyGrant(GOD_NECRO, val);
if (attackstyle == ATTACKSTYLE_SPELL)
pietyGrant(GOD_WIZARD, val);
if (attackstyle == ATTACKSTYLE_THROWN)
pietyGrant(GOD_ROGUE, val);
if (mob->defn().mobtype == MOBTYPE_UNDEAD)
{
pietyGrant(GOD_CLERIC, val);
}
}
void
MOB::pietyEat(ITEM *item, int foodval)
{
if (item->getCorpseMob())
{
// Fallen foe....
// Only counts if you aren't hungry.
if (getHungerLevel() > HUNGER_HUNGRY)
pietyGrant(GOD_CLERIC, -2);
}
}
void
MOB::pietyDress(INTRINSIC_NAMES intrinsic)
{
// Only one in 5 chance of actually responding to this state.
if (rand_choice(5))
return;
if (intrinsic == INTRINSIC_DRESSED_WIZARD)
pietyGrant(GOD_WIZARD, 1);
if (intrinsic == INTRINSIC_DRESSED_FIGHTER)
pietyGrant(GOD_FIGHTER, 1);
if (intrinsic == INTRINSIC_DRESSED_RANGER)
pietyGrant(GOD_ROGUE, 1);
if (intrinsic == INTRINSIC_DRESSED_CLERIC)
{
// Pax isn't too impressed by all this..
if (rand_choice(8))
return;
pietyGrant(GOD_CLERIC, 1);
}
if (intrinsic == INTRINSIC_DRESSED_NECROMANCER)
{
// Necros should not be about piety.
if (rand_choice(4))
return;
pietyGrant(GOD_NECRO, 1);
}
if (intrinsic == INTRINSIC_DRESSED_BARBARIAN)
{
// H'ruth isn't into fashion.
if (rand_choice(8))
return;
pietyGrant(GOD_BARB, 1);
}
}
void
MOB::pietyZapWand(ITEM *wand)
{
pietyGrant(GOD_ROGUE, 2);
pietyGrant(GOD_WIZARD, 1);
pietyGrant(GOD_BARB, -1);
}
void
MOB::pietySurrounded(int numenemy)
{
// Barbarian bonus:
if (numenemy > 1)
{
// TODO: This would be a good time to grant BERSERK.
pietyGrant(GOD_BARB, numenemy * 2);
// Wizards do not like to be surrounded.
pietyGrant(GOD_WIZARD, -1);
}
}
void
MOB::pietyHeal(int amount, bool self, bool enemy, bool vampiric)
{
// Necros are rewarded for healing enemies, as it is assumed
// one merely wants them to suffer longer.
// Otherwise, it isn't something one should be doing.
if (enemy || vampiric)
pietyGrant(GOD_NECRO, 1);
else
pietyGrant(GOD_NECRO, -5);
// Clerics are of two minds of enemy healing. It is a no-op
// as otherwise it would encourage uncleric like behaviour.
// We get massive bonuses for healing our pets.
if (!enemy)
{
// vampiric styles of healing are not appreciated.
if (vampiric)
pietyGrant(GOD_CLERIC, -1);
else
pietyGrant(GOD_CLERIC, self ? 1 : 3);
}
}
void
MOB::pietyCastSpell(SPELL_NAMES spell)
{
int val;
val = glb_spelldefs[spell].mpcost +
(glb_spelldefs[spell].hpcost/2) +
(glb_spelldefs[spell].xpcost/10);
// An additional point is given for every 5 vals.
val /= 5;
if (val <= 0) val = 1;
pietyGrant(GOD_WIZARD, val);
if (glb_spelldefs[spell].type == SPELLTYPE_DEATH)
{
pietyGrant(GOD_NECRO, (val + 1) / 2);
pietyGrant(GOD_CLERIC, -val, true);
}
if (glb_spelldefs[spell].type == SPELLTYPE_HEAL)
{
pietyGrant(GOD_NECRO, -val, true);
pietyGrant(GOD_CLERIC, (val + 1) / 2);
}
// Forbidden for barbarians!
pietyGrant(GOD_BARB, -val, true);
}
void
MOB::pietyCreateTrap()
{
pietyGrant(GOD_ROGUE, 5);
}
void
MOB::pietyFindSecret()
{
pietyGrant(GOD_ROGUE, 5);
}
void
MOB::pietyAttack(MOB *mob, const ATTACK_DEF *attack, ATTACKSTYLE_NAMES style)
{
// Determine if it is a friendly attack.
ATTITUDE_NAMES attitude;
attitude = mob->getAttitude(this);
// Check for attacking friendly or what not.
if (attitude == ATTITUDE_FRIENDLY)
{
// Killing friendly undead is an act of mercy.
if (mob->defn().mobtype != MOBTYPE_UNDEAD)
pietyGrant(GOD_CLERIC, -5);
}
if (attitude == ATTITUDE_NEUTRAL)
{
// It is not *that* bad to start combat.
// However, if the target is undead, Pax has no issues.
if (mob->defn().mobtype != MOBTYPE_UNDEAD)
pietyGrant(GOD_CLERIC, -1);
}
if ( ( mob->hasIntrinsic(INTRINSIC_PARALYSED) &&
!mob->hasIntrinsic(INTRINSIC_FREEDOM)) ||
(mob->hasIntrinsic(INTRINSIC_ASLEEP)) )
{
// Strike helpless.
pietyGrant(GOD_ROGUE, 1);
pietyGrant(GOD_NECRO, 2);
// The exception is undead. You are free to
// engage them regardless of their status.
if (mob->defn().mobtype != MOBTYPE_UNDEAD)
{
pietyGrant(GOD_CLERIC, -2);
}
}
if (style == ATTACKSTYLE_THROWN)
{
// Ranged attack.
pietyGrant(GOD_ROGUE, 1);
pietyGrant(GOD_BARB, -2);
}
if (style == ATTACKSTYLE_MELEE)
{
// Melee attack
if (!rand_choice(5))
{
pietyGrant(GOD_WIZARD, -1);
pietyGrant(GOD_NECRO, -1);
}
}
}
void
MOB::pietyMakeNoise(int noiselevel)
{
if (noiselevel > 2)
{
if (!rand_choice(30))
pietyGrant(GOD_ROGUE, -1 * (noiselevel - 2));
}
}
void
MOB::pietyIdentify(ITEM_NAMES /*itemdef*/)
{
pietyGrant(GOD_ROGUE, 5);
pietyGrant(GOD_WIZARD, 3);
}
void
MOB::pietyBreak(ITEM *item)
{
if (glbWhimOfXOM == GOD_CLERIC)
{
// The hint makes it seem like that breaking things abuses
// ><0|V| The wiki picked up on this and I'd hate for
// it to be incorrect so I've retconned this pathway
pietyGrant(GOD_CULTIST, -2);
}
}
void
MOB::pietyGrant(GOD_NAMES god, int amount, bool forbidden)
{
// Only record piety for the avatar.
if (!isAvatar())
return;
// If this god is CULTIST, we need to see what the current
// whim of ><0|V| is, and act accordingly.
if (god == glbWhimOfXOM)
{
pietyGrant(GOD_CULTIST, amount, forbidden);
}
// If the action is forbidden, we want to zero out
// our piety in one go.
if (forbidden && glbPiety[god] > 0)
{
// You will likely invoke the wrath of the god. If it is
// your god, you will wipe your xp.
pietyTransgress(god);
glbPiety[god] += amount*10;
}
// If the piety is negative, and it is your chosen god,
// it is twice as bad.
if (god == glbChosenGod && amount < 0)
amount *= 2;
// DIminish returns on positive piety gain to prevent people
// stacking up 10k piety for constant healing
if (amount > 0)
{
if (glbPiety[god] > 200)
{
// Lose 1/16th chance for every 100 piety above this
// up to 15 * 100 + 200 = 1700..
int goal = (glbPiety[god]-200)/100;
if (goal >= 15)
goal = 14;
if (rand_choice(16) <= goal)
amount = 0;
// Double jeopardy for every 1000 there on (Caps at 10k)
if (glbPiety[god] > 2000)
{
if (rand_choice(16) < (glbPiety[god]-2000)/1000)
{
amount = 0;
}
}
}
}
// Adjust our piety & god points.
if (glbPiety[god] * amount > 0)
{
// Both piety & amount have same sign, increment god points.
if (amount > 0)
glbGodPoints[god] += amount;
else
glbGodPoints[god] -= amount;
}
glbPiety[god] += amount;
// Clamp piety to reasonable limits to avoid overflow/underflow
if (glbPiety[god] > 10000)
glbPiety[god] = 10000;
if (glbPiety[god] < -10000)
glbPiety[god] = -10000;
// Reduce god points to not become larger than piety.
if (abs(glbPiety[god]) < glbGodPoints[god])
glbGodPoints[god] = abs(glbPiety[god]);
#if 0
BUF buf;
buf.sprintf("%s: %d:%d. ",
glb_goddefs[god].name,
glbPiety[god],
amount);
msg_report(buf);
#endif
}
void
MOB::pietyTransgress(GOD_NAMES god)
{
// The user did something forbidden to this god.
// The penalty is determined by:
// 1) If you are currently following this god, wipe experience,
// report transgression, and dump all god piety into punishment.
// 2) If you are not, check to see if the god points are more than
// your current god's piety. If so, punish. Otherwise it is
// assumed that your own god stood in the way.
//
// We wipe out our god points, but don't wipe out our piety.
BUF buf;
// First, the god is given as many points as he wants to play with!
glbGodPoints[god] = glbPiety[god];
if (god == glbChosenGod)
{
const char *abusemsg[] =
{
"Your Actions Defile Me!",
"Do you value me so little?",
"Respect My Commands!"
};
buf.sprintf("%s: %s ", glb_goddefs[god].name,
abusemsg[rand_choice(3)]);
msg_announce(buf);
wipeExp();
pietyPunish(god);
}
else
{
if (glbChosenGod == GOD_AGNOSTIC)
{
const char *agnosticsavemsg[] =
{
"You sense celestial displeasure. ",
"You wonder if there are gods after all? ",
"A painful hangnail briefly distracts you. "
};
msg_announce(agnosticsavemsg[rand_choice(3)]);
// Your powers of disbelief succeed.
glbGodPoints[god] = 0;
}
else if (glbGodPoints[god] > glbPiety[glbChosenGod])
{
// Your current god cannot come to your rescue.
const char *abusemsg[] =
{
"%s: Do not look to %s to protect you! ",
"%s: You should obey Me! ",
"%s: You cannot hide from Me! "
};
buf.sprintf(abusemsg[rand_choice(3)],
glb_goddefs[god].name,
glb_goddefs[glbChosenGod].name);
msg_announce(buf);
pietyPunish(god);
}
else
{
// Let the player know a divine struggle just occurred.
const char *godsavemsg[] =
{
"%s: %s shall not meddle with my disciple! ",
"%s: Fear not %s while you follow me! ",
"%s: %s! Leave my people alone! "
};
buf.sprintf(godsavemsg[rand_choice(3)],
glb_goddefs[glbChosenGod].name,
glb_goddefs[god].name);
msg_announce(buf);
// This will cost you piety with your god!
glbPiety[glbChosenGod] -= glbGodPoints[god];
// We may have moved our piety to 0. If we leave
// our god points, this could result in us being
// punished!
// Thus, we ensure god points are less than piety.
if (glbGodPoints[glbChosenGod] > abs(glbPiety[glbChosenGod]))
glbGodPoints[glbChosenGod] = abs(glbPiety[glbChosenGod]);
// They all get nullified against your chosen god.
glbGodPoints[god] = 0;
}
}
glbPiety[god] = glbGodPoints[god];
glbGodPoints[god] = 0;
}
void
MOB::pietyPunish(GOD_NAMES god)
{
// Choose a punishment that fits the god and fits the available points.
PUNISH_NAMES valid[NUM_PUNISHS];
int numvalid = 0;
int points;
PUNISH_NAMES punish;
BUF buf;
points = glbGodPoints[god];
FOREACH_PUNISH(punish)
{
if (glb_punishdefs[punish].points <= points)
{
if (strchr(glb_punishdefs[punish].god, (char) god))
{
// This god is willing to do this punishment.
valid[numvalid++] = punish;
}
}
}
// If there is no valid punishments, quit.
if (!numvalid)
return;
punish = valid[rand_choice(numvalid)];
// Subtract the points & apply the punishment.
glbGodPoints[god] -= glb_punishdefs[punish].points;
switch (punish)
{
case PUNISH_FLAMESTRIKE:
{
formatAndReport("%U <smell> sulphur.");
glbFlameStrikeTimer = rand_range(3, 6);
glbFlameGod = god;
break;
}
case PUNISH_SUMMON:
{
buf.sprintf("%s: Prove your worth! ",
glb_goddefs[god].name);
msg_announce(buf);
MOB *mob;
int dx, dy;
for (dy = -1; dy <= 1; dy++)
{
for (dx = -1; dx <= 1; dx++)
{
if (glbCurLevel->getMob(getX()+dx,
getY()+dy))
continue;
mob = MOB::createNPC(getExpLevel()+3);
if (!mob->canMove(getX() + dx,
getY() + dy,
true))
{
delete mob;
continue;
}
mob->move(getX() + dx,
getY() + dy,
true);
glbCurLevel->registerMob(mob);
mob->formatAndReport("%U <appear> out of thin air!");
// Ensure we want to kill the target, which is this.
mob->setAITarget(this);
}
}
break;
}
case PUNISH_CURSE_WORN:
{
buf.sprintf("%s: To the pits with you! ",
glb_goddefs[god].name);
msg_announce(buf);
// Curse only equpped items.
receiveCurse(true, false);
break;
}
case PUNISH_CURSE_ANY:
{
buf.sprintf("%s: A pox on you! ",
glb_goddefs[god].name);
msg_announce(buf);
// Curse all items with equal chance.
receiveCurse(false, true);
break;
}
case PUNISH_DISENCHANT_WEAPON:
{
buf.sprintf("%s: You are an inferior tool! ",
glb_goddefs[god].name);
msg_announce(buf);
// gods do not invoke shuddering.
receiveWeaponEnchant(-1, false);
break;
}
case PUNISH_DISENCHANT_ARMOUR:
{
buf.sprintf("%s: You deserve no protection! ",
glb_goddefs[god].name);
msg_announce(buf);
// gods do not invoke shuddering.
receiveArmourEnchant((ITEMSLOT_NAMES)-1, -1, false);
break;
}
case PUNISH_POISON:
{
buf.sprintf("%s: Drink the poison you have brewed! ",
glb_goddefs[god].name);
msg_announce(buf);
setTimedIntrinsic(0, INTRINSIC_POISON_STRONG, 20);
break;
}
case PUNISH_PARALYSE:
{
buf.sprintf("%s: Freeze with Fright at my Wrath! ",
glb_goddefs[god].name);
msg_announce(buf);
setTimedIntrinsic(0, INTRINSIC_PARALYSED, 5);
break;
}
case PUNISH_SLEEP:
{
buf.sprintf("%s: Dream in Terror! ",
glb_goddefs[god].name);
msg_announce(buf);
setTimedIntrinsic(0, INTRINSIC_ASLEEP, 30);
break;
}
case PUNISH_POLY:
{
MOB_NAMES mob;
// Determine a suitable pathetic beast.
MOB_NAMES targets[3] =
{
MOB_MOUSE,
MOB_BROWNSLUG,
MOB_GRIDBUG
};
if (god == GOD_NECRO)
mob = MOB_SKELETON;
else
mob = targets[rand_choice(3)];
buf.sprintf("%s: Learn Humility! ",
glb_goddefs[god].name);
msg_announce(buf);
// And poly the loser into it!
actionPolymorph(false, true, mob);
break;
}
case PUNISH_MANADRAIN:
{
buf.sprintf("%s: Your Magic Will Not Avail You! ",
glb_goddefs[god].name);
msg_announce(buf);
// drain magic.
// 50 + 5d10 turns.
setTimedIntrinsic(0, INTRINSIC_MAGICDRAIN,
rand_dice(5, 10, 50));
break;
}
case PUNISH_POLYWEAPON:
{
ITEM *weapon;
weapon = getEquippedItem(ITEMSLOT_RHAND);
if (!weapon)
{
// Should not occur?
buf.sprintf("%s: I have caught you empty handed! Ha! ",
glb_goddefs[god].name);
msg_announce(buf);
break;
}
BUF weapname = weapon->getName();
buf.sprintf("%s: Your over use of %s bores me! ",
glb_goddefs[god].name,
weapname.buffer());
msg_announce(buf);
// polymorph the weapon...
ITEM *newweapon;
newweapon = weapon->polymorph(this);
// If the polymorph fails, we don't want to delete
// their weapon!
if (!newweapon)
{
// We haven't yet dropped the old weapon,
// so just break for status quo
break;
}
// Some day I will make a less error prone way of writing
// this. This is not that day!
weapon = dropItem(weapon->getX(), weapon->getY());
// If the weapon has a stack, we split & reacquire. Otherwise
// we destroy.
if (weapon->getStackCount() > 1)
{
weapon->splitAndDeleteStack();
// Try and reacquire as a non-weapon.
if (!acquireItem(weapon))
{
// Failed to put in inventory, drop.
formatAndReport("%U <lack> room for %IU.", weapon);
glbCurLevel->acquireItem(weapon, getX(), getY(), 0);
}
}
else
{
// Toss the item silently
delete weapon;
}
// Re-equip the new item. This could fail.
// First, we need it in our inventory.
if (!acquireItem(newweapon, &newweapon))
{
// Failed to acquire, drop on ground.
formatAndReport("%U <lack> room for %IU.", newweapon);
glbCurLevel->acquireItem(newweapon, getX(), getY(), 0);
}
else
{
// It is now in our inventory. Try to equip it,
// including failure messages!
actionEquip(newweapon->getX(), newweapon->getY(), ITEMSLOT_RHAND);
}
break;
}
case NUM_PUNISHS:
{
// Confusion!
buf.sprintf("%s wails in confusion. ",
glb_goddefs[god].name);
msg_announce(buf);
break;
}
}
}
bool
MOB::pietyBoonValid(BOON_NAMES boon)
{
ITEM *item;
bool haswater = false;
bool hascursed = false;
bool hasweapon = false;
bool hasarmour = false;
bool hasnonid = false;
// Check for items needed.
for (item = myInventory; item; item = item->getNext())
{
// Check for potential sanctify:
if ( item->getDefinition() == ITEM_WATER &&
!item->isBlessed())
haswater = true;
// Check if the item is an unided artifact or unided
// magic type.
if (!item->isIdentified() && item->getMagicType() != MAGICTYPE_NONE)
hasnonid = true;
if (item->getArtifact() && !item->isFullyIdentified())
hasnonid = true;
// Check for an uncursing.
if (item->isCursed() && item->getX() == 0)
hascursed = true;
if (item->getX() == 0 &&
item->getY() == ITEMSLOT_RHAND)
hasweapon = true;
if (item->getX() == 0 &&
(item->getY() == ITEMSLOT_LHAND ||
item->getY() == ITEMSLOT_HEAD ||
item->getY() == ITEMSLOT_BODY ||
item->getY() == ITEMSLOT_FEET))
hasarmour = true;
}
switch (boon)
{
case BOON_UNCURSE:
return hascursed;
case BOON_HEAL:
if (getHP() < getMaxHP() / 3)
return true;
return false;
case BOON_LICHFORM:
if (getHP() < getMaxHP() / 4)
return true;
return false;
case BOON_CURE:
return aiIsPoisoned();
case BOON_SANCTIFY:
return haswater;
case BOON_SURROUNDATTACK:
// Verify you are surrounded by a foe...
if (calculateFoesSurrounding() > 1)
{
return true;
}
break;
case BOON_UNSTONE:
// If you are turning to stone, and are not actively resisting
// turning to stone, then help.
return hasIntrinsic(INTRINSIC_STONING) &&
!hasIntrinsic(INTRINSIC_RESISTSTONING) &&
!hasIntrinsic(INTRINSIC_UNCHANGING);
case BOON_ENCHANT_WEAPON:
return hasweapon;
case BOON_ENCHANT_ARMOUR:
return hasarmour;
case BOON_GRANT_SPELL:
// TODO: Find if we have any holes in our spell schools.
return true;
// Trivially true boons:
case BOON_GIFT_WEAPON:
case BOON_GIFT_ARMOUR:
case BOON_GIFT_WAND:
case BOON_GIFT_SPELLBOOK:
case BOON_GIFT_STAFF:
return true;
case BOON_IDENTIFY:
return hasnonid;
case NUM_BOONS:
break;
}
return false;
}
void
MOB::pietyBoon(GOD_NAMES god)
{
BOON_NAMES valid[NUM_BOONS], boon;
int numvalid = 0;
BUF buf;
ITEM *item;
bool hasrescue = false;
// Run through the boons determining if they apply and if they
// can be paid for.
FOREACH_BOON(boon)
{
// See if we can afford the cost.
if (glb_boondefs[boon].points > glbGodPoints[god])
continue;