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.31 by root, Thu Nov 8 19:43:27 2007 UTC vs.
Revision 1.45 by root, Thu Jan 1 16:05:13 2009 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
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->remove (); /* remove obj from players inv. */ 176 tmp->destroy ();
205 esrv_del_item (op->contr, tmp->count); /* notify client */
206 tmp->destroy (); /* free object */
207 } 177 }
208 178
209 if (tmp->inv) 179 if (tmp->inv)
210 follower_remove_similar_item (tmp, item); 180 follower_remove_similar_item (tmp, item);
211 } 181 }
237 * God gives an item to the player. 207 * God gives an item to the player.
238 */ 208 */
239static int 209static int
240god_gives_present (object *op, object *god, treasure *tr) 210god_gives_present (object *op, object *god, treasure *tr)
241{ 211{
242 object *tmp;
243
244 if (!tr->item) 212 if (!tr->item)
245 return 0; 213 return 0;
246 214
247 if (follower_has_similar_item (op, tr->item)) 215 if (follower_has_similar_item (op, tr->item))
248 return 0; 216 return 0;
249 217
250 tmp = arch_to_object (tr->item); 218 object *tmp = arch_to_object (tr->item);
251 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lets %s appear in your hands.", &god->name, query_short_name (tmp)); 219 new_draw_info_format (NDI_UNIQUE, 0, op, "%s lets %s appear in your hands.", &god->name, query_short_name (tmp));
252 tmp = insert_ob_in_ob (tmp, op); 220 op->insert (tmp);
253 if (op->type == PLAYER)
254 esrv_send_item (op, tmp);
255 221
256 return 1; 222 return 1;
257} 223}
258 224
259/** 225/**
406 { 372 {
407 remove = 0; 373 remove = 0;
408 break; 374 break;
409 } 375 }
410 } 376 }
377
411 if (remove) 378 if (remove)
412 { 379 do_forget_spell (op, tmp->name);
413 /* just do the work of removing the spell ourselves - we already
414 * know that the player knows the spell
415 */
416 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "You lose knowledge of %s.", &tmp->name);
417 player_unready_range_ob (op->contr, tmp);
418 tmp->destroy ();
419 }
420
421 } 380 }
422} 381}
423 382
424/** 383/**
425 * This function is called whenever a player has 384 * This function is called whenever a player has
433 object *old_god = NULL; /* old god */ 392 object *old_god = NULL; /* old god */
434 treasure *tr; 393 treasure *tr;
435 object *item, *skop, *next; 394 object *item, *skop, *next;
436 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. */
437 396
438
439 old_god = find_god (determine_god (op)); 397 old_god = find_god (determine_god (op));
440 398
441 /* take away any special god-characteristic items. */ 399 /* take away any special god-characteristic items. */
442 for (item = op->inv; item != NULL; item = next) 400 for (item = op->inv; item; item = next)
443 { 401 {
444 next = item->below; 402 next = item->below;
403
445 // 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
446 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible && 405 if (QUERY_FLAG (item, FLAG_STARTEQUIP) && item->invisible &&
447 (item->type != SKILL) && (item->type != FORCE)) 406 (item->type != SKILL) && (item->type != FORCE))
448 { 407 {
449
450 if (item->type == SPELL) 408 if (item->type == SPELL)
409 {
451 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 }
452 413
453 player_unready_range_ob (op->contr, item); 414 player_unready_range_ob (op->contr, item);
454 item->destroy (); 415 item->destroy ();
455 } 416 }
456 } 417 }
462 follower_remove_similar_item (op, tr->item); 423 follower_remove_similar_item (op, tr->item);
463 424
464 if (!op || !new_god) 425 if (!op || !new_god)
465 return; 426 return;
466 427
467 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))
468 { 429 {
469 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);
470 431
471 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)
472 { 433 {
475 cast_magic_storm (op, tmp, new_god->level + 10); 436 cast_magic_storm (op, tmp, new_god->level + 10);
476 } 437 }
477 438
478 return; 439 return;
479 } 440 }
480
481 441
482 /* give the player any special god-characteristic-items. */ 442 /* give the player any special god-characteristic-items. */
483 for (tr = new_god->randomitems->items; tr; tr = tr->next) 443 for (tr = new_god->randomitems->items; tr; tr = tr->next)
484 { 444 {
485 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK 445 if (tr->item && tr->item->invisible && tr->item->type != SPELLBOOK
486 && tr->item->type != BOOK && tr->item->type != SPELL) 446 && tr->item->type != BOOK && tr->item->type != SPELL)
487 god_gives_present (op, new_god, tr); 447 god_gives_present (op, new_god, tr);
488 } 448 }
489 449
490
491 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);
492 451
493 for (skop = op->inv; skop != NULL; skop = skop->below) 452 for (skop = op->inv; skop; skop = skop->below)
494 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 453 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
495 break; 454 break;
496 455
497 /* Player has no skill - give them the skill */ 456 /* Player has no skill - give them the skill */
498 if (!skop) 457 if (!skop)
499 {
500 /* 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,
501 * things are really messed up anyways. 459 * things are really messed up anyways.
502 */ 460 */
503 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);
504 link_player_skills (op);
505 }
506 462
507 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 463 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */
508 464
509 /* 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,
510 * so I set undeadified for that. 466 * so I set undeadified for that.
511 * - gros, 21th July 2006. 467 * - gros, 21th July 2006.
512 */ 468 */
513 if ((old_god) && (QUERY_FLAG (old_god, FLAG_UNDEAD))) 469 if (old_god && QUERY_FLAG (old_god, FLAG_UNDEAD))
514 { 470 {
515 CLEAR_FLAG (skop, FLAG_UNDEAD); 471 CLEAR_FLAG (skop, FLAG_UNDEAD);
516 undeadified = 1; 472 undeadified = 1;
517 } 473 }
518 474
519 if (skop->title) 475 if (skop->title)
520 { /* get rid of old god */ 476 {
477 /* get rid of old god */
521 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
522 /* 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 */
523 if (sk_applied || undeadified) 481 if (sk_applied || undeadified)
524 { 482 {
525
526 CLEAR_FLAG (skop, FLAG_APPLIED); 483 CLEAR_FLAG (skop, FLAG_APPLIED);
527 (void) change_abil (op, skop); 484 change_abil (op, skop);
528 } 485 }
529 } 486 }
530 487
531 /* now change to the new gods attributes to exp_obj */ 488 /* now change to the new gods attributes to exp_obj */
532 skop->title = new_god->name; 489 skop->title = new_god->name;
567 * 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
568 * 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.
569 */ 526 */
570 if (!present_in_ob_by_name (FORCE, "no weapon force", op)) 527 if (!present_in_ob_by_name (FORCE, "no weapon force", op))
571 update_priest_flag (new_god, skop, FLAG_USE_WEAPON); 528 update_priest_flag (new_god, skop, FLAG_USE_WEAPON);
529
572 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR); 530 update_priest_flag (new_god, skop, FLAG_USE_ARMOUR);
573 531
574 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons")) 532 if (worship_forbids_use (op, skop, FLAG_USE_WEAPON, "weapons"))
575 stop_using_item (op, WEAPON, 2); 533 stop_using_item (op, WEAPON, 2);
576 534
602 */ 560 */
603 561
604int 562int
605worship_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)
606{ 564{
607
608 if (QUERY_FLAG (op->arch, flag)) 565 if (QUERY_FLAG (op->arch, flag))
609 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag)) 566 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
610 { 567 {
611 update_priest_flag (exp_obj, op, flag); 568 update_priest_flag (exp_obj, op, flag);
612 if (QUERY_FLAG (op, flag)) 569 if (QUERY_FLAG (op, flag))
615 { 572 {
616 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);
617 return 1; 574 return 1;
618 } 575 }
619 } 576 }
577
620 return 0; 578 return 0;
621} 579}
622 580
623/** 581/**
624 * Unapplies up to number worth of items of type 582 * Unapplies up to number worth of items of type
661/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/ 619/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
662 CLEAR_FLAG (exp_ob, flag); 620 CLEAR_FLAG (exp_ob, flag);
663 }; 621 };
664} 622}
665 623
666
667
668archetype * 624archetype *
669determine_holy_arch (object *god, const char *type) 625determine_holy_arch (object *god, shstr_cmp type)
670{ 626{
671 treasure *tr; 627 treasure *tr;
672 628
673 if (!god || !god->randomitems) 629 if (!god || !god->randomitems)
674 { 630 {
675 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");
676 return NULL; 632 return 0;
677 } 633 }
678 634
679 for (tr = god->randomitems->items; tr; tr = tr->next) 635 for (tr = god->randomitems->items; tr; tr = tr->next)
680 { 636 {
681 if (!tr->item) 637 if (!tr->item)
682 continue; 638 continue;
683 639
684 object *item = tr->item; 640 object *item = tr->item;
685 641
686 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 642 if (item->type == BOOK && item->invisible && item->name == type)
687 return item->other_arch; 643 return item->other_arch;
688 } 644 }
645
689 return NULL; 646 return 0;
690} 647}
691 648
692/** 649/**
693 * God helps player by removing curse and/or damnation. 650 * God helps player by removing curse and/or damnation.
694 */ 651 */
695static int 652static int
696god_removes_curse (object *op, int remove_damnation) 653god_removes_curse (object *op, int remove_damnation)
697{ 654{
698 object *tmp;
699 int success = 0; 655 int success = 0;
700 656
701 for (tmp = op->inv; tmp; tmp = tmp->below) 657 for (object *tmp = op->inv; tmp; tmp = tmp->below)
702 { 658 {
703 if (tmp->invisible) 659 if (tmp->invisible)
704 continue; 660 continue;
661
705 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation) 662 if (QUERY_FLAG (tmp, FLAG_DAMNED) && !remove_damnation)
706 continue; 663 continue;
664
707 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 665 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
708 { 666 {
709 success = 1; 667 success = 1;
710 CLEAR_FLAG (tmp, FLAG_DAMNED); 668 CLEAR_FLAG (tmp, FLAG_DAMNED);
711 CLEAR_FLAG (tmp, FLAG_CURSED); 669 CLEAR_FLAG (tmp, FLAG_CURSED);
712 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED); 670 CLEAR_FLAG (tmp, FLAG_KNOWN_CURSED);
713 if (op->type == PLAYER) 671
672 if (object *pl = tmp->visible_to ())
714 esrv_send_item (op, tmp); 673 esrv_update_item (UPD_FLAGS, pl, tmp);
715 } 674 }
716 } 675 }
717 676
718 if (success) 677 if (success)
719 new_draw_info (NDI_UNIQUE, 0, op, "You feel like someone is helping you."); 678 new_draw_info (NDI_UNIQUE, 0, op, "You feel like someone is helping you.");
679
720 return success; 680 return success;
721} 681}
722 682
723static int 683static int
724follower_level_to_enchantments (int level, int difficulty) 684follower_level_to_enchantments (int level, int difficulty)
729 return 0; 689 return 0;
730 } 690 }
731 691
732 if (level <= 20) 692 if (level <= 20)
733 return level / difficulty; 693 return level / difficulty;
694
734 if (level <= 40) 695 if (level <= 40)
735 return (20 + (level - 20) / 2) / difficulty; 696 return (20 + (level - 20) / 2) / difficulty;
736 697
737 return (30 + (level - 40) / 4) / difficulty; 698 return (30 + (level - 40) / 4) / difficulty;
738} 699}
744 * attacktype, slaying and such. 705 * attacktype, slaying and such.
745 */ 706 */
746static int 707static int
747god_enchants_weapon (object *op, object *god, object *tr, object *skill) 708god_enchants_weapon (object *op, object *god, object *tr, object *skill)
748{ 709{
749 char buf[MAX_BUF];
750 object *weapon; 710 object *weapon;
751 uint32 attacktype; 711 uint32 attacktype;
752 int tmp; 712 int tmp;
753 713
754 for (weapon = op->inv; weapon; weapon = weapon->below) 714 for (weapon = op->inv; weapon; weapon = weapon->below)
755 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))
756 break; 716 break;
757 717
758 if (weapon == NULL || god_examines_item (god, weapon) <= 0) 718 if (!weapon || god_examines_item (god, weapon) <= 0)
759 return 0; 719 return 0;
760 720
761 /* 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 */
762 if (!weapon->title) 722 if (!weapon->title)
763 { 723 {
764 sprintf (buf, "of %s", &god->name); 724 weapon->title = format ("of %s", &god->name);
765 weapon->title = buf; 725
766 if (op->type == PLAYER) 726 if (object *pl = weapon->visible_to ())
767 esrv_update_item (UPD_NAME, op, weapon); 727 esrv_update_item (UPD_NAME, pl, weapon);
728
768 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!");
769 } 730 }
770 731
771 /* Allow the weapon to slay enemies */ 732 /* Allow the weapon to slay enemies */
772 if (!weapon->slaying && god->slaying) 733 if (!weapon->slaying && god->slaying)
789 tmp = follower_level_to_enchantments (skill->level, tr->level); 750 tmp = follower_level_to_enchantments (skill->level, tr->level);
790 if (weapon->magic < tmp) 751 if (weapon->magic < tmp)
791 { 752 {
792 new_draw_info (NDI_UNIQUE, 0, op, "A phosphorescent glow envelops your weapon!"); 753 new_draw_info (NDI_UNIQUE, 0, op, "A phosphorescent glow envelops your weapon!");
793 weapon->magic++; 754 weapon->magic++;
794 if (op->type == PLAYER) 755
756 if (object *pl = weapon->visible_to ())
795 esrv_update_item (UPD_NAME, op, weapon); 757 esrv_update_item (UPD_NAME, pl, weapon);
758
796 return 1; 759 return 1;
797 } 760 }
798 761
799 return 0; 762 return 0;
800} 763}
840 if (tl == NULL) 803 if (tl == NULL)
841 continue; 804 continue;
842 805
843 new_draw_info (NDI_UNIQUE, 0, op, "Something appears before your eyes. You catch it before it falls to the ground."); 806 new_draw_info (NDI_UNIQUE, 0, op, "Something appears before your eyes. You catch it before it falls to the ground.");
844 807
845 create_treasure (tl, op, GT_STARTEQUIP | GT_ONLY_GOOD | GT_UPDATE_INV, skill->level, 0); 808 create_treasure (tl, op, GT_STARTEQUIP | GT_ONLY_GOOD, skill->level, 0);
846 return; 809 return;
847 } 810 }
848 811
849 if (!tr->item) 812 if (!tr->item)
850 continue; 813 continue;
851 814
852 item = tr->item; 815 item = tr->item;
853 816
854 /* Grace limit */ 817 /* Grace limit */
855 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0) 818 if (item->type == BOOK && item->invisible && item->name == shstr_grace_limit)
856 { 819 {
857 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)
858 { 821 {
859 object *tmp;
860
861 /* Follower lacks the required grace for the following 822 /* Follower lacks the required grace for the following
862 * treasure list items. */ 823 * treasure list items. */
863 824
864 tmp = get_archetype (HOLY_POSSESSION); 825 object *tmp = get_archetype (HOLY_POSSESSION);
865 cast_change_ability (op, op, tmp, 0, 1); 826 cast_change_ability (op, op, tmp, 0, 1);
866 tmp->destroy (); 827 tmp->destroy ();
867 return; 828 return;
868 } 829 }
869 830
870 continue; 831 continue;
871 } 832 }
872 833
873 /* Restore grace */ 834 /* Restore grace */
874 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0) 835 if (item->type == BOOK && item->invisible && item->name == shstr_restore_grace)
875 { 836 {
876 if (op->stats.grace >= 0) 837 if (op->stats.grace >= 0)
877 continue; 838 continue;
839
878 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH); 840 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH);
879 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.");
880 return; 842 return;
881 } 843 }
882 844
883 /* Heal damage */ 845 /* Heal damage */
884 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)
885 { 847 {
886 if (op->stats.hp >= op->stats.maxhp) 848 if (op->stats.hp >= op->stats.maxhp)
887 continue; 849 continue;
850
888 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!");
889 op->stats.hp = op->stats.maxhp; 852 op->stats.hp = op->stats.maxhp;
890 return; 853 return;
891 } 854 }
892 855
898 /* Restore to 50 .. 100%, if sp < 50% */ 861 /* Restore to 50 .. 100%, if sp < 50% */
899 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);
900 863
901 if (op->stats.sp >= max / 2) 864 if (op->stats.sp >= max / 2)
902 continue; 865 continue;
866
903 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!");
904 op->stats.sp = new_sp; 868 op->stats.sp = new_sp;
905 } 869 }
906 870
907 /* Various heal spells */ 871 /* Various heal spells */
908 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)
909 { 873 {
910 object *tmp;
911 int success;
912
913 tmp = get_archetype_by_object_name (item->slaying); 874 object *tmp = archetype::get (item->slaying);
914
915 success = cast_heal (op, op, tmp, 0); 875 int success = cast_heal (op, op, tmp, 0);
916 tmp->destroy (); 876 tmp->destroy ();
877
917 if (success) 878 if (success)
918 return; 879 return;
919 else 880 else
920 continue; 881 continue;
921 } 882 }
948 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 909 if ((at = archetype::find (ARCH_DEPLETION)) == NULL)
949 { 910 {
950 LOG (llevError, "Could not find archetype depletion.\n"); 911 LOG (llevError, "Could not find archetype depletion.\n");
951 continue; 912 continue;
952 } 913 }
914
953 depl = present_arch_in_ob (at, op); 915 depl = present_arch_in_ob (at, op);
954 916
955 if (depl == NULL) 917 if (depl == NULL)
956 continue; 918 continue;
957 919
1028{ 990{
1029 int reaction = 1; 991 int reaction = 1;
1030 object *item = NULL, *skop; 992 object *item = NULL, *skop;
1031 993
1032 for (item = op->inv; item; item = item->below) 994 for (item = op->inv; item; item = item->below)
1033 {
1034 if (QUERY_FLAG (item, FLAG_APPLIED)) 995 if (QUERY_FLAG (item, FLAG_APPLIED))
1035 {
1036 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);
1037 }
1038 }
1039 997
1040 /* 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 */
1041 if (reaction < 0) 999 if (reaction < 0)
1042 { 1000 {
1043 int loss = 10000000; 1001 int loss = 10000000;
1044 int angry = abs (reaction); 1002 int angry = abs (reaction);
1045 1003
1046 for (skop = op->inv; skop != NULL; skop = skop->below) 1004 for (skop = op->inv; skop; skop = skop->below)
1047 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 1005 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
1048 break; 1006 break;
1049 1007
1050 if (skop) 1008 if (skop)
1051 loss = (int) (0.05 * (float) skop->stats.exp); 1009 loss = 0.05f * skop->stats.exp;
1010
1052 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
1053 if (random_roll (0, angry, op, PREFER_LOW)) 1013 if (random_roll (0, angry, op, PREFER_LOW))
1054 { 1014 {
1055 object *tmp = get_archetype (LOOSE_MANA); 1015 object *tmp = get_archetype (LOOSE_MANA);
1056 1016
1057 cast_magic_storm (op, tmp, op->level + (angry * 3)); 1017 cast_magic_storm (op, tmp, op->level + (angry * 3));
1058 } 1018 }
1019
1059 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);
1060 } 1021 }
1022
1061 return reaction; 1023 return reaction;
1062} 1024}
1063 1025
1064/** 1026/**
1065 * God checks item the player is using. 1027 * God checks item the player is using.
1066 * Return either -1 (bad), 0 (neutral) or 1028 * Return either -1 (bad), 0 (neutral) or
1067 * 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
1068 * god, it can be bad...-b.t. 1030 * god, it can be bad...-b.t.
1069 */ 1031 */
1070
1071int 1032int
1072god_examines_item (object *god, object *item) 1033god_examines_item (object *god, object *item)
1073{ 1034{
1074 char buf[MAX_BUF]; 1035 char buf[MAX_BUF];
1075 1036
1078 1039
1079 if (!item->title) 1040 if (!item->title)
1080 return 1; /* unclaimed item are ok */ 1041 return 1; /* unclaimed item are ok */
1081 1042
1082 sprintf (buf, "of %s", &god->name); 1043 sprintf (buf, "of %s", &god->name);
1083 if (!strcmp (item->title, buf)) 1044 if (!strcmp (&item->title, buf))
1084 return 1; /* belongs to that God */ 1045 return 1; /* belongs to that God */
1085 1046
1086 if (god->title) 1047 if (god->title)
1087 { /* check if we have any enemy blessed item */ 1048 { /* check if we have any enemy blessed item */
1088 sprintf (buf, "of %s", &god->title); 1049 sprintf (buf, "of %s", &god->title);
1089 if (!strcmp (item->title, buf)) 1050 if (!strcmp (&item->title, buf))
1090 { 1051 {
1091 if (item->env) 1052 if (item->env)
1092 { 1053 {
1093 char buf[MAX_BUF]; 1054 char buf[MAX_BUF];
1094 1055
1095 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1056 sprintf (buf, "Heretic! You are using %s!", query_name (item));
1096 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf); 1057 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf);
1097 } 1058 }
1059
1098 return -1; 1060 return -1;
1099 } 1061 }
1100 } 1062 }
1101 1063
1102 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 */
1104 1066
1105/** 1067/**
1106 * Returns priest's god's id. 1068 * Returns priest's god's id.
1107 * Straight calls lookup_god_by_name 1069 * Straight calls lookup_god_by_name
1108 */ 1070 */
1109
1110int 1071int
1111get_god (object *priest) 1072get_god (object *priest)
1112{ 1073{
1113 int godnr = lookup_god_by_name (determine_god (priest)); 1074 return lookup_god_by_name (determine_god (priest));
1114
1115 return godnr;
1116}
1117
1118/**
1119 * Returns a string that is the name of the god that should be natively worshipped by a
1120 * creature of who has race *race
1121 * if we can't find a god that is appropriate, we return NULL
1122 */
1123const char *
1124get_god_for_race (const char *race)
1125{
1126 godlink *gl = first_god;
1127 const char *godname = NULL;
1128
1129 if (race == NULL)
1130 return NULL;
1131 while (gl)
1132 {
1133 if (!strcasecmp (gl->arch->race, race))
1134 {
1135 godname = gl->name;
1136 break;
1137 }
1138 gl = gl->next;
1139 }
1140 return godname;
1141} 1075}
1142 1076
1143/** 1077/**
1144 * 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.
1145 * 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