Revert "Track who destroys an item; incur Nemelex penance for deck destruction."
[crawl.git] / crawl-ref / source / godconduct.cc
1 #include "AppHdr.h"
2
3 #include "godconduct.h"
4
5 #include "fight.h"
6 #include "godwrath.h"
7 #include "libutil.h"
8 #include "monster.h"
9 #include "mon-util.h"
10 #include "player.h"
11 #include "random.h"
12 #include "religion.h"
13 #include "state.h"
14
15 /////////////////////////////////////////////////////////////////////
16 // god_conduct_trigger
17
18 god_conduct_trigger::god_conduct_trigger(
19     conduct_type c, int pg, bool kn, const monster* vict)
20   : conduct(c), pgain(pg), known(kn), enabled(true), victim(nullptr)
21 {
22     if (vict)
23     {
24         victim.reset(new monster);
25         *(victim.get()) = *vict;
26     }
27 }
28
29 void god_conduct_trigger::set(conduct_type c, int pg, bool kn,
30                               const monster* vict)
31 {
32     conduct = c;
33     pgain = pg;
34     known = kn;
35     victim.reset(NULL);
36     if (vict)
37     {
38         victim.reset(new monster);
39         *victim.get() = *vict;
40     }
41 }
42
43 god_conduct_trigger::~god_conduct_trigger()
44 {
45     if (enabled && conduct != NUM_CONDUCTS)
46         did_god_conduct(conduct, pgain, known, victim.get());
47 }
48
49 // This function is the merger of done_good() and naughty().
50 // Returns true if god was interested (good or bad) in conduct.
51 bool did_god_conduct(conduct_type thing_done, int level, bool known,
52                      const monster* victim)
53 {
54     ASSERT(!crawl_state.game_is_arena());
55
56     bool retval = false;
57
58     if (you.religion != GOD_NO_GOD && you.religion != GOD_XOM
59         && (you.religion != GOD_LUGONU || !player_in_branch(BRANCH_ABYSS)))
60     {
61         int piety_change = 0;
62         int piety_denom = 1;
63         int penance = 0;
64
65         god_acting gdact;
66
67         switch (thing_done)
68         {
69         case DID_DRINK_BLOOD:
70             switch (you.religion)
71             {
72             case GOD_ZIN:
73             case GOD_SHINING_ONE:
74             case GOD_ELYVILON:
75                 if (!known)
76                 {
77                     simple_god_message(" forgives your inadvertent "
78                                        "blood-drinking, just this once.");
79                     break;
80                 }
81                 if (you.religion == GOD_SHINING_ONE)
82                     penance = level;
83                 piety_change = -2*level;
84                 retval = true;
85                 break;
86             default:
87                 break;
88             }
89             break;
90
91         case DID_CANNIBALISM:
92             switch (you.religion)
93             {
94             case GOD_ZIN:
95             case GOD_SHINING_ONE:
96             case GOD_ELYVILON:
97             case GOD_BEOGH:
98                 piety_change = -level;
99                 penance = level;
100                 retval = true;
101                 break;
102             default:
103                 break;
104             }
105             break;
106
107         case DID_CORPSE_VIOLATION:
108             if (you.religion == GOD_FEDHAS)
109             {
110                 if (known)
111                 {
112                     piety_change = -level;
113                     penance = level;
114                     retval = true;
115                 }
116                 else
117                 {
118                     simple_god_message(" forgives your inadvertent necromancy, "
119                                        "just this once.");
120                 }
121             }
122             break;
123
124         case DID_DESECRATE_HOLY_REMAINS:
125             if (you.religion == GOD_YREDELEMNUL)
126             {
127                 simple_god_message(" appreciates your desecration of holy "
128                                    "remains.");
129                 retval = true;
130                 piety_change = 1;
131                 break;
132             }
133             // deliberate fall through
134
135         case DID_NECROMANCY:
136         case DID_UNHOLY:
137         case DID_ATTACK_HOLY:
138             switch (you.religion)
139             {
140             case GOD_ZIN:
141             case GOD_SHINING_ONE:
142             case GOD_ELYVILON:
143                 if (!known && thing_done != DID_ATTACK_HOLY
144                     && thing_done != DID_DESECRATE_HOLY_REMAINS)
145                 {
146                     simple_god_message(" forgives your inadvertent unholy act, "
147                                        "just this once.");
148                     break;
149                 }
150
151                 if (thing_done == DID_ATTACK_HOLY
152                     && victim
153                     && !testbits(victim->flags, MF_NO_REWARD)
154                     && !testbits(victim->flags, MF_WAS_NEUTRAL))
155                 {
156                     break;
157                 }
158
159                 piety_change = -level;
160                 penance = level * ((you.religion == GOD_SHINING_ONE) ? 2
161                                                                      : 1);
162                 retval = true;
163                 break;
164             default:
165                 break;
166             }
167             break;
168
169         case DID_HOLY:
170             if (you.religion == GOD_YREDELEMNUL)
171             {
172                 if (!known)
173                 {
174                     simple_god_message(" forgives your inadvertent holy act, "
175                                        "just this once.");
176                     break;
177                 }
178                 retval = true;
179                 piety_change = -level;
180                 penance = level * 2;
181             }
182             break;
183
184         case DID_UNCHIVALRIC_ATTACK:
185         case DID_POISON:
186             if (you.religion == GOD_SHINING_ONE)
187             {
188                 if (thing_done == DID_UNCHIVALRIC_ATTACK)
189                 {
190                     if (victim && tso_unchivalric_attack_safe_monster(victim))
191                         break;
192
193                     if (!known)
194                     {
195                         simple_god_message(" forgives your inadvertent "
196                                            "dishonourable attack, just this "
197                                            "once.");
198                         break;
199                     }
200                 }
201                 retval = true;
202                 piety_change = -level;
203                 penance = level * 2;
204             }
205             break;
206
207        case DID_KILL_SLIME:
208             if (you.religion == GOD_JIYVA && !victim->is_shapeshifter())
209             {
210                 retval = true;
211                 piety_change = -level;
212                 penance = level * 2;
213             }
214             break;
215
216        case DID_KILL_PLANT:
217        case DID_PLANT_KILLED_BY_SERVANT:
218             // Piety loss but no penance for killing a plant.
219             if (you.religion == GOD_FEDHAS)
220             {
221                 retval = true;
222                 piety_change = -level;
223             }
224             break;
225
226         case DID_ATTACK_NEUTRAL:
227             switch (you.religion)
228             {
229             case GOD_SHINING_ONE:
230             case GOD_ELYVILON:
231                 if (!known)
232                 {
233                     simple_god_message(" forgives your inadvertent attack on a "
234                                        "neutral, just this once.");
235                     break;
236                 }
237                 penance = level/2 + 1;
238                 // deliberate fall through
239
240             case GOD_ZIN:
241                 if (!known)
242                 {
243                     simple_god_message(" forgives your inadvertent attack on a "
244                                        "neutral, just this once.");
245                     break;
246                 }
247                 piety_change = -(level/2 + 1);
248                 retval = true;
249                 break;
250
251             case GOD_JIYVA:
252                 if (victim && mons_is_slime(victim)
253                     && !victim->is_shapeshifter())
254                 {
255                     piety_change = -(level/2 + 3);
256                     penance = level/2 + 3;
257                     retval = true;
258                 }
259                 break;
260
261             default:
262                 break;
263             }
264             break;
265
266         case DID_ATTACK_FRIEND:
267             if (god_hates_attacking_friend(you.religion, victim))
268             {
269                 if (!known)
270                 {
271                     simple_god_message(" forgives your inadvertent attack on "
272                                        "an ally, just this once.");
273                     break;
274                 }
275
276                 piety_change = -level;
277                 if (known)
278                     penance = level * 3;
279                 retval = true;
280             }
281             break;
282
283         case DID_FRIEND_DIED:
284         case DID_SOULED_FRIEND_DIED:
285             if (victim && you.religion != GOD_FEDHAS
286                 && (victim->holiness() == MH_NONLIVING
287                     || victim->holiness() == MH_PLANT))
288             {
289                 // For everyone but Fedhas, plants are items not creatures,
290                 // and animated items are, well, items as well.
291                 break;
292             }
293
294             switch (you.religion)
295             {
296             case GOD_FEDHAS:
297                 // Ballistomycetes dying is penalised separately.
298                 if (victim && fedhas_protects(victim)
299                     && victim->mons_species() != MONS_BALLISTOMYCETE)
300                 {
301                     // level is (1 + monsterHD/2) for this conduct,
302                     // trying a fixed cost since plant HD aren't that
303                     // meaningful. -cao
304                     piety_change = -1;
305                     retval = true;
306                     break;
307                 }
308                 break;
309
310             case GOD_ELYVILON:
311                 // Converted allies (marked as TSOites) can be martyrs.
312                 if (victim && victim->god == GOD_SHINING_ONE)
313                     break;
314
315                 piety_change = -(level/2 + 1);
316                 retval = true;
317                 break;
318
319             case GOD_ZIN:
320                 // Converted allies (marked as TSOites) can be martyrs.
321                 if (victim && victim->god == GOD_SHINING_ONE)
322                     break;
323
324                 // Zin only cares about the deaths of those with souls.
325                 if (thing_done == DID_FRIEND_DIED)
326                     break;
327                 // fall through
328
329             case GOD_OKAWARU:
330                 piety_change = -level;
331                 retval = true;
332                 break;
333
334             default:
335                 break;
336             }
337             break;
338
339         case DID_BANISH:
340             if (you.religion != GOD_LUGONU)
341                 break;
342         case DID_KILL_LIVING:
343             switch (you.religion)
344             {
345             case GOD_ELYVILON:
346                 // Killing is only disapproved of during prayer.
347                 if (you.duration[DUR_LIFESAVING])
348                 {
349                     simple_god_message(" does not appreciate your shedding "
350                                        "blood when asking for salvation!");
351                     retval = true;
352                     piety_change = -level;
353                     penance = level * 2;
354                 }
355                 break;
356
357             case GOD_KIKUBAAQUDGHA:
358             case GOD_YREDELEMNUL:
359             case GOD_VEHUMET:
360             case GOD_MAKHLEB:
361             case GOD_TROG:
362             case GOD_BEOGH:
363             case GOD_LUGONU:
364                 if (god_hates_attacking_friend(you.religion, victim))
365                     break;
366
367                 if (thing_done == DID_BANISH)
368                     simple_god_message(" claims a new guest.");
369                 else
370                     simple_god_message(" accepts your kill.");
371                 retval = true;
372                 piety_denom = level + 18 - you.experience_level / 2;
373                 piety_change = piety_denom - 6;
374                 piety_denom = max(piety_denom, 1);
375                 piety_change = max(piety_change, 0);
376                 break;
377
378             default:
379                 break;
380             }
381             break;
382
383         case DID_KILL_UNDEAD:
384             switch (you.religion)
385             {
386             case GOD_SHINING_ONE:
387             case GOD_VEHUMET:
388             case GOD_MAKHLEB:
389             case GOD_BEOGH:
390             case GOD_LUGONU:
391                 if (god_hates_attacking_friend(you.religion, victim))
392                     break;
393
394                 simple_god_message(" accepts your kill.");
395                 retval = true;
396                 // Holy gods are easier to please this way.
397                 piety_denom = level + 18 - (is_good_god(you.religion) ? 0 :
398                                           you.experience_level / 2);
399                 piety_change = piety_denom - 5;
400                 piety_denom = max(piety_denom, 1);
401                 piety_change = max(piety_change, 0);
402                 break;
403
404             default:
405                 break;
406             }
407             break;
408
409         case DID_KILL_DEMON:
410             switch (you.religion)
411             {
412             case GOD_SHINING_ONE:
413             case GOD_VEHUMET:
414             case GOD_MAKHLEB:
415             case GOD_TROG:
416             case GOD_KIKUBAAQUDGHA:
417             case GOD_BEOGH:
418             case GOD_LUGONU:
419                 if (god_hates_attacking_friend(you.religion, victim))
420                     break;
421
422                 simple_god_message(" accepts your kill.");
423                 retval = true;
424                 // Holy gods are easier to please this way.
425                 piety_denom = level + 18 - (is_good_god(you.religion) ? 0 :
426                                           you.experience_level / 2);
427                 piety_change = piety_denom - 4;
428                 piety_denom = max(piety_denom, 1);
429                 piety_change = max(piety_change, 0);
430                 break;
431
432             default:
433                 break;
434             }
435             break;
436
437         case DID_KILL_NATURAL_UNHOLY:
438         case DID_KILL_NATURAL_EVIL:
439             if (you.religion == GOD_SHINING_ONE
440                 && !god_hates_attacking_friend(you.religion, victim))
441             {
442                 simple_god_message(" accepts your kill.");
443                 retval = true;
444                 piety_denom = level + 18;
445                 piety_change = piety_denom - 4;
446             }
447             break;
448
449         case DID_KILL_UNCLEAN:
450         case DID_KILL_CHAOTIC:
451             if (you.religion == GOD_ZIN
452                 && !god_hates_attacking_friend(you.religion, victim))
453             {
454                 simple_god_message(" accepts your kill.");
455                 retval = true;
456                 piety_denom = level + 18;
457                 piety_change = piety_denom - 4;
458             }
459             break;
460
461         case DID_KILL_PRIEST:
462             if (you.religion == GOD_BEOGH
463                 && !god_hates_attacking_friend(you.religion, victim))
464             {
465                 simple_god_message(" appreciates your killing of a heretic "
466                                    "priest.");
467                 retval = true;
468                 piety_denom = level + 10;
469                 piety_change = piety_denom - 6;
470             }
471             break;
472
473         case DID_KILL_WIZARD:
474             if (you.religion == GOD_TROG
475                 && !god_hates_attacking_friend(you.religion, victim))
476             {
477                 simple_god_message(" appreciates your killing of a magic "
478                                    "user.");
479                 retval = true;
480                 piety_denom = level + 10;
481                 piety_change = piety_denom - 6;
482             }
483             break;
484
485         case DID_KILL_FAST:
486             if (you.religion == GOD_CHEIBRIADOS
487                 && !god_hates_attacking_friend(you.religion, victim))
488             {
489                 retval = true;
490                 piety_denom = level + 18 - you.experience_level / 2;
491                 piety_change = piety_denom - 6;
492                 piety_denom = max(piety_denom, 1);
493                 piety_change = max(piety_change, 0);
494
495                 const int speed_delta =
496                     cheibriados_monster_player_speed_delta(victim);
497                 dprf("Che DID_KILL_FAST: %s speed delta: %d",
498                      victim->name(DESC_PLAIN, true).c_str(),
499                      speed_delta);
500                 if (speed_delta > 0 && x_chance_in_y(speed_delta, 12))
501                 {
502                     piety_change *= 2;
503                     simple_god_message(" thoroughly appreciates the change of pace.");
504                 }
505                 else
506                     simple_god_message(" appreciates the change of pace.");
507             }
508             break;
509
510         case DID_KILL_ARTIFICIAL:
511             if (you.religion == GOD_YREDELEMNUL
512                 && !god_hates_attacking_friend(you.religion, victim))
513             {
514                 simple_god_message(" accepts your kill.");
515                 retval = true;
516                 piety_denom = level + 18;
517                 piety_change = piety_denom - 3;
518             }
519             break;
520
521         // Note that holy deaths are special, they are always noticed...
522         // If you or any friendly kills one, you'll get the credit or
523         // the blame.
524         case DID_KILL_HOLY:
525             switch (you.religion)
526             {
527             case GOD_ZIN:
528             case GOD_SHINING_ONE:
529             case GOD_ELYVILON:
530                 if (victim
531                     && !testbits(victim->flags, MF_NO_REWARD)
532                     && !testbits(victim->flags, MF_WAS_NEUTRAL))
533                 {
534                     break;
535                 }
536
537                 penance = level * 3;
538                 piety_change = -level * 3;
539                 retval = true;
540                 break;
541
542             case GOD_YREDELEMNUL:
543             case GOD_KIKUBAAQUDGHA:
544             case GOD_TROG:
545             case GOD_VEHUMET:
546             case GOD_MAKHLEB:
547             case GOD_BEOGH:
548             case GOD_LUGONU:
549                 if (god_hates_attacking_friend(you.religion, victim))
550                     break;
551
552                 simple_god_message(" accepts your kill.");
553                 retval = true;
554                 piety_denom = level + 18;
555                 piety_change = piety_denom - 3;
556
557                 if (you.religion == GOD_YREDELEMNUL)
558                 {
559                     simple_god_message(" appreciates your killing of a holy "
560                                        "being.");
561                     piety_change *= 2;
562                 }
563                 break;
564
565             default:
566                 break;
567             }
568             break;
569
570         case DID_HOLY_KILLED_BY_UNDEAD_SLAVE:
571             switch (you.religion)
572             {
573             case GOD_YREDELEMNUL:
574             case GOD_KIKUBAAQUDGHA:
575             case GOD_MAKHLEB:
576             case GOD_BEOGH:
577             case GOD_LUGONU:
578                 if (god_hates_attacking_friend(you.religion, victim))
579                     break;
580
581                 simple_god_message(" accepts your slave's kill.");
582                 retval = true;
583                 piety_denom = level + 18;
584                 piety_change = piety_denom - 3;
585                 break;
586
587             default:
588                 break;
589             }
590             break;
591
592         case DID_HOLY_KILLED_BY_SERVANT:
593             switch (you.religion)
594             {
595             case GOD_ZIN:
596             case GOD_SHINING_ONE:
597             case GOD_ELYVILON:
598                 if (victim
599                     && !testbits(victim->flags, MF_NO_REWARD)
600                     && !testbits(victim->flags, MF_WAS_NEUTRAL))
601                 {
602                     break;
603                 }
604
605                 penance = level * 3;
606                 piety_change = -level * 3;
607                 retval = true;
608                 break;
609
610             case GOD_TROG:
611             case GOD_MAKHLEB:
612             case GOD_BEOGH:
613             case GOD_LUGONU:
614                 if (god_hates_attacking_friend(you.religion, victim))
615                     break;
616
617                 simple_god_message(" accepts your collateral kill.");
618                 retval = true;
619                 piety_denom = level + 18;
620                 piety_change = piety_denom - 3;
621                 break;
622
623             default:
624                 break;
625             }
626             break;
627
628         case DID_LIVING_KILLED_BY_UNDEAD_SLAVE:
629             switch (you.religion)
630             {
631             case GOD_YREDELEMNUL:
632             case GOD_KIKUBAAQUDGHA:
633             case GOD_MAKHLEB:
634             case GOD_BEOGH:
635             case GOD_LUGONU:
636                 simple_god_message(" accepts your slave's kill.");
637                 retval = true;
638                 piety_denom = level + 10 - you.experience_level/3;
639                 piety_change = piety_denom - 6;
640                 piety_denom = max(piety_denom, 1);
641                 piety_change = max(piety_change, 0);
642                 break;
643             default:
644                 break;
645             }
646             break;
647
648         case DID_LIVING_KILLED_BY_SERVANT:
649             switch (you.religion)
650             {
651             case GOD_MAKHLEB:
652             case GOD_TROG:
653             case GOD_BEOGH:
654             case GOD_LUGONU:
655                 simple_god_message(" accepts your collateral kill.");
656                 retval = true;
657                 piety_denom = level + 10 - you.experience_level/3;
658                 piety_change = piety_denom - 6;
659                 piety_denom = max(piety_denom, 1);
660                 piety_change = max(piety_change, 0);
661                 break;
662             default:
663                 break;
664             }
665             break;
666
667         case DID_UNDEAD_KILLED_BY_UNDEAD_SLAVE:
668             switch (you.religion)
669             {
670             case GOD_MAKHLEB:
671             case GOD_BEOGH:
672             case GOD_LUGONU:
673                 simple_god_message(" accepts your slave's kill.");
674                 retval = true;
675                 piety_denom = level + 10 - you.experience_level/3;
676                 piety_change = piety_denom - 6;
677                 piety_denom = max(piety_denom, 1);
678                 piety_change = max(piety_change, 0);
679                 break;
680             default:
681                 break;
682             }
683             break;
684
685         case DID_UNDEAD_KILLED_BY_SERVANT:
686             switch (you.religion)
687             {
688             case GOD_SHINING_ONE:
689             case GOD_MAKHLEB:
690             case GOD_BEOGH:
691             case GOD_LUGONU:
692                 simple_god_message(" accepts your collateral kill.");
693                 retval = true;
694                 piety_denom = level + 10 - (is_good_god(you.religion) ? 0 :
695                                             you.experience_level/3);
696                 piety_change = piety_denom - 6;
697                 piety_denom = max(piety_denom, 1);
698                 piety_change = max(piety_change, 0);
699                 break;
700             default:
701                 break;
702             }
703             break;
704
705         case DID_DEMON_KILLED_BY_UNDEAD_SLAVE:
706             switch (you.religion)
707             {
708             case GOD_KIKUBAAQUDGHA:
709             case GOD_MAKHLEB:
710             case GOD_BEOGH:
711             case GOD_LUGONU:
712                 simple_god_message(" accepts your slave's kill.");
713                 retval = true;
714                 piety_denom = level + 10 - you.experience_level/3;
715                 piety_change = piety_denom - 6;
716                 piety_denom = max(piety_denom, 1);
717                 piety_change = max(piety_change, 0);
718                 break;
719             default:
720                 break;
721             }
722             break;
723
724         case DID_DEMON_KILLED_BY_SERVANT:
725             switch (you.religion)
726             {
727             case GOD_SHINING_ONE:
728             case GOD_MAKHLEB:
729             case GOD_TROG:
730             case GOD_BEOGH:
731             case GOD_LUGONU:
732                 simple_god_message(" accepts your collateral kill.");
733                 retval = true;
734                 piety_denom = level + 10 - (is_good_god(you.religion) ? 0 :
735                                             you.experience_level/3);
736                 piety_change = piety_denom - 6;
737                 piety_denom = max(piety_denom, 1);
738                 piety_change = max(piety_change, 0);
739                 break;
740             default:
741                 break;
742             }
743             break;
744
745         case DID_NATURAL_UNHOLY_KILLED_BY_SERVANT:
746         case DID_NATURAL_EVIL_KILLED_BY_SERVANT:
747             if (you.religion == GOD_SHINING_ONE)
748             {
749                 simple_god_message(" accepts your collateral kill.");
750                 retval = true;
751                 piety_denom = level + 10;
752                 piety_change = piety_denom - 6;
753             }
754             break;
755
756         case DID_UNCLEAN_KILLED_BY_SERVANT:
757         case DID_CHAOTIC_KILLED_BY_SERVANT:
758             if (you.religion == GOD_ZIN)
759             {
760                 simple_god_message(" accepts your collateral kill.");
761                 retval = true;
762
763                 piety_denom = level + 10;
764                 piety_change = piety_denom - 6;
765             }
766             break;
767
768         case DID_ARTIFICIAL_KILLED_BY_UNDEAD_SLAVE:
769             if (you.religion == GOD_YREDELEMNUL)
770             {
771                 simple_god_message(" accepts your slave's kill.");
772                 retval = true;
773                 piety_denom = level + 18;
774                 piety_change = piety_denom - 3;
775             }
776             break;
777
778         // Currently used only when confused undead kill artificial
779         // beings, which Yredelemnul doesn't care about.
780         case DID_ARTIFICIAL_KILLED_BY_SERVANT:
781             break;
782
783         case DID_SPELL_MEMORISE:
784             if (you.religion == GOD_TROG)
785             {
786                 penance = level * 10;
787                 piety_change = -penance;
788                 retval = true;
789             }
790             break;
791
792         case DID_SPELL_CASTING:
793             if (you.religion == GOD_TROG)
794             {
795                 piety_change = -level;
796                 penance = level * 5;
797                 retval = true;
798             }
799             break;
800
801         case DID_SPELL_PRACTISE:
802             // Like CAST, but for skill advancement.
803             // Level is number of skill points gained...
804             // typically 10 * exercise, but may be more/less if the
805             // skill is at 0 (INT adjustment), or if the PC's pool is
806             // low and makes change.
807             if (you.religion == GOD_SIF_MUNA)
808             {
809                 piety_change = level;
810                 piety_denom = 40;
811                 retval = true;
812             }
813             else if (you.religion == GOD_TROG)
814             {
815                 simple_god_message(" doesn't appreciate your training magic!");
816                 piety_change = -level;
817                 piety_denom = 10;
818                 retval = true;
819             }
820             break;
821
822         case DID_CARDS:
823             if (you.religion == GOD_NEMELEX_XOBEH)
824             {
825                 piety_change = level;
826                 retval = true;
827
828                 // level == 0: stacked, deck not used up
829                 // level == 1: used up or nonstacked
830                 // level == 2: used up and nonstacked
831                 // and there's a 1/3 chance of an additional bonus point
832                 // for nonstacked cards.
833                 int chance = 0;
834                 switch (level)
835                 {
836                 case 0: chance = 0;   break;
837                 case 1: chance = 40;  break;
838                 case 2: chance = 70;  break;
839                 default:
840                 case 3: chance = 100; break;
841                 }
842
843                 if (x_chance_in_y(chance, 100)
844                     && you.attribute[ATTR_CARD_COUNTDOWN])
845                 {
846                     you.attribute[ATTR_CARD_COUNTDOWN]--;
847 #if defined(DEBUG_DIAGNOSTICS) || defined(DEBUG_CARDS) || defined(DEBUG_GIFTS)
848                     mprf(MSGCH_DIAGNOSTICS, "Countdown down to %d",
849                          you.attribute[ATTR_CARD_COUNTDOWN]);
850 #endif
851                 }
852             }
853             break;
854
855         case DID_CAUSE_GLOWING:
856         case DID_DELIBERATE_MUTATING:
857             if (you.religion == GOD_ZIN)
858             {
859                 if (!known && thing_done != DID_CAUSE_GLOWING)
860                 {
861                     simple_god_message(" forgives your inadvertent chaotic "
862                                        "act, just this once.");
863                     break;
864                 }
865
866                 if (thing_done == DID_CAUSE_GLOWING)
867                 {
868                     static int last_glowing_lecture = -1;
869                     if (!level)
870                     {
871                         simple_god_message(" is not enthusiastic about the "
872                                            "mutagenic glow surrounding you.");
873                     }
874                     else if (last_glowing_lecture != you.num_turns)
875                     {
876                         last_glowing_lecture = you.num_turns;
877                         // Increase contamination within yellow glow.
878                         simple_god_message(" does not appreciate the extra "
879                                            "mutagenic glow surrounding you!");
880                     }
881                 }
882
883                 piety_change = -level;
884                 retval = true;
885             }
886             break;
887
888         // level depends on intelligence: normal -> 1, high -> 2
889         // cannibalism is still worse
890         case DID_EAT_SOULED_BEING:
891             if (you.religion == GOD_ZIN)
892             {
893                 piety_change = -level * 5;
894                 if (level > 1)
895                     penance = 5;
896                 retval = true;
897             }
898             break;
899
900         case DID_UNCLEAN:
901             if (you.religion == GOD_ZIN)
902             {
903                 retval = true;
904                 if (!known)
905                 {
906                     simple_god_message(" forgives your inadvertent unclean "
907                                        "act, just this once.");
908                     break;
909                 }
910                 piety_change = -level;
911                 penance      = level;
912             }
913             break;
914
915         case DID_CHAOS:
916             if (you.religion == GOD_ZIN)
917             {
918                 retval = true;
919                 if (!known)
920                 {
921                     simple_god_message(" forgives your inadvertent chaotic "
922                                        "act, just this once.");
923                     break;
924                 }
925                 piety_change = -level;
926                 penance      = level;
927             }
928             break;
929
930         case DID_ATTACK_IN_SANCTUARY:
931             if (you.religion == GOD_ZIN)
932             {
933                 piety_change = -level;
934                 retval = true;
935             }
936             break;
937
938         case DID_DESECRATE_ORCISH_REMAINS:
939             if (you.religion == GOD_BEOGH)
940             {
941                 piety_change = -level;
942                 retval = true;
943             }
944             break;
945
946         case DID_DESTROY_ORCISH_IDOL:
947             if (you.religion == GOD_BEOGH)
948             {
949                 piety_change = -level;
950                 penance = level * 3;
951                 retval = true;
952             }
953             break;
954
955         case DID_HASTY:
956             if (you.religion == GOD_CHEIBRIADOS)
957             {
958                 if (!known)
959                 {
960                     simple_god_message(" forgives your accidental hurry, just this once.");
961                     break;
962                 }
963                 simple_god_message(" thinks you should slow down.");
964                 piety_change = -level;
965                 if (level > 5)
966                     penance = level - 5;
967                 retval = true;
968             }
969             break;
970
971         case DID_DESTROY_SPELLBOOK:
972             if (you.religion == GOD_SIF_MUNA)
973             {
974                 piety_change = -level;
975                 penance = level * (known ? 2 : 1);
976                 retval = true;
977             }
978             break;
979
980         case DID_EXPLORATION:
981             if (you.religion == GOD_ASHENZARI)
982             {
983                 const int base_gain = 6; // base gain per dungeon level
984                 // levels: x1, x1.5, x2, x2.5, x3
985                 piety_change = base_gain + base_gain * you.bondage_level / 2;
986                 piety_denom = level;
987                 retval = true;
988             }
989             break;
990
991         case DID_SEE_MONSTER:
992             if (you.religion == GOD_SHINING_ONE)
993             {
994                 if (victim && (victim->is_evil() || victim->is_unholy()))
995                     break;
996                 piety_denom = level / 2 + 6 - you.experience_level / 4;
997                 piety_change = piety_denom - 4;
998                 piety_denom = max(piety_denom, 1);
999                 piety_change = max(piety_change, 0);
1000                 retval = true;
1001             }
1002             break;
1003
1004         case DID_NOTHING:
1005         case NUM_CONDUCTS:
1006             break;
1007         }
1008
1009         if (you.religion == GOD_OKAWARU
1010             // currently no constructs and plants
1011             && (thing_done == DID_KILL_LIVING
1012                 || thing_done == DID_KILL_UNDEAD
1013                 || thing_done == DID_KILL_DEMON
1014                 || thing_done == DID_KILL_HOLY)
1015             && !god_hates_attacking_friend(you.religion, victim))
1016         {
1017             piety_change = get_fuzzied_monster_difficulty(victim);
1018             dprf("fuzzied monster difficulty: %4.2f", piety_change * 0.01);
1019             piety_denom = 700;
1020             if (piety_change > 3200)
1021                 simple_god_message(" appreciates your kill.");
1022             else if (piety_change > 9) // might still be miniscule
1023                 simple_god_message(" accepts your kill.");
1024             retval = true;
1025         }
1026
1027 #ifdef DEBUG_DIAGNOSTICS
1028         int old_piety = you.piety;
1029 #endif
1030
1031         if (piety_change > 0)
1032             gain_piety(piety_change, piety_denom);
1033         else
1034             dock_piety(div_rand_round(-piety_change, piety_denom), penance);
1035
1036 #ifdef DEBUG_DIAGNOSTICS
1037         // don't announce exploration piety unless you actually got a boost
1038         if (retval && (thing_done != DID_EXPLORATION || old_piety != you.piety))
1039         {
1040             static const char *conducts[] =
1041             {
1042                 "",
1043                 "Necromancy", "Holy", "Unholy", "Attack Holy", "Attack Neutral",
1044                 "Attack Friend", "Friend Died", "Unchivalric Attack",
1045                 "Poison", "Kill Living", "Kill Undead",
1046                 "Kill Demon", "Kill Natural Unholy", "Kill Natural Evil",
1047                 "Kill Unclean", "Kill Chaotic", "Kill Wizard", "Kill Priest",
1048                 "Kill Holy", "Kill Fast", "Undead Slave Kill Living",
1049                 "Servant Kill Living", "Undead Slave Kill Undead",
1050                 "Servant Kill Undead", "Undead Slave Kill Demon",
1051                 "Servant Kill Demon", "Servant Kill Natural Unholy",
1052                 "Servant Kill Natural Evil", "Undead Slave Kill Holy",
1053                 "Servant Kill Holy", "Banishment", "Spell Memorise", "Spell Cast",
1054                 "Spell Practise", "Cards",
1055                 "Drink Blood", "Cannibalism","Eat Souled Being",
1056                 "Deliberate Mutation", "Cause Glowing", "Use Unclean",
1057                 "Use Chaos", "Desecrate Orcish Remains", "Destroy Orcish Idol",
1058                 "Kill Slime", "Kill Plant", "Servant Kill Plant",
1059                 "Was Hasty", "Corpse Violation",
1060                 "Souled Friend Died", "Servant Kill Unclean",
1061                 "Servant Kill Chaotic", "Attack In Sanctuary",
1062                 "Kill Artificial", "Undead Slave Kill Artificial",
1063                 "Servant Kill Artificial", "Destroy Spellbook",
1064                 "Exploration", "Desecrate Holy Remains", "Seen Monster",
1065             };
1066
1067             COMPILE_CHECK(ARRAYSZ(conducts) == NUM_CONDUCTS);
1068             dprf("conduct: %s; piety: %d (%+d/%d); penance: %d (%+d)",
1069                  conducts[thing_done],
1070                  you.piety, piety_change, piety_denom,
1071                  you.penance[you.religion], penance);
1072
1073         }
1074 #endif
1075     }
1076
1077     do_god_revenge(thing_done, victim);
1078
1079     return retval;
1080 }
1081
1082 // These two arrays deal with the situation where a beam hits a non-fleeing
1083 // monster, the monster starts to flee because of the damage, and then the
1084 // beam bounces and hits the monster again.  If the monster wasn't fleeing
1085 // when the beam started then hits from bounces shouldn't count as
1086 // unchivalric attacks, but if the first hit from the beam *was* unchivalrous
1087 // then all the bounces should count as unchivalrous as well.
1088 //
1089 // Also do the same sort of check for harming a friendly monster,
1090 // since a Beogh worshipper zapping an orc with lightning might cause it to
1091 // become a follower on the first hit, and the second hit would be
1092 // against a friendly orc.
1093 static FixedBitVector<MAX_MONSTERS> _first_attack_conduct;
1094 static FixedBitVector<MAX_MONSTERS> _first_attack_was_unchivalric;
1095 static FixedBitVector<MAX_MONSTERS> _first_attack_was_friendly;
1096
1097 void god_conduct_turn_start()
1098 {
1099     _first_attack_conduct.reset();
1100     _first_attack_was_unchivalric.reset();
1101     _first_attack_was_friendly.reset();
1102 }
1103
1104 void set_attack_conducts(god_conduct_trigger conduct[3], const monster* mon,
1105                          bool known)
1106 {
1107     const unsigned int midx = mon->mindex();
1108
1109     if (mon->friendly())
1110     {
1111         if (!_first_attack_conduct[midx]
1112             || _first_attack_was_friendly[midx])
1113         {
1114             conduct[0].set(DID_ATTACK_FRIEND, 5, known, mon);
1115             _first_attack_was_friendly.set(midx);
1116         }
1117     }
1118     else if (mon->neutral())
1119         conduct[0].set(DID_ATTACK_NEUTRAL, 5, known, mon);
1120
1121     if (is_unchivalric_attack(&you, mon)
1122         && (!_first_attack_conduct[midx]
1123             || _first_attack_was_unchivalric[midx]))
1124     {
1125         conduct[1].set(DID_UNCHIVALRIC_ATTACK, 4, known, mon);
1126         _first_attack_was_unchivalric.set(midx);
1127     }
1128
1129     if (mon->is_holy())
1130         conduct[2].set(DID_ATTACK_HOLY, mon->hit_dice, known, mon);
1131
1132     _first_attack_conduct.set(midx);
1133 }
1134
1135 void enable_attack_conducts(god_conduct_trigger conduct[3])
1136 {
1137     for (int i = 0; i < 3; ++i)
1138         conduct[i].enabled = true;
1139 }
1140
1141 void disable_attack_conducts(god_conduct_trigger conduct[3])
1142 {
1143     for (int i = 0; i < 3; ++i)
1144         conduct[i].enabled = false;
1145 }