ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/gods.C
(Generate patch)

Comparing deliantra/server/server/gods.C (file contents):
Revision 1.33 by root, Tue Apr 22 07:01:47 2008 UTC vs.
Revision 1.45 by root, Thu Jan 1 16:05:13 2009 UTC

36 36
37/** 37/**
38 * Returns the id of specified god. 38 * Returns the id of specified god.
39 */ 39 */
40int 40int
41lookup_god_by_name (const char *name) 41lookup_god_by_name (shstr_cmp name)
42{ 42{
43 int godnr = -1; 43 if (name)
44 size_t nmlen = strlen (name);
45
46 if (name && strcmp (name, "none"))
47 {
48 godlink *gl;
49
50 for (gl = first_god; gl; gl = gl->next) 44 for (godlink *gl = first_god; gl; gl = gl->next)
51 if (!strncmp (name, gl->name, MIN ((size_t) strlen (gl->name), nmlen))) 45 if (gl->name == name)
52 break;
53
54 if (gl)
55 godnr = gl->id; 46 return gl->id;
56 }
57 47
58 return godnr; 48 return -1;
59} 49}
60 50
61/** 51/**
62 * Returns pointer to specified god's object through pntr_to_god_obj.. 52 * Returns pointer to specified god's object through pntr_to_god_obj..
63 */ 53 */
64object * 54object *
65find_god (const char *name) 55find_god (shstr_cmp name)
66{ 56{
67 object *god = NULL;
68
69 if (name) 57 if (name)
70 {
71 godlink *gl;
72
73 for (gl = first_god; gl; gl = gl->next) 58 for (godlink *gl = first_god; gl; gl = gl->next)
74 if (!strcmp (name, gl->name)) 59 if (gl->name == name)
75 break;
76 if (gl)
77 god = pntr_to_god_obj (gl); 60 return pntr_to_god_obj (gl);
78 } 61
79 return god; 62 return 0;
63}
64
65/**
66 * Returns a string that is the name of the god that should be natively worshipped by a
67 * creature of who has race *race
68 * if we can't find a god that is appropriate, we return NULL
69 */
70static shstr_tmp
71get_god_for_race (shstr_cmp race)
72{
73 if (race)
74 for (godlink *gl = first_god; gl; gl = gl->next)
75 if (gl->arch->race == race)
76 return gl->name;
77
78 return shstr_tmp ();
80} 79}
81 80
82/** 81/**
83 * Determines if op worships a god. 82 * Determines if op worships a god.
84 * Returns the godname if they do or "none" if they have no god. 83 * Returns the godname if they do or "none" if they have no god.
85 * In the case of an NPC, if they have no god, we try and guess 84 * In the case of an NPC, if they have no god, we try and guess
86 * who they should worship based on their race. If that fails we 85 * who they should worship based on their race. If that fails we
87 * give them a random one. 86 * give them a random one.
88 */ 87 */
89 88shstr_tmp
90const char *
91determine_god (object *op) 89determine_god (object *op)
92{ 90{
93 int godnr = -1;
94 const char *godname;
95
96 /* spells */ 91 /* spells */
97 if ((op->type == SPELL || op->type == SPELL_EFFECT) && op->title) 92 if ((op->type == SPELL || op->type == SPELL_EFFECT) && op->title)
98 {
99 if (lookup_god_by_name (op->title) >= 0) 93 if (lookup_god_by_name (op->title) >= 0)
100 return op->title; 94 return op->title;
95
96 if (!op->is_player () && op->flag [FLAG_ALIVE])
101 } 97 {
102
103 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_ALIVE))
104 {
105
106 /* find a god based on race */ 98 /* find a god based on race */
107 if (!op->title) 99 if (!op->title)
108 {
109 if (op->race)
110 {
111 godname = get_god_for_race (op->race); 100 op->title = get_god_for_race (op->race);
112
113 if (godname)
114 op->title = godname;
115 }
116 }
117 101
118 /* find a random god */ 102 /* find a random god */
119 if (!op->title) 103 if (!op->title)
120 { 104 {
121 godlink *gl = first_god;
122
123 godnr = rndm (1, gl->id); 105 int godnr = rndm (1, first_god->id);
124 while (gl) 106
125 { 107 for (godlink *gl = first_god; gl && gl->id != godnr; gl = gl->next)
126 if (gl->id == godnr) 108 if (gl->id == godnr)
109 {
110 op->title = gl->name;
127 break; 111 break;
128
129 gl = gl->next;
130 } 112 }
131
132 op->title = gl->name;
133 } 113 }
134 114
135 return op->title; 115 return op->title;
136 } 116 }
137
138 117
139 /* The god the player worships is in the praying skill (native skill 118 /* The god the player worships is in the praying skill (native skill
140 * not skill tool). Since a player can only have one instance of 119 * not skill tool). Since a player can only have one instance of
141 * that skill, once we find it, we can return, either with the 120 * that skill, once we find it, we can return, either with the
142 * title or "none". 121 * title or "none".
143 */ 122 */
144 if (op->type == PLAYER) 123 if (op->type == PLAYER)
145 {
146 for (object *tmp = op->inv; tmp; tmp = tmp->below) 124 for (object *tmp = op->inv; tmp; tmp = tmp->below)
147 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING) 125 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING)
148 { 126 {
149 if (tmp->title) 127 if (tmp->title)
150 return tmp->title; 128 return tmp->title;
151 else 129
152 return "none"; 130 break;
153 } 131 }
154 }
155 132
156 return "none"; 133 return shstr_none;
157} 134}
158 135
159/** 136/**
160 * Returns 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0 137 * Returns 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0
161 */ 138 */
162static int 139static int
163same_string (const char *s1, const char *s2) 140same_string (const char *s1, const char *s2)
164{ 141{
165 if (s1 == NULL) 142 if (s1 == s2)
166 if (s2 == NULL)
167 return 1; 143 return 1;
144 else if (s1 && s2)
145 return !strcmp (s1, s2);
168 else 146 else
169 return 0;
170 else if (s2 == NULL)
171 return 0; 147 return 0;
172 else
173 return strcmp (s1, s2) == 0;
174} 148}
175 149
176/** 150/**
177 * Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively). 151 * Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively).
178 * Any matching items in the inventory are deleted, and a 152 * Any matching items in the inventory are deleted, and a
192 166
193 if (tmp->type == item->type 167 if (tmp->type == item->type
194 && same_string (tmp->name, item->name) 168 && same_string (tmp->name, item->name)
195 && same_string (tmp->title, item->title) && same_string (tmp->msg, item->msg) && same_string (tmp->slaying, item->slaying)) 169 && same_string (tmp->title, item->title) && same_string (tmp->msg, item->msg) && same_string (tmp->slaying, item->slaying))
196 { 170 {
197
198 /* message */ 171 /* message */
199 if (tmp->nrof > 1) 172 new_draw_info_format (NDI_UNIQUE, 0, op,
200 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumble to dust!", query_short_name (tmp)); 173 tmp->nrof > 1 ? "The %s crumble to dust!" : "The %s crumbles to dust!",
201 else 174 query_short_name (tmp));
202 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumbles to dust!", query_short_name (tmp));
203 175
204 tmp->destroy (); 176 tmp->destroy ();
205 } 177 }
206 178
207 if (tmp->inv) 179 if (tmp->inv)
400 { 372 {
401 remove = 0; 373 remove = 0;
402 break; 374 break;
403 } 375 }
404 } 376 }
377
405 if (remove) 378 if (remove)
406 { 379 do_forget_spell (op, tmp->name);
407 /* just do the work of removing the spell ourselves - we already
408 * know that the player knows the spell
409 */
410 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &tmp->name);
411 player_unready_range_ob (op->contr, tmp);
412 tmp->destroy ();
413 }
414
415 } 380 }
416} 381}
417 382
418/** 383/**
419 * This function is called whenever a player has 384 * This function is called whenever a player has
427 object *old_god = NULL; /* old god */ 392 object *old_god = NULL; /* old god */
428 treasure *tr; 393 treasure *tr;
429 object *item, *skop, *next; 394 object *item, *skop, *next;
430 int i, sk_applied, undeadified = 0; /* Turns to true if changing god can changes the undead status of the player. */ 395 int i, sk_applied, undeadified = 0; /* Turns to true if changing god can changes the undead status of the player. */
431 396
432
433 old_god = find_god (determine_god (op)); 397 old_god = find_god (determine_god (op));
434 398
435 /* take away any special god-characteristic items. */ 399 /* take away any special god-characteristic items. */
436 for (item = op->inv; item != NULL; item = next) 400 for (item = op->inv; item; item = next)
437 { 401 {
438 next = item->below; 402 next = item->below;
403
439 // remove all invisible startequip items which are not skill, exp or force 404 // remove all invisible startequip items which are not skill, exp or force
440 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible && 405 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible &&
441 (item->type != SKILL) && (item->type != FORCE)) 406 (item->type != SKILL) && (item->type != FORCE))
442 { 407 {
443
444 if (item->type == SPELL) 408 if (item->type == SPELL)
409 {
445 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &item->name); 410 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &item->name);
411 esrv_remove_spell (op->contr, item);
412 }
446 413
447 player_unready_range_ob (op->contr, item); 414 player_unready_range_ob (op->contr, item);
448 item->destroy (); 415 item->destroy ();
449 } 416 }
450 } 417 }
456 follower_remove_similar_item (op, tr->item); 423 follower_remove_similar_item (op, tr->item);
457 424
458 if (!op || !new_god) 425 if (!op || !new_god)
459 return; 426 return;
460 427
461 if (op->race && new_god->slaying && strstr (op->race, new_god->slaying)) 428 if (op->race && new_god->slaying && op->race.contains (new_god->slaying))
462 { 429 {
463 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name); 430 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name);
464 431
465 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0) 432 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0)
466 { 433 {
469 cast_magic_storm (op, tmp, new_god->level + 10); 436 cast_magic_storm (op, tmp, new_god->level + 10);
470 } 437 }
471 438
472 return; 439 return;
473 } 440 }
474
475 441
476 /* give the player any special god-characteristic-items. */ 442 /* give the player any special god-characteristic-items. */
477 for (tr = new_god->randomitems->items; tr; tr = tr->next) 443 for (tr = new_god->randomitems->items; tr; tr = tr->next)
478 { 444 {
479 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK 445 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK
480 && tr->item->type != BOOK && tr->item->type != SPELL) 446 && tr->item->type != BOOK && tr->item->type != SPELL)
481 god_gives_present (op, new_god, tr); 447 god_gives_present (op, new_god, tr);
482 } 448 }
483 449
484
485 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You become a follower of %s!", &new_god->name); 450 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You become a follower of %s!", &new_god->name);
486 451
487 for (skop = op->inv; skop != NULL; skop = skop->below) 452 for (skop = op->inv; skop; skop = skop->below)
488 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 453 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
489 break; 454 break;
490 455
491 /* Player has no skill - give them the skill */ 456 /* Player has no skill - give them the skill */
492 if (!skop) 457 if (!skop)
493 {
494 /* The arhetype should always be defined - if we crash here because it doesn't, 458 /* The archetype should always be defined - if we crash here because it doesn't,
495 * things are really messed up anyways. 459 * things are really messed up anyways.
496 */ 460 */
497 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill); 461 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill);
498 link_player_skills (op);
499 }
500 462
501 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 463 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */
502 464
503 /* Clear the "undead" status. We also need to force a call to change_abil, 465 /* Clear the "undead" status. We also need to force a call to change_abil,
504 * so I set undeadified for that. 466 * so I set undeadified for that.
505 * - gros, 21th July 2006. 467 * - gros, 21th July 2006.
506 */ 468 */
507 if ((old_god) && (QUERY_FLAG (old_god, FLAG_UNDEAD))) 469 if (old_god && QUERY_FLAG (old_god, FLAG_UNDEAD))
508 { 470 {
509 CLEAR_FLAG (skop, FLAG_UNDEAD); 471 CLEAR_FLAG (skop, FLAG_UNDEAD);
510 undeadified = 1; 472 undeadified = 1;
511 } 473 }
512 474
513 if (skop->title) 475 if (skop->title)
514 { /* get rid of old god */ 476 {
477 /* get rid of old god */
515 new_draw_info_format (NDI_UNIQUE, 0, op, "%s's blessing is withdrawn from you.", &skop->title); 478 new_draw_info_format (NDI_UNIQUE, 0, op, "%s's blessing is withdrawn from you.", &skop->title);
479
516 /* The point of this is to really show what abilities the player just lost */ 480 /* The point of this is to really show what abilities the player just lost */
517 if (sk_applied || undeadified) 481 if (sk_applied || undeadified)
518 { 482 {
519
520 CLEAR_FLAG (skop, FLAG_APPLIED); 483 CLEAR_FLAG (skop, FLAG_APPLIED);
521 (void) change_abil (op, skop); 484 change_abil (op, skop);
522 } 485 }
523 } 486 }
524 487
525 /* now change to the new gods attributes to exp_obj */ 488 /* now change to the new gods attributes to exp_obj */
526 skop->title = new_god->name; 489 skop->title = new_god->name;
561 * This also can happen for monks which cannot use weapons. In this case 524 * This also can happen for monks which cannot use weapons. In this case
562 * do not allow to use weapons even if the god otherwise would allow it. 525 * do not allow to use weapons even if the god otherwise would allow it.
563 */ 526 */
564 if (!present_in_ob_by_name (FORCE, "no weapon force", op)) 527 if (!present_in_ob_by_name (FORCE, "no weapon force", op))
565 update_priest_flag (new_god, skop, FLAG_USE_WEAPON); 528 update_priest_flag (new_god, skop, FLAG_USE_WEAPON);
529
566 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR); 530 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR);
567 531
568 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons")) 532 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons"))
569 stop_using_item (op, WEAPON, 2); 533 stop_using_item (op, WEAPON, 2);
570 534
596 */ 560 */
597 561
598int 562int
599worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string) 563worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
600{ 564{
601
602 if (QUERY_FLAG (op->arch, flag)) 565 if (QUERY_FLAG (op->arch, flag))
603 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag)) 566 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
604 { 567 {
605 update_priest_flag (exp_obj, op, flag); 568 update_priest_flag (exp_obj, op, flag);
606 if (QUERY_FLAG (op, flag)) 569 if (QUERY_FLAG (op, flag))
609 { 572 {
610 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string); 573 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
611 return 1; 574 return 1;
612 } 575 }
613 } 576 }
577
614 return 0; 578 return 0;
615} 579}
616 580
617/** 581/**
618 * Unapplies up to number worth of items of type 582 * Unapplies up to number worth of items of type
655/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/ 619/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
656 CLEAR_FLAG (exp_ob, flag); 620 CLEAR_FLAG (exp_ob, flag);
657 }; 621 };
658} 622}
659 623
660
661
662archetype * 624archetype *
663determine_holy_arch (object *god, const char *type) 625determine_holy_arch (object *god, shstr_cmp type)
664{ 626{
665 treasure *tr; 627 treasure *tr;
666 628
667 if (!god || !god->randomitems) 629 if (!god || !god->randomitems)
668 { 630 {
669 LOG (llevError, "BUG: determine_holy_arch(): no god or god without " "randomitems\n"); 631 LOG (llevError, "BUG: determine_holy_arch(): no god or god without " "randomitems\n");
670 return NULL; 632 return 0;
671 } 633 }
672 634
673 for (tr = god->randomitems->items; tr; tr = tr->next) 635 for (tr = god->randomitems->items; tr; tr = tr->next)
674 { 636 {
675 if (!tr->item) 637 if (!tr->item)
676 continue; 638 continue;
677 639
678 object *item = tr->item; 640 object *item = tr->item;
679 641
680 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 642 if (item->type == BOOK && item->invisible && item->name == type)
681 return item->other_arch; 643 return item->other_arch;
682 } 644 }
645
683 return NULL; 646 return 0;
684} 647}
685 648
686/** 649/**
687 * God helps player by removing curse and/or damnation. 650 * God helps player by removing curse and/or damnation.
688 */ 651 */
726 return 0; 689 return 0;
727 } 690 }
728 691
729 if (level <= 20) 692 if (level <= 20)
730 return level / difficulty; 693 return level / difficulty;
694
731 if (level <= 40) 695 if (level <= 40)
732 return (20 + (level - 20) / 2) / difficulty; 696 return (20 + (level - 20) / 2) / difficulty;
733 697
734 return (30 + (level - 40) / 4) / difficulty; 698 return (30 + (level - 40) / 4) / difficulty;
735} 699}
741 * attacktype, slaying and such. 705 * attacktype, slaying and such.
742 */ 706 */
743static int 707static int
744god_enchants_weapon (object *op, object *god, object *tr, object *skill) 708god_enchants_weapon (object *op, object *god, object *tr, object *skill)
745{ 709{
746 char buf[MAX_BUF];
747 object *weapon; 710 object *weapon;
748 uint32 attacktype; 711 uint32 attacktype;
749 int tmp; 712 int tmp;
750 713
751 for (weapon = op->inv; weapon; weapon = weapon->below) 714 for (weapon = op->inv; weapon; weapon = weapon->below)
752 if ((weapon->type == WEAPON || weapon->type == BOW) && QUERY_FLAG (weapon, FLAG_APPLIED)) 715 if ((weapon->type == WEAPON || weapon->type == BOW) && QUERY_FLAG (weapon, FLAG_APPLIED))
753 break; 716 break;
754 717
755 if (weapon == NULL || god_examines_item (god, weapon) <= 0) 718 if (!weapon || god_examines_item (god, weapon) <= 0)
756 return 0; 719 return 0;
757 720
758 /* First give it a title, so other gods won't touch it */ 721 /* First give it a title, so other gods won't touch it */
759 if (!weapon->title) 722 if (!weapon->title)
760 { 723 {
761 sprintf (buf, "of %s", &god->name); 724 weapon->title = format ("of %s", &god->name);
762 weapon->title = buf;
763 725
764 if (object *pl = weapon->visible_to ()) 726 if (object *pl = weapon->visible_to ())
765 esrv_update_item (UPD_NAME, pl, weapon); 727 esrv_update_item (UPD_NAME, pl, weapon);
766 728
767 new_draw_info (NDI_UNIQUE, 0, op, "Your weapon quivers as if struck!"); 729 new_draw_info (NDI_UNIQUE, 0, op, "Your weapon quivers as if struck!");
851 continue; 813 continue;
852 814
853 item = tr->item; 815 item = tr->item;
854 816
855 /* Grace limit */ 817 /* Grace limit */
856 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0) 818 if (item->type == BOOK && item->invisible && item->name == shstr_grace_limit)
857 { 819 {
858 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace) 820 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace)
859 { 821 {
860 object *tmp;
861
862 /* Follower lacks the required grace for the following 822 /* Follower lacks the required grace for the following
863 * treasure list items. */ 823 * treasure list items. */
864 824
865 tmp = get_archetype (HOLY_POSSESSION); 825 object *tmp = get_archetype (HOLY_POSSESSION);
866 cast_change_ability (op, op, tmp, 0, 1); 826 cast_change_ability (op, op, tmp, 0, 1);
867 tmp->destroy (); 827 tmp->destroy ();
868 return; 828 return;
869 } 829 }
870 830
871 continue; 831 continue;
872 } 832 }
873 833
874 /* Restore grace */ 834 /* Restore grace */
875 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0) 835 if (item->type == BOOK && item->invisible && item->name == shstr_restore_grace)
876 { 836 {
877 if (op->stats.grace >= 0) 837 if (op->stats.grace >= 0)
878 continue; 838 continue;
839
879 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH); 840 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH);
880 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace."); 841 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace.");
881 return; 842 return;
882 } 843 }
883 844
884 /* Heal damage */ 845 /* Heal damage */
885 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore hitpoints") == 0) 846 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore hitpoints") == 0)
886 { 847 {
887 if (op->stats.hp >= op->stats.maxhp) 848 if (op->stats.hp >= op->stats.maxhp)
888 continue; 849 continue;
850
889 new_draw_info (NDI_UNIQUE, 0, op, "A white light surrounds and heals you!"); 851 new_draw_info (NDI_UNIQUE, 0, op, "A white light surrounds and heals you!");
890 op->stats.hp = op->stats.maxhp; 852 op->stats.hp = op->stats.maxhp;
891 return; 853 return;
892 } 854 }
893 855
899 /* Restore to 50 .. 100%, if sp < 50% */ 861 /* Restore to 50 .. 100%, if sp < 50% */
900 int new_sp = (int) (random_roll (1000, 1999, op, PREFER_HIGH) / 2000.0 * max); 862 int new_sp = (int) (random_roll (1000, 1999, op, PREFER_HIGH) / 2000.0 * max);
901 863
902 if (op->stats.sp >= max / 2) 864 if (op->stats.sp >= max / 2)
903 continue; 865 continue;
866
904 new_draw_info (NDI_UNIQUE, 0, op, "A blue lightning strikes " "your head but doesn't hurt you!"); 867 new_draw_info (NDI_UNIQUE, 0, op, "A blue lightning strikes your head but doesn't hurt you!");
905 op->stats.sp = new_sp; 868 op->stats.sp = new_sp;
906 } 869 }
907 870
908 /* Various heal spells */ 871 /* Various heal spells */
909 if (item->type == BOOK && item->invisible && strcmp (item->name, "heal spell") == 0) 872 if (item->type == BOOK && item->invisible && strcmp (item->name, "heal spell") == 0)
910 { 873 {
911 object *tmp;
912 int success;
913
914 tmp = get_archetype_by_object_name (item->slaying); 874 object *tmp = archetype::get (item->slaying);
915
916 success = cast_heal (op, op, tmp, 0); 875 int success = cast_heal (op, op, tmp, 0);
917 tmp->destroy (); 876 tmp->destroy ();
877
918 if (success) 878 if (success)
919 return; 879 return;
920 else 880 else
921 continue; 881 continue;
922 } 882 }
949 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 909 if ((at = archetype::find (ARCH_DEPLETION)) == NULL)
950 { 910 {
951 LOG (llevError, "Could not find archetype depletion.\n"); 911 LOG (llevError, "Could not find archetype depletion.\n");
952 continue; 912 continue;
953 } 913 }
914
954 depl = present_arch_in_ob (at, op); 915 depl = present_arch_in_ob (at, op);
955 916
956 if (depl == NULL) 917 if (depl == NULL)
957 continue; 918 continue;
958 919
1029{ 990{
1030 int reaction = 1; 991 int reaction = 1;
1031 object *item = NULL, *skop; 992 object *item = NULL, *skop;
1032 993
1033 for (item = op->inv; item; item = item->below) 994 for (item = op->inv; item; item = item->below)
1034 {
1035 if (QUERY_FLAG (item, FLAG_APPLIED)) 995 if (QUERY_FLAG (item, FLAG_APPLIED))
1036 {
1037 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1); 996 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
1038 }
1039 }
1040 997
1041 /* well, well. Looks like we screwed up. Time for god's revenge */ 998 /* well, well. Looks like we screwed up. Time for god's revenge */
1042 if (reaction < 0) 999 if (reaction < 0)
1043 { 1000 {
1044 int loss = 10000000; 1001 int loss = 10000000;
1045 int angry = abs (reaction); 1002 int angry = abs (reaction);
1046 1003
1047 for (skop = op->inv; skop != NULL; skop = skop->below) 1004 for (skop = op->inv; skop; skop = skop->below)
1048 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 1005 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
1049 break; 1006 break;
1050 1007
1051 if (skop) 1008 if (skop)
1052 loss = (int) (0.05 * (float) skop->stats.exp); 1009 loss = 0.05f * skop->stats.exp;
1010
1053 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP); 1011 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
1012
1054 if (random_roll (0, angry, op, PREFER_LOW)) 1013 if (random_roll (0, angry, op, PREFER_LOW))
1055 { 1014 {
1056 object *tmp = get_archetype (LOOSE_MANA); 1015 object *tmp = get_archetype (LOOSE_MANA);
1057 1016
1058 cast_magic_storm (op, tmp, op->level + (angry * 3)); 1017 cast_magic_storm (op, tmp, op->level + (angry * 3));
1059 } 1018 }
1019
1060 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name); 1020 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
1061 } 1021 }
1022
1062 return reaction; 1023 return reaction;
1063} 1024}
1064 1025
1065/** 1026/**
1066 * God checks item the player is using. 1027 * God checks item the player is using.
1067 * Return either -1 (bad), 0 (neutral) or 1028 * Return either -1 (bad), 0 (neutral) or
1068 * 1 (item is ok). If you are using the item of an enemy 1029 * 1 (item is ok). If you are using the item of an enemy
1069 * god, it can be bad...-b.t. 1030 * god, it can be bad...-b.t.
1070 */ 1031 */
1071
1072int 1032int
1073god_examines_item (object *god, object *item) 1033god_examines_item (object *god, object *item)
1074{ 1034{
1075 char buf[MAX_BUF]; 1035 char buf[MAX_BUF];
1076 1036
1079 1039
1080 if (!item->title) 1040 if (!item->title)
1081 return 1; /* unclaimed item are ok */ 1041 return 1; /* unclaimed item are ok */
1082 1042
1083 sprintf (buf, "of %s", &god->name); 1043 sprintf (buf, "of %s", &god->name);
1084 if (!strcmp (item->title, buf)) 1044 if (!strcmp (&item->title, buf))
1085 return 1; /* belongs to that God */ 1045 return 1; /* belongs to that God */
1086 1046
1087 if (god->title) 1047 if (god->title)
1088 { /* check if we have any enemy blessed item */ 1048 { /* check if we have any enemy blessed item */
1089 sprintf (buf, "of %s", &god->title); 1049 sprintf (buf, "of %s", &god->title);
1090 if (!strcmp (item->title, buf)) 1050 if (!strcmp (&item->title, buf))
1091 { 1051 {
1092 if (item->env) 1052 if (item->env)
1093 { 1053 {
1094 char buf[MAX_BUF]; 1054 char buf[MAX_BUF];
1095 1055
1096 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1056 sprintf (buf, "Heretic! You are using %s!", query_name (item));
1097 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf); 1057 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf);
1098 } 1058 }
1059
1099 return -1; 1060 return -1;
1100 } 1061 }
1101 } 1062 }
1102 1063
1103 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */ 1064 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1105 1066
1106/** 1067/**
1107 * Returns priest's god's id. 1068 * Returns priest's god's id.
1108 * Straight calls lookup_god_by_name 1069 * Straight calls lookup_god_by_name
1109 */ 1070 */
1110
1111int 1071int
1112get_god (object *priest) 1072get_god (object *priest)
1113{ 1073{
1114 int godnr = lookup_god_by_name (determine_god (priest)); 1074 return lookup_god_by_name (determine_god (priest));
1115
1116 return godnr;
1117}
1118
1119/**
1120 * Returns a string that is the name of the god that should be natively worshipped by a
1121 * creature of who has race *race
1122 * if we can't find a god that is appropriate, we return NULL
1123 */
1124const char *
1125get_god_for_race (const char *race)
1126{
1127 godlink *gl = first_god;
1128 const char *godname = NULL;
1129
1130 if (race == NULL)
1131 return NULL;
1132 while (gl)
1133 {
1134 if (!strcasecmp (gl->arch->race, race))
1135 {
1136 godname = gl->name;
1137 break;
1138 }
1139 gl = gl->next;
1140 }
1141 return godname;
1142} 1075}
1143 1076
1144/** 1077/**
1145 * Changes the attributes of cone, smite, and ball spells as needed by the code. 1078 * Changes the attributes of cone, smite, and ball spells as needed by the code.
1146 * Returns false if there was no race to assign to the slaying field of the spell, but 1079 * Returns false if there was no race to assign to the slaying field of the spell, but

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines