File: piety.cpp

package info (click to toggle)
powder 117-2
  • links: PTS
  • area: non-free
  • in suites: stretch
  • size: 10,576 kB
  • ctags: 3,545
  • sloc: cpp: 55,002; makefile: 541; sh: 258; objc: 245; ansic: 107; csh: 54
file content (1609 lines) | stat: -rw-r--r-- 34,310 bytes parent folder | download | duplicates (6)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
/*
 * 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;

	// See if this is a valid god.
	if (!strchr(glb_boondefs[boon].god, (char) god))
	    continue;

	// Check to see if it applies.  Eg, no point curing
	// someone not poisoned.
	if (pietyBoonValid(boon))
	{
	    if (hasrescue && !glb_boondefs[boon].isrescue)
		continue;

	    if (glb_boondefs[boon].isrescue && !hasrescue)
	    {
		hasrescue = true;
		numvalid = 0;
	    }
	    valid[numvalid++] = boon;
	}
    }

    // If no valid boons, quit.
    if (!numvalid)
	return;

    boon = valid[rand_choice(numvalid)];

    // Pay the cost.
    glbGodPoints[god] -= glb_boondefs[boon].points;

    // Do the boon:
    switch (boon)
    {
	case BOON_UNCURSE:
	    buf.sprintf("%s: Allow me to aid you.  ",
			    glb_goddefs[god].name);
	    msg_announce(buf);
	    receiveUncurse(false);
	    break;
	    
	case BOON_HEAL:
	    buf.sprintf("%s: Your flesh shall mend!  ",
			    glb_goddefs[god].name);
	    msg_announce(buf);
	    // Full heal
	    receiveHeal(getMaxHP() - getHP(), 0);
	    break;

	case BOON_LICHFORM:
	    buf.sprintf("%s: Show your devotion!  ",
			    glb_goddefs[god].name);
	    msg_announce(buf);
	    setTimedIntrinsic(0, INTRINSIC_LICHFORM, 2);
	    break;

	case BOON_SURROUNDATTACK:
	{
	    buf.sprintf("%s: You've proven your worth!",
			glb_goddefs[god].name);
	    msg_announce(buf);

	    int		dx, dy;

	    FORALL_4DIR(dx, dy)
	    {
		MOB		*mob;
		
		mob = glbCurLevel->getMob(getX()+dx, getY()+dy);

		if (mob && mob->getAttitude(this) == ATTITUDE_HOSTILE)
		{
		    mob->receiveAttack(ATTACK_SURROUNDSMITE, 0, 0, 0,
					    ATTACKSTYLE_SPELL);
		}
	    }
	    break;
	}

	case BOON_CURE:
	    buf.sprintf("%s: Your affliction pains me!  ",
			    glb_goddefs[god].name);
	    msg_announce(buf);

	    receiveCure();
	    break;
	    
	case BOON_UNSTONE:
	    buf.sprintf("%s: I wish no more statues.  ",
			    glb_goddefs[god].name);
	    msg_announce(buf);

	    clearIntrinsic(INTRINSIC_STONING);
	    setTimedIntrinsic(0, INTRINSIC_RESISTSTONING, 10);
	    break;

	case BOON_SANCTIFY:
	{
	    buf.sprintf("%s: Your water is blessed!  ",
			    glb_goddefs[god].name);
	    msg_announce(buf);

	    for (item = myInventory; item; item = item->getNext())
	    {
		if (item->getDefinition() == ITEM_WATER)
		{
		    // Twice to ensure we end up at blessed status.
		    item->makeBlessed();
		    item->makeBlessed();
		    // It is rather obvious that the water must now be
		    // holy water.
		    item->markCursedKnown();
		}
	    }
	    
	    break;
	}

	case BOON_ENCHANT_WEAPON:
	{
	    buf.sprintf("%s: You are my weapon: Cut Deeply!  ",
		    glb_goddefs[god].name);
	    msg_announce(buf);

	    receiveWeaponEnchant(1, false);
	    break;
	}

	case BOON_ENCHANT_ARMOUR:
	{
	    buf.sprintf("%s: Accept my protection.  ",
		    glb_goddefs[god].name);
	    msg_announce(buf);

	    receiveArmourEnchant((ITEMSLOT_NAMES) -1, 1, false);
	    break;
	}

	case BOON_GRANT_SPELL:
	{
	    buf.sprintf("%s: Knowledge is Power!  ",
			glb_goddefs[god].name);
	    msg_announce(buf);

	    // Random spell..
	    SPELL_NAMES			spell;

	    spell = findSpell(god);

	    if (spell == SPELL_NONE)
	    {
		// You are so cool you already know all
		// the spells you can!  Deity is suitably impressed.
		msg_announce("You already have knowledge.  Now gain power!  ");
		
		// Maximize MP.
		if (getMP() < getMaxMP())
		{
		    formatAndReport("%U <be> energized.");
		    myMP = getMaxMP();
		}

		// Bonus XP.
		formatAndReport("%U <gain> experience.");
		receiveExp(100);
	    }
	    else
		learnSpell(spell);
	    break;
	}

	case BOON_GIFT_WEAPON:
	case BOON_GIFT_ARMOUR:
	case BOON_GIFT_WAND:
	case BOON_GIFT_SPELLBOOK:
	case BOON_GIFT_STAFF:
	{
	    buf.sprintf("%s: Use my gift wisely.  ",
			glb_goddefs[god].name);
	    msg_announce(buf);

	    ITEM		*gift;

	    gift = ITEM::createRandomType((ITEMTYPE_NAMES) 
					    glb_boondefs[boon].gifttype);

	    // Ensure it is blessed and a +3 enchant.
	    gift->makeBlessed();
	    gift->makeBlessed();
	    
	    gift->enchant(3 - gift->getEnchantment());

	    // Drop at feet:
	    buf = formatToString("%IU <I:appear> by %R %B1.",
		    this, 0, 0, gift,
		    getSlotName(ITEMSLOT_FEET) ?
			    getSlotName(ITEMSLOT_FEET) :
			    "shadow");
	    reportMessage(buf);

	    glbCurLevel->acquireItem(gift, getX(), getY(), 0);
	    break;
	}

	case BOON_IDENTIFY:
	{
	    ITEMSTACK		 stack;
	    ITEM		*item;

	    buf.sprintf("%s: Know Your Tools!  ",
			glb_goddefs[god].name);
	    msg_announce(buf);
	    
	    for (item = myInventory; item; item = item->getNext())
	    {
		if (!item->isIdentified() && item->getMagicType() != MAGICTYPE_NONE)
		    stack.append(item);
		else if (item->getArtifact() && !item->isFullyIdentified())
		    stack.append(item);
	    }

	    UT_ASSERT(stack.entries());
	    if (!stack.entries())
		break;
	    
	    item = stack(rand_choice(stack.entries()));

	    if (isAvatar())
		item->markIdentified();
	    
	    formatAndReport("%U <gain> insight into the nature of %IU.", item);
	    break;
	}

	case NUM_BOONS:
	    // Should not occur.
	    break;
    }
}

void
MOB::pietyAnnounceWhimOfXom()
{
    // If you worship ><0|V|, you get a clue as to his new preference.
    if (glbChosenGod == GOD_CULTIST)
    {
	msg_announce(glb_goddefs[glbWhimOfXOM].whimofxom);
    }
}

void
MOB::pietyRungods()
{
    GOD_NAMES		god;

    // Only run the god code on the avatar.
    if (!isAvatar())
	return;

    // Update ><0|V|s whim.
    if (rand_chance(80))
	glbWhimOfXOMTimer--;

    if (!glbWhimOfXOMTimer)
    {
	glbWhimOfXOMTimer = rand_range(100, 200);
	glbWhimOfXOM = piety_randomnonxomgod();

	pietyAnnounceWhimOfXom();
    }

    // If we are worshipping no one god, we get no benefits or punishments.
    if (glbChosenGod == GOD_AGNOSTIC)
    {
	return;
    }

    if (glbFlameStrikeTimer)
    {
	glbFlameStrikeTimer--;

	if (!glbFlameStrikeTimer)
	{
	    BUF		buf;

	    buf.sprintf("%s: Suffer my Wrath!  ",
			glb_goddefs[glbFlameGod].name);
	    msg_announce(buf);

	    // Peform flamestrike.
	    // TODO: Have MOBs for placeholders for the gods.
	    receiveAttack(ATTACK_FLAMESTRIKE, 0, 0, 0,
				    ATTACKSTYLE_SPELL);
	    return;
	}
    }
	
    FOREACH_GOD(god)
    {
	// Fickle gods do not always act.
	// this is broken and should be continue, not return, or we bias
	// against later gods.
	if (!rand_choice(10))
	    return;
	if (glbGodPoints[god] > 100)
	{
	    // Consider granting a boon.
	    // TODO: Track number of levels gained and bias
	    // accordingly.
	    if (god == glbChosenGod || !rand_choice(50))
	    {
		if (glbPiety[god] > 0)
		    pietyBoon((GOD_NAMES) god);
		else
		    pietyPunish((GOD_NAMES) god);

		// Do not test anything else in case we died
		return;
	    }
	}
    }
}

void
MOB::pietyGainLevel()
{
    GOD_NAMES		 godlist[NUM_GODS], god;
    int			 numvalid = 0, i, choice, y;
    int			 aorb = 0;
    MOB			*base;
    SPELL_NAMES		 spell = (SPELL_NAMES) -1;
    BUF			 buf;
    SKILL_NAMES		 skill = SKILL_NONE;
    int			 newpts;

    base = myBaseType.getMob();

    const char *gainmsg[] =
    {
	"You have gained a level!  ",
	"Welcome to the next level.  ",
	"Level Up!  ",
	"You learn from experience.  ",
	"Another kill, Another level.  "
    };
    // This message announce helps avoid accidental button presses.
    msg_announce(gainmsg[rand_choice(5)]);

    // Report current god...
    BUF		curgod;
    curgod.sprintf("You currently worship %s.  ", glb_goddefs[glbChosenGod].name);
    msg_report(curgod);

    FOREACH_GOD(god)
    {
	// Is this a valid god?  Agnostic is always valid.
	if (god == GOD_AGNOSTIC ||
	    glbPiety[god] >= 10)
	{
	    godlist[numvalid++] = god;
	}
    }

    // Ask the user to pick a level.
    char		**menu;

    menu = new char *[numvalid+2];
    // First choice is a sentinel to insure rapid clickers don't get
    // get the wrong choice.
    menu[0] = "Select a god";
    for (i = 0; i < numvalid; i++)
    {
	if (godlist[i] != GOD_AGNOSTIC)
	{
	    // Give some detailed info about the god.
	    // I think providing both numbers is a bit confusing, so
	    // we'll stick with the Piety
	    menu[i+1] = new char [30];
	    sprintf(menu[i+1], "%-11s (%d)",
		    glb_goddefs[godlist[i]].classname,
		    glbPiety[godlist[i]]);
	}
	else
	    menu[i+1] = (char *) glb_goddefs[godlist[i]].classname;
    }
    menu[numvalid+1] = 0;

    while (1)
    {
	choice = gfx_selectmenu(30 - 20, 3, (const char **)menu, aorb);
	for (y = 3; y < 19; y++)
	    gfx_cleartextline(y);

	if (hamfake_forceQuit())
	{
	    // We sadly have to force-pick a god to be able
	    // to save successfully.  Adventurer is likely the safest.
	    god = GOD_AGNOSTIC;
	    break;
	}

	// Valid choices,,,,
	if (choice >= 1 && !aorb)
	{
	    BUF		godchoice;

	    // Fix off by one due to sentinel
	    choice--;

	    // User chose godlist[choice].
	    god = godlist[choice];

	    // Inform the user of their future decision.
	    // Display the info text.
	    encyc_viewentry("GOD", god);

	    godchoice.sprintf("Follow %s?", glb_goddefs[god].name);

	    // Verify user is serious.
	    if (gfx_yesnomenu(godchoice))
		break;
	}
    }

    // Wipe out our menu.
    for (i = 0; i < numvalid; i++)
    {
	if (godlist[i] != GOD_AGNOSTIC)
	{
	    delete [] menu[i+1];
	}
    }
    delete [] menu;

    glbChosenGod = god;
    
    formatAndReport("%U <worship> %B1.",
		glb_goddefs[god].name);

    // Add an exp level.
    myExpLevel++;

    // Add our health & magic.
    myHitDie += glb_goddefs[god].physical;

    // 3-5 points per level with a bias to 4.  Considered having it
    // controled by piety but that just forces people away from
    // experimentation.
    // 2d2+1
    newpts = rand_dice(glb_goddefs[god].physical*2, 2, glb_goddefs[god].physical);
    incrementMaxHP(newpts);

    if (base)
    {
	base->myHitDie += glb_goddefs[god].physical;
    }
    
    myMagicDie += glb_goddefs[god].mental;
    newpts = rand_dice(glb_goddefs[god].mental*2, 2, glb_goddefs[god].mental);
    incrementMaxMP(newpts);

    if (base)
    {
	base->myMagicDie += glb_goddefs[god].mental;
    }

    int		numskill = 0, numspell = 0;
    
    skill = findSkill(god, &numskill);
    spell = findSpell(god, &numspell);

    // You only get one of skill or spell, never both.
    // We bias according to the number of valid choices.
    if (spell != SPELL_NONE && skill != SKILL_NONE)
    {
	if (rand_choice(numspell + numskill) < numskill)
	    spell = SPELL_NONE;
	else
	    skill = SKILL_NONE;
    }

    // Special cases for gods...
    switch (god)
    {
	case GOD_CULTIST:
	{
	    // Gain random hit & magic dice.
	    int		phys, ment;

	    phys = rand_choice(5);
	    ment = rand_choice(5);
	    myHitDie += phys;
	    myMagicDie += ment;
	    if (base)
	    {
		base->myHitDie += phys;
		base->myMagicDie += ment;
	    }

	    phys = rand_choice(phys * 10);
	    ment = rand_choice(ment * 10);

	    incrementMaxHP(phys);
	    incrementMaxMP(ment);
	    break;
	}

	case GOD_WIZARD:
	{
	    break;
	}

	case GOD_CLERIC:
	{
	    break;
	}

	case GOD_NECRO:
	{
	    break;
	}

	case GOD_AGNOSTIC:
	{
	    // Do nothing!
	    break;
	}

	case GOD_FIGHTER:
	{
	    break;
	}

	case GOD_ROGUE:
	{
	    break;
	}

	case GOD_BARB:
	{
	    break;
	}

	case NUM_GODS:
	{
	    break;
	}
    }

    learnSpell(spell);
    learnSkill(skill);

    // Report number of free slots
    buf.sprintf("You have %d free spell and %d free skill slots.",
		    getFreeSpellSlots(),
		    getFreeSkillSlots());
    reportMessage(buf);

    // If you just started following Xom, pretty important.
    pietyAnnounceWhimOfXom();
}

void
MOB::pietyReport()
{
    char		*menu[NUM_GODS + 1];
    int			 dressiness[NUM_GODS];

    int			 i, aorb;
    GOD_NAMES		 god;

    determineClassiness(dressiness);

    FOREACH_GOD(god)
    {
	menu[god] = new char[30];

	sprintf(menu[god], "%10s: %d (%d)",
		glb_goddefs[god].name,
		glbPiety[god],
		glbGodPoints[god]);
	if (dressiness[god])
	{
	    // Pad out a tad
	    strcat(menu[god], " ");
	}
	for (int i = 2; i <= dressiness[god]; i+=2)
	    strcat(menu[god], "*");
	if (dressiness[god] & 1)
	    strcat(menu[god], "+");
    }
    menu[NUM_GODS] = 0;

    {
	BUF		buf;
	buf.sprintf("Now Worshipping: %s", glb_goddefs[glbChosenGod].name);
	gfx_printtext(2, 4, buf.buffer());
    }

    gfx_selectmenu(5, 6, (const char **) menu, aorb, glbChosenGod);

    // And clear it...
    for (i = 3; i < 18; i++)
    {
	gfx_cleartextline(i);
    }

    for (i = 0; i < NUM_GODS; i++)
	delete [] menu[i];
}