Apply the new ground_level method.
[crawl.git] / crawl-ref / source / godconduct.cc
blobabfcd4306554791802fa331eac6bca9d6bd38577
1 #include "AppHdr.h"
3 #include "godconduct.h"
5 #include "fight.h"
6 #include "godpassive.h"
7 #include "godwrath.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 #include "stuff.h"
16 /////////////////////////////////////////////////////////////////////
17 // god_conduct_trigger
19 god_conduct_trigger::god_conduct_trigger(
20 conduct_type c, int pg, bool kn, const monster* vict)
21 : conduct(c), pgain(pg), known(kn), enabled(true), victim(NULL)
23 if (vict)
25 victim.reset(new monster);
26 *(victim.get()) = *vict;
30 void god_conduct_trigger::set(conduct_type c, int pg, bool kn,
31 const monster* vict)
33 conduct = c;
34 pgain = pg;
35 known = kn;
36 victim.reset(NULL);
37 if (vict)
39 victim.reset(new monster);
40 *victim.get() = *vict;
44 god_conduct_trigger::~god_conduct_trigger()
46 if (enabled && conduct != NUM_CONDUCTS)
47 did_god_conduct(conduct, pgain, known, victim.get());
50 // This function is the merger of done_good() and naughty().
51 // Returns true if god was interested (good or bad) in conduct.
52 bool did_god_conduct(conduct_type thing_done, int level, bool known,
53 const monster* victim)
55 ASSERT(!crawl_state.game_is_arena());
57 bool retval = false;
59 if (you.religion != GOD_NO_GOD && you.religion != GOD_XOM)
61 int piety_change = 0;
62 int piety_denom = 1;
63 int penance = 0;
65 god_acting gdact;
67 switch (thing_done)
69 case DID_DRINK_BLOOD:
70 switch (you.religion)
72 case GOD_ZIN:
73 case GOD_SHINING_ONE:
74 case GOD_ELYVILON:
75 if (!known)
77 simple_god_message(" forgives your inadvertent "
78 "blood-drinking, just this once.");
79 break;
81 if (you.religion == GOD_SHINING_ONE)
82 penance = level;
83 piety_change = -2*level;
84 retval = true;
85 break;
86 default:
87 break;
89 break;
91 case DID_CANNIBALISM:
92 switch (you.religion)
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;
105 break;
107 case DID_CORPSE_VIOLATION:
108 if (you.religion == GOD_FEDHAS)
110 if (known)
112 piety_change = -level;
113 penance = level;
114 retval = true;
116 else
118 simple_god_message(" forgives your inadvertent necromancy, "
119 "just this once.");
122 break;
124 case DID_NECROMANCY:
125 case DID_UNHOLY:
126 case DID_ATTACK_HOLY:
127 switch (you.religion)
129 case GOD_ZIN:
130 case GOD_SHINING_ONE:
131 case GOD_ELYVILON:
132 if (!known && thing_done != DID_ATTACK_HOLY)
134 simple_god_message(" forgives your inadvertent unholy act, "
135 "just this once.");
136 break;
139 if (thing_done == DID_ATTACK_HOLY && victim
140 && !testbits(victim->flags, MF_NO_REWARD)
141 && !testbits(victim->flags, MF_WAS_NEUTRAL))
143 break;
146 piety_change = -level;
147 penance = level * ((you.religion == GOD_SHINING_ONE) ? 2
148 : 1);
149 retval = true;
150 break;
151 default:
152 break;
154 break;
156 case DID_HOLY:
157 if (you.religion == GOD_YREDELEMNUL)
159 if (!known)
161 simple_god_message(" forgives your inadvertent holy act, "
162 "just this once.");
163 break;
165 retval = true;
166 piety_change = -level;
167 penance = level * 2;
169 break;
171 case DID_UNCHIVALRIC_ATTACK:
172 case DID_POISON:
173 if (you.religion == GOD_SHINING_ONE)
175 if (thing_done == DID_UNCHIVALRIC_ATTACK)
177 if (victim && tso_unchivalric_attack_safe_monster(victim))
178 break;
180 if (!known)
182 simple_god_message(" forgives your inadvertent "
183 "dishonourable attack, just this "
184 "once.");
185 break;
188 retval = true;
189 piety_change = -level;
190 penance = level * 2;
192 break;
194 case DID_KILL_SLIME:
195 if (you.religion == GOD_JIYVA && !victim->is_shapeshifter())
197 retval = true;
198 piety_change = -level;
199 penance = level * 2;
201 break;
203 case DID_KILL_PLANT:
204 case DID_PLANT_KILLED_BY_SERVANT:
205 // Piety loss but no penance for killing a plant.
206 if (you.religion == GOD_FEDHAS)
208 retval = true;
209 piety_change = -level;
211 break;
213 case DID_ATTACK_NEUTRAL:
214 switch (you.religion)
216 case GOD_SHINING_ONE:
217 case GOD_ELYVILON:
218 if (!known)
220 simple_god_message(" forgives your inadvertent attack on a "
221 "neutral, just this once.");
222 break;
224 penance = level/2 + 1;
225 // deliberate fall through
227 case GOD_ZIN:
228 if (!known)
230 simple_god_message(" forgives your inadvertent attack on a "
231 "neutral, just this once.");
232 break;
234 piety_change = -(level/2 + 1);
235 retval = true;
236 break;
238 case GOD_JIYVA:
239 if (victim && mons_is_slime(victim)
240 && !victim->is_shapeshifter())
242 piety_change = -(level/2 + 3);
243 penance = level/2 + 3;
244 retval = true;
246 break;
248 default:
249 break;
251 break;
253 case DID_ATTACK_FRIEND:
254 if (god_hates_attacking_friend(you.religion, victim))
256 if (!known)
258 simple_god_message(" forgives your inadvertent attack on "
259 "an ally, just this once.");
260 break;
263 piety_change = -level;
264 if (known)
265 penance = level * 3;
266 retval = true;
268 break;
270 case DID_FRIEND_DIED:
271 case DID_SOULED_FRIEND_DIED:
272 switch (you.religion)
274 case GOD_FEDHAS:
275 // Ballistomycetes dying is penalised separately.
276 if (victim && fedhas_protects(victim)
277 && victim->mons_species() != MONS_BALLISTOMYCETE)
279 // level is (1 + monsterHD/2) for this conduct,
280 // trying a fixed cost since plant HD aren't that
281 // meaningful. -cao
282 piety_change = -1;
283 retval = true;
284 break;
286 break;
288 case GOD_ELYVILON: // healer god cares more about this
289 // Converted allies (marked as TSOites) can be martyrs.
290 if (victim && victim->god == GOD_SHINING_ONE)
291 break;
293 if (player_under_penance())
294 penance = 1; // if already under penance smaller bonus
295 else
296 penance = level;
297 // fall through
299 case GOD_ZIN:
300 // Converted allies (marked as TSOites) can be martyrs.
301 if (victim && victim->god == GOD_SHINING_ONE)
302 break;
304 // Zin only cares about the deaths of those with souls.
305 if (thing_done == DID_FRIEND_DIED)
306 break;
307 // fall through
309 case GOD_OKAWARU:
310 piety_change = -level;
311 retval = true;
312 break;
314 default:
315 break;
317 break;
319 case DID_KILL_LIVING:
320 switch (you.religion)
322 case GOD_ELYVILON:
323 // Killing is only disapproved of during prayer.
324 if (you.duration[DUR_LIFESAVING])
326 simple_god_message(" does not appreciate your shedding "
327 "blood when asking for salvation!");
328 retval = true;
329 piety_change = -level;
330 penance = level * 2;
332 break;
334 case GOD_KIKUBAAQUDGHA:
335 case GOD_YREDELEMNUL:
336 case GOD_OKAWARU:
337 case GOD_VEHUMET:
338 case GOD_MAKHLEB:
339 case GOD_TROG:
340 case GOD_BEOGH:
341 case GOD_LUGONU:
342 if (god_hates_attacking_friend(you.religion, victim))
343 break;
345 simple_god_message(" accepts your kill.");
346 retval = true;
347 piety_denom = level + 18 - you.experience_level / 2;
348 piety_change = piety_denom - 6;
349 piety_denom = std::max(piety_denom, 1);
350 piety_change = std::max(piety_change, 0);
351 break;
353 default:
354 break;
356 break;
358 case DID_KILL_UNDEAD:
359 switch (you.religion)
361 case GOD_SHINING_ONE:
362 case GOD_OKAWARU:
363 case GOD_VEHUMET:
364 case GOD_MAKHLEB:
365 case GOD_BEOGH:
366 case GOD_LUGONU:
367 if (god_hates_attacking_friend(you.religion, victim))
368 break;
370 simple_god_message(" accepts your kill.");
371 retval = true;
372 // Holy gods are easier to please this way.
373 piety_denom = level + 18 - (is_good_god(you.religion) ? 0 :
374 you.experience_level / 2);
375 piety_change = piety_denom - 5;
376 piety_denom = std::max(piety_denom, 1);
377 piety_change = std::max(piety_change, 0);
378 break;
380 default:
381 break;
383 break;
385 case DID_KILL_DEMON:
386 switch (you.religion)
388 case GOD_SHINING_ONE:
389 case GOD_OKAWARU:
390 case GOD_MAKHLEB:
391 case GOD_TROG:
392 case GOD_KIKUBAAQUDGHA:
393 case GOD_BEOGH:
394 if (god_hates_attacking_friend(you.religion, victim))
395 break;
397 simple_god_message(" accepts your kill.");
398 retval = true;
399 // Holy gods are easier to please this way.
400 piety_denom = level + 18 - (is_good_god(you.religion) ? 0 :
401 you.experience_level / 2);
402 piety_change = piety_denom - 4;
403 piety_denom = std::max(piety_denom, 1);
404 piety_change = std::max(piety_change, 0);
405 break;
407 default:
408 break;
410 break;
412 case DID_KILL_NATURAL_UNHOLY:
413 case DID_KILL_NATURAL_EVIL:
414 if (you.religion == GOD_SHINING_ONE
415 && !god_hates_attacking_friend(you.religion, victim))
417 simple_god_message(" accepts your kill.");
418 retval = true;
419 piety_denom = level + 18;
420 piety_change = piety_denom - 4;
422 break;
424 case DID_KILL_UNCLEAN:
425 case DID_KILL_CHAOTIC:
426 if (you.religion == GOD_ZIN
427 && !god_hates_attacking_friend(you.religion, victim))
429 simple_god_message(" accepts your kill.");
430 retval = true;
431 piety_denom = level + 18;
432 piety_change = piety_denom - 4;
434 break;
436 case DID_KILL_PRIEST:
437 if (you.religion == GOD_BEOGH
438 && !god_hates_attacking_friend(you.religion, victim))
440 simple_god_message(" appreciates your killing of a heretic "
441 "priest.");
442 retval = true;
443 piety_denom = level + 10;
444 piety_change = piety_denom - 6;
446 break;
448 case DID_KILL_WIZARD:
449 if (you.religion == GOD_TROG
450 && !god_hates_attacking_friend(you.religion, victim))
452 simple_god_message(" appreciates your killing of a magic "
453 "user.");
454 retval = true;
455 piety_denom = level + 10;
456 piety_change = piety_denom - 6;
458 break;
460 case DID_KILL_FAST:
461 if (you.religion == GOD_CHEIBRIADOS
462 && !god_hates_attacking_friend(you.religion, victim))
464 retval = true;
465 piety_denom = level + 18 - you.experience_level / 2;
466 piety_change = piety_denom - 6;
467 piety_denom = std::max(piety_denom, 1);
468 piety_change = std::max(piety_change, 0);
470 const int speed_delta =
471 cheibriados_monster_player_speed_delta(victim);
472 dprf("Che DID_KILL_FAST: %s speed delta: %d",
473 victim->name(DESC_PLAIN, true).c_str(),
474 speed_delta);
475 if (speed_delta > 0 && x_chance_in_y(speed_delta, 12))
477 piety_change *= 2;
478 simple_god_message(" thoroughly appreciates the change of pace.");
480 else
481 simple_god_message(" appreciates the change of pace.");
483 break;
485 case DID_KILL_ARTIFICIAL:
486 if (you.religion == GOD_YREDELEMNUL
487 && !god_hates_attacking_friend(you.religion, victim))
489 simple_god_message(" accepts your kill.");
490 retval = true;
491 piety_denom = level + 18;
492 piety_change = piety_denom - 3;
494 break;
496 // Note that holy deaths are special, they are always noticed...
497 // If you or any friendly kills one, you'll get the credit or
498 // the blame.
499 case DID_KILL_HOLY:
500 switch (you.religion)
502 case GOD_ZIN:
503 case GOD_SHINING_ONE:
504 case GOD_ELYVILON:
505 if (victim
506 && !testbits(victim->flags, MF_NO_REWARD)
507 && !testbits(victim->flags, MF_WAS_NEUTRAL))
509 break;
512 penance = level * 3;
513 piety_change = -level * 3;
514 retval = true;
515 break;
517 case GOD_YREDELEMNUL:
518 case GOD_KIKUBAAQUDGHA:
519 case GOD_MAKHLEB:
520 case GOD_BEOGH:
521 case GOD_LUGONU:
522 if (god_hates_attacking_friend(you.religion, victim))
523 break;
525 simple_god_message(" accepts your kill.");
526 retval = true;
527 piety_denom = level + 18;
528 piety_change = piety_denom - 3;
530 if (you.religion == GOD_YREDELEMNUL)
532 simple_god_message(" appreciates your killing of a holy "
533 "being.");
534 retval = true;
535 piety_change *= 2;
537 break;
539 default:
540 break;
542 break;
544 case DID_HOLY_KILLED_BY_UNDEAD_SLAVE:
545 switch (you.religion)
547 case GOD_YREDELEMNUL:
548 case GOD_KIKUBAAQUDGHA:
549 case GOD_MAKHLEB:
550 case GOD_BEOGH:
551 case GOD_LUGONU:
552 if (god_hates_attacking_friend(you.religion, victim))
553 break;
555 simple_god_message(" accepts your slave's kill.");
556 retval = true;
557 piety_denom = level + 18;
558 piety_change = piety_denom - 3;
559 break;
561 default:
562 break;
564 break;
566 case DID_HOLY_KILLED_BY_SERVANT:
567 switch (you.religion)
569 case GOD_ZIN:
570 case GOD_SHINING_ONE:
571 case GOD_ELYVILON:
572 if (victim
573 && !testbits(victim->flags, MF_NO_REWARD)
574 && !testbits(victim->flags, MF_WAS_NEUTRAL))
576 break;
579 penance = level * 3;
580 piety_change = -level * 3;
581 retval = true;
582 break;
584 case GOD_MAKHLEB:
585 case GOD_BEOGH:
586 case GOD_LUGONU:
587 if (god_hates_attacking_friend(you.religion, victim))
588 break;
590 simple_god_message(" accepts your collateral kill.");
591 retval = true;
592 piety_denom = level + 18;
593 piety_change = piety_denom - 3;
594 break;
596 default:
597 break;
599 break;
601 case DID_LIVING_KILLED_BY_UNDEAD_SLAVE:
602 switch (you.religion)
604 case GOD_YREDELEMNUL:
605 case GOD_KIKUBAAQUDGHA:
606 case GOD_VEHUMET:
607 case GOD_MAKHLEB:
608 case GOD_BEOGH:
609 case GOD_LUGONU:
610 simple_god_message(" accepts your slave's kill.");
611 retval = true;
612 piety_denom = level + 10 - you.experience_level/3;
613 piety_change = piety_denom - 6;
614 piety_denom = std::max(piety_denom, 1);
615 piety_change = std::max(piety_change, 0);
616 break;
617 default:
618 break;
620 break;
622 case DID_LIVING_KILLED_BY_SERVANT:
623 switch (you.religion)
625 case GOD_VEHUMET:
626 case GOD_MAKHLEB:
627 case GOD_TROG:
628 case GOD_BEOGH:
629 case GOD_LUGONU:
630 simple_god_message(" accepts your collateral kill.");
631 retval = true;
632 piety_denom = level + 10 - you.experience_level/3;
633 piety_change = piety_denom - 6;
634 piety_denom = std::max(piety_denom, 1);
635 piety_change = std::max(piety_change, 0);
636 break;
637 default:
638 break;
640 break;
642 case DID_UNDEAD_KILLED_BY_UNDEAD_SLAVE:
643 switch (you.religion)
645 case GOD_VEHUMET:
646 case GOD_MAKHLEB:
647 case GOD_BEOGH:
648 case GOD_LUGONU:
649 simple_god_message(" accepts your slave's kill.");
650 retval = true;
651 piety_denom = level + 10 - you.experience_level/3;
652 piety_change = piety_denom - 6;
653 piety_denom = std::max(piety_denom, 1);
654 piety_change = std::max(piety_change, 0);
655 break;
656 default:
657 break;
659 break;
661 case DID_UNDEAD_KILLED_BY_SERVANT:
662 switch (you.religion)
664 case GOD_SHINING_ONE:
665 case GOD_VEHUMET:
666 case GOD_MAKHLEB:
667 case GOD_BEOGH:
668 case GOD_LUGONU:
669 simple_god_message(" accepts your collateral kill.");
670 retval = true;
671 piety_denom = level + 10 - (is_good_god(you.religion) ? 0 :
672 you.experience_level/3);
673 piety_change = piety_denom - 6;
674 piety_denom = std::max(piety_denom, 1);
675 piety_change = std::max(piety_change, 0);
676 break;
677 default:
678 break;
680 break;
682 case DID_DEMON_KILLED_BY_UNDEAD_SLAVE:
683 switch (you.religion)
685 case GOD_KIKUBAAQUDGHA:
686 case GOD_MAKHLEB:
687 case GOD_BEOGH:
688 simple_god_message(" accepts your slave's kill.");
689 retval = true;
690 piety_denom = level + 10 - you.experience_level/3;
691 piety_change = piety_denom - 6;
692 piety_denom = std::max(piety_denom, 1);
693 piety_change = std::max(piety_change, 0);
694 break;
695 default:
696 break;
698 break;
700 case DID_DEMON_KILLED_BY_SERVANT:
701 switch (you.religion)
703 case GOD_SHINING_ONE:
704 case GOD_MAKHLEB:
705 case GOD_TROG:
706 case GOD_BEOGH:
707 simple_god_message(" accepts your collateral kill.");
708 retval = true;
709 piety_denom = level + 10 - (is_good_god(you.religion) ? 0 :
710 you.experience_level/3);
711 piety_change = piety_denom - 6;
712 piety_denom = std::max(piety_denom, 1);
713 piety_change = std::max(piety_change, 0);
714 break;
715 default:
716 break;
718 break;
720 case DID_NATURAL_UNHOLY_KILLED_BY_SERVANT:
721 case DID_NATURAL_EVIL_KILLED_BY_SERVANT:
722 if (you.religion == GOD_SHINING_ONE)
724 simple_god_message(" accepts your collateral kill.");
725 retval = true;
726 piety_denom = level + 10;
727 piety_change = piety_denom - 6;
729 break;
731 case DID_UNCLEAN_KILLED_BY_SERVANT:
732 case DID_CHAOTIC_KILLED_BY_SERVANT:
733 if (you.religion == GOD_ZIN)
735 simple_god_message(" accepts your collateral kill.");
736 retval = true;
738 piety_denom = level + 10;
739 piety_change = piety_denom - 6;
741 break;
743 case DID_ARTIFICIAL_KILLED_BY_UNDEAD_SLAVE:
744 if (you.religion == GOD_YREDELEMNUL)
746 simple_god_message(" accepts your slave's kill.");
747 retval = true;
748 piety_denom = level + 18;
749 piety_change = piety_denom - 3;
751 break;
753 // Currently used only when confused undead kill artificial
754 // beings, which Yredelemnul doesn't care about.
755 case DID_ARTIFICIAL_KILLED_BY_SERVANT:
756 break;
758 case DID_SPELL_MEMORISE:
759 if (you.religion == GOD_TROG)
761 penance = level * 10;
762 piety_change = -penance;
763 retval = true;
765 break;
767 case DID_SPELL_CASTING:
768 if (you.religion == GOD_TROG)
770 piety_change = -level;
771 penance = level * 5;
772 retval = true;
774 break;
776 case DID_SPELL_PRACTISE:
777 // Like CAST, but for skill advancement.
778 // Level is number of skill points gained...
779 // typically 10 * exercise, but may be more/less if the
780 // skill is at 0 (INT adjustment), or if the PC's pool is
781 // low and makes change.
782 if (you.religion == GOD_SIF_MUNA)
784 // Old curve: random2(12) <= spell-level, this is
785 // similar, but faster at low levels (to help ease
786 // things for low level spells). Power averages about
787 // (level * 20 / 3) + 10 / 3 now. Also note that spell
788 // skill practise comes just after XP gain, so magical
789 // kills tend to do both at the same time (unlike
790 // melee). This means high level spells probably work
791 // pretty much like they used to (use spell, get piety).
792 piety_change = level + 10;
793 piety_denom = 80;
794 retval = true;
796 break;
798 case DID_CARDS:
799 if (you.religion == GOD_NEMELEX_XOBEH)
801 piety_change = level;
802 retval = true;
804 // level == 0: stacked, deck not used up
805 // level == 1: used up or nonstacked
806 // level == 2: used up and nonstacked
807 // and there's a 1/3 chance of an additional bonus point
808 // for nonstacked cards.
809 int chance = 0;
810 switch (level)
812 case 0: chance = 0; break;
813 case 1: chance = 40; break;
814 case 2: chance = 70; break;
815 default:
816 case 3: chance = 100; break;
819 if (x_chance_in_y(chance, 100)
820 && you.attribute[ATTR_CARD_COUNTDOWN])
822 you.attribute[ATTR_CARD_COUNTDOWN]--;
823 #if defined(DEBUG_DIAGNOSTICS) || defined(DEBUG_CARDS) || defined(DEBUG_GIFTS)
824 mprf(MSGCH_DIAGNOSTICS, "Countdown down to %d",
825 you.attribute[ATTR_CARD_COUNTDOWN]);
826 #endif
829 break;
831 case DID_CAUSE_GLOWING:
832 case DID_DELIBERATE_MUTATING:
833 if (you.religion == GOD_ZIN)
835 if (!known && thing_done != DID_CAUSE_GLOWING)
837 simple_god_message(" forgives your inadvertent chaotic "
838 "act, just this once.");
839 break;
842 if (thing_done == DID_CAUSE_GLOWING)
844 static long last_glowing_lecture = -1L;
845 if (!level)
847 simple_god_message(" is not enthusiastic about the "
848 "mutagenic glow surrounding you.");
850 else if (last_glowing_lecture != you.num_turns)
852 last_glowing_lecture = you.num_turns;
853 // Increase contamination within yellow glow.
854 simple_god_message(" does not appreciate the extra "
855 "mutagenic glow surrounding you!");
859 piety_change = -level;
860 retval = true;
862 break;
864 // level depends on intelligence: normal -> 1, high -> 2
865 // cannibalism is still worse
866 case DID_EAT_SOULED_BEING:
867 if (you.religion == GOD_ZIN)
869 piety_change = -level * 5;
870 if (level > 1)
871 penance = 5;
872 retval = true;
874 break;
876 case DID_UNCLEAN:
877 if (you.religion == GOD_ZIN)
879 retval = true;
880 if (!known)
882 simple_god_message(" forgives your inadvertent unclean "
883 "act, just this once.");
884 break;
886 piety_change = -level;
887 penance = level;
889 break;
891 case DID_CHAOS:
892 if (you.religion == GOD_ZIN)
894 retval = true;
895 if (!known)
897 simple_god_message(" forgives your inadvertent chaotic "
898 "act, just this once.");
899 break;
901 piety_change = -level;
902 penance = level;
904 break;
906 case DID_ATTACK_IN_SANCTUARY:
907 if (you.religion == GOD_ZIN)
909 piety_change = -level;
910 retval = true;
912 break;
914 case DID_DESECRATE_ORCISH_REMAINS:
915 if (you.religion == GOD_BEOGH)
917 piety_change = -level;
918 retval = true;
920 break;
922 case DID_DESTROY_ORCISH_IDOL:
923 if (you.religion == GOD_BEOGH)
925 piety_change = -level;
926 penance = level * 3;
927 retval = true;
929 break;
931 case DID_HASTY:
932 if (you.religion == GOD_CHEIBRIADOS)
934 if (!known)
936 simple_god_message(" forgives your accidental hurry, just this once.");
937 break;
939 simple_god_message(" thinks you should slow down.");
940 piety_change = -level;
941 if (level > 5)
942 penance = level - 5;
943 retval = true;
945 break;
947 case DID_DESTROY_SPELLBOOK:
948 if (you.religion == GOD_SIF_MUNA)
950 piety_change = -level;
951 penance = level * (known ? 2 : 1);
952 retval = true;
954 break;
956 case DID_EXPLORATION:
957 if (you.religion == GOD_ASHENZARI)
959 // levels: x1, x2, x4, x6
960 piety_change = ash_bondage_level() * 2;
961 if (!piety_change)
962 piety_change = 1;
963 piety_change *= 8; // base gain per dungeon level
964 piety_denom = level;
965 retval = true;
967 break;
969 case DID_NOTHING:
970 case DID_GLUTTONY: // previously used for Chei
971 case DID_STABBING: // unused
972 case DID_STIMULANTS: // unused
973 case DID_EAT_MEAT: // unused
974 case DID_CREATE_LIFE: // unused
975 case DID_SPELL_NONUTILITY: // unused
976 case DID_DEDICATED_BUTCHERY: // unused
977 case NUM_CONDUCTS:
978 break;
981 #ifdef DEBUG_DIAGNOSTICS
982 int old_piety = you.piety;
983 #endif
985 if (piety_change > 0)
986 gain_piety(piety_change, piety_denom);
987 else
988 dock_piety(div_rand_round(-piety_change, piety_denom), penance);
990 #ifdef DEBUG_DIAGNOSTICS
991 // don't announce exploration piety unless you actually got a boost
992 if (retval && (thing_done != DID_EXPLORATION || old_piety != you.piety))
994 static const char *conducts[] =
997 "Necromancy", "Holy", "Unholy", "Attack Holy", "Attack Neutral",
998 "Attack Friend", "Friend Died", "Stab", "Unchivalric Attack",
999 "Poison", "Field Sacrifice", "Kill Living", "Kill Undead",
1000 "Kill Demon", "Kill Natural Unholy", "Kill Natural Evil",
1001 "Kill Unclean", "Kill Chaotic", "Kill Wizard", "Kill Priest",
1002 "Kill Holy", "Kill Fast", "Undead Slave Kill Living",
1003 "Servant Kill Living", "Undead Slave Kill Undead",
1004 "Servant Kill Undead", "Undead Slave Kill Demon",
1005 "Servant Kill Demon", "Servant Kill Natural Unholy",
1006 "Servant Kill Natural Evil", "Undead Slave Kill Holy",
1007 "Servant Kill Holy", "Spell Memorise", "Spell Cast",
1008 "Spell Practise", "Spell Nonutility", "Cards", "Stimulants",
1009 "Drink Blood", "Cannibalism", "Eat Meat", "Eat Souled Being",
1010 "Deliberate Mutation", "Cause Glowing", "Use Unclean",
1011 "Use Chaos", "Desecrate Orcish Remains", "Destroy Orcish Idol",
1012 "Create Life", "Kill Slime", "Kill Plant", "Servant Kill Plant",
1013 "Was Hasty", "Gluttony", "Corpse Violation",
1014 "Souled Friend Died", "Servant Kill Unclean",
1015 "Servant Kill Chaotic", "Attack In Sanctuary",
1016 "Kill Artificial", "Undead Slave Kill Artificial",
1017 "Servant Kill Artificial", "Destroy Spellbook",
1018 "Exploration",
1021 COMPILE_CHECK(ARRAYSZ(conducts) == NUM_CONDUCTS, c1);
1022 mprf(MSGCH_DIAGNOSTICS,
1023 "conduct: %s; piety: %d (%+d/%d); penance: %d (%+d)",
1024 conducts[thing_done],
1025 you.piety, piety_change, piety_denom,
1026 you.penance[you.religion], penance);
1029 #endif
1032 do_god_revenge(thing_done);
1034 return (retval);
1037 // These two arrays deal with the situation where a beam hits a non-fleeing
1038 // monster, the monster starts to flee because of the damage, and then the
1039 // beam bounces and hits the monster again. If the monster wasn't fleeing
1040 // when the beam started then hits from bounces shouldn't count as
1041 // unchivalric attacks, but if the first hit from the beam *was* unchivalrous
1042 // then all the bounces should count as unchivalrous as well.
1044 // Also do the same sort of check for harming a friendly monster,
1045 // since a Beogh worshipper zapping an orc with lightning might cause it to
1046 // become a follower on the first hit, and the second hit would be
1047 // against a friendly orc.
1048 static FixedVector<bool, MAX_MONSTERS> _first_attack_conduct;
1049 static FixedVector<bool, MAX_MONSTERS> _first_attack_was_unchivalric;
1050 static FixedVector<bool, MAX_MONSTERS> _first_attack_was_friendly;
1052 void god_conduct_turn_start()
1054 _first_attack_conduct.init(true);
1055 _first_attack_was_unchivalric.init(false);
1056 _first_attack_was_friendly.init(false);
1059 void set_attack_conducts(god_conduct_trigger conduct[3], const monster* mon,
1060 bool known)
1062 const unsigned int midx = mon->mindex();
1064 if (mon->friendly())
1066 if (_first_attack_conduct[midx]
1067 || _first_attack_was_friendly[midx])
1069 conduct[0].set(DID_ATTACK_FRIEND, 5, known, mon);
1070 _first_attack_was_friendly[midx] = true;
1073 else if (mon->neutral())
1075 conduct[0].set(DID_ATTACK_NEUTRAL, 5, known, mon);
1078 if (is_unchivalric_attack(&you, mon)
1079 && (_first_attack_conduct[midx]
1080 || _first_attack_was_unchivalric[midx]))
1082 conduct[1].set(DID_UNCHIVALRIC_ATTACK, 4, known, mon);
1083 _first_attack_was_unchivalric[midx] = true;
1086 if (mon->is_holy())
1087 conduct[2].set(DID_ATTACK_HOLY, mon->hit_dice, known, mon);
1089 _first_attack_conduct[midx] = false;
1092 void enable_attack_conducts(god_conduct_trigger conduct[3])
1094 for (int i = 0; i < 3; ++i)
1095 conduct[i].enabled = true;
1098 void disable_attack_conducts(god_conduct_trigger conduct[3])
1100 for (int i = 0; i < 3; ++i)
1101 conduct[i].enabled = false;