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.40 by root, Mon Sep 29 10:32:50 2008 UTC vs.
Revision 1.53 by root, Sat Nov 7 18:30:06 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 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 it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and 25/* Oct 3, 1995 - Code laid down for initial gods, priest alignment, and
35#include <sproto.h> 36#include <sproto.h>
36 37
37/** 38/**
38 * Returns the id of specified god. 39 * Returns the id of specified god.
39 */ 40 */
40int 41static int
41lookup_god_by_name (const char *name) 42lookup_god_by_name (shstr_cmp name)
42{ 43{
43 int godnr = -1; 44 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) 45 for (godlink *gl = first_god; gl; gl = gl->next)
51 if (!strncmp (name, gl->name, MIN ((size_t) strlen (gl->name), nmlen))) 46 if (gl->name == name)
52 break;
53
54 if (gl)
55 godnr = gl->id; 47 return gl->id;
56 }
57 48
58 return godnr; 49 return -1;
59} 50}
60 51
61/** 52/**
62 * Returns pointer to specified god's object through pntr_to_god_obj.. 53 * Returns pointer to specified god's object through pntr_to_god_obj..
63 */ 54 */
64object * 55object *
65find_god (const char *name) 56find_god (shstr_cmp name)
66{ 57{
67 object *god = NULL;
68
69 if (name) 58 if (name)
70 {
71 godlink *gl;
72
73 for (gl = first_god; gl; gl = gl->next) 59 for (godlink *gl = first_god; gl; gl = gl->next)
74 if (!strcmp (name, gl->name)) 60 if (gl->name == name)
75 break;
76 if (gl)
77 god = pntr_to_god_obj (gl); 61 return pntr_to_god_obj (gl);
78 } 62
79 return god; 63 return 0;
64}
65
66/**
67 * Returns a string that is the name of the god that should be natively worshipped by a
68 * creature of who has race *race
69 * if we can't find a god that is appropriate, we return NULL
70 */
71static shstr_tmp
72get_god_for_race (shstr_cmp race)
73{
74 if (race)
75 for (godlink *gl = first_god; gl; gl = gl->next)
76 if (gl->arch->race == race)
77 return gl->name;
78
79 return shstr_tmp ();
80} 80}
81 81
82/** 82/**
83 * Determines if op worships a god. 83 * Determines if op worships a god.
84 * Returns the godname if they do or "none" if they have no god. 84 * 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 85 * 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 86 * who they should worship based on their race. If that fails we
87 * give them a random one. 87 * give them a random one.
88 */ 88 */
89 89shstr_tmp
90const char *
91determine_god (object *op) 90determine_god (object *op)
92{ 91{
93 int godnr = -1;
94 const char *godname;
95
96 /* spells */ 92 /* spells */
97 if ((op->type == SPELL || op->type == SPELL_EFFECT) && op->title) 93 if ((op->type == SPELL || op->type == SPELL_EFFECT) && op->title)
98 {
99 if (lookup_god_by_name (op->title) >= 0) 94 if (lookup_god_by_name (op->title) >= 0)
100 return op->title; 95 return op->title;
96
97 if (!op->is_player () && op->flag [FLAG_ALIVE])
101 } 98 {
102
103 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_ALIVE))
104 {
105
106 /* find a god based on race */ 99 /* find a god based on race */
107 if (!op->title) 100 if (!op->title)
108 {
109 if (op->race)
110 {
111 godname = get_god_for_race (op->race); 101 op->title = get_god_for_race (op->race);
112
113 if (godname)
114 op->title = godname;
115 }
116 }
117 102
118 /* find a random god */ 103 /* find a random god */
119 if (!op->title) 104 if (!op->title)
120 { 105 {
121 godlink *gl = first_god;
122
123 godnr = rndm (1, gl->id); 106 int godnr = rndm (1, first_god->id);
124 while (gl) 107
125 { 108 for (godlink *gl = first_god; gl; gl = gl->next)
126 if (gl->id == godnr) 109 if (gl->id == godnr)
110 {
111 op->title = gl->name;
127 break; 112 break;
128
129 gl = gl->next;
130 } 113 }
131
132 op->title = gl->name;
133 } 114 }
134 115
135 return op->title; 116 return op->title;
136 } 117 }
137
138 118
139 /* The god the player worships is in the praying skill (native skill 119 /* 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 120 * 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 121 * that skill, once we find it, we can return, either with the
142 * title or "none". 122 * title or "none".
143 */ 123 */
144 if (op->type == PLAYER) 124 if (op->type == PLAYER)
145 {
146 for (object *tmp = op->inv; tmp; tmp = tmp->below) 125 for (object *tmp = op->inv; tmp; tmp = tmp->below)
147 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING) 126 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING)
148 { 127 {
149 if (tmp->title) 128 if (tmp->title)
150 return tmp->title; 129 return tmp->title;
151 else 130
152 return "none"; 131 break;
153 } 132 }
154 }
155 133
156 return "none"; 134 return shstr_none;
157} 135}
158 136
159/** 137/**
160 * Returns 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0 138 * Returns 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0
161 */ 139 */
162static int 140static int
163same_string (const char *s1, const char *s2) 141same_string (const char *s1, const char *s2)
164{ 142{
165 if (s1 == NULL) 143 if (s1 == s2)
166 if (s2 == NULL)
167 return 1; 144 return 1;
145 else if (s1 && s2)
146 return !strcmp (s1, s2);
168 else 147 else
169 return 0;
170 else if (s2 == NULL)
171 return 0; 148 return 0;
172 else
173 return strcmp (s1, s2) == 0;
174} 149}
175 150
176/** 151/**
177 * Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively). 152 * 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 153 * Any matching items in the inventory are deleted, and a
247 222
248 return 1; 223 return 1;
249} 224}
250 225
251/** 226/**
252 * Player prays at altar.
253 * Checks for god changing, divine intervention, and so on.
254 */
255void
256pray_at_altar (object *pl, object *altar, object *skill)
257{
258 object *pl_god = find_god (determine_god (pl));
259
260 if (INVOKE_PLAYER (PRAY_ALTAR, pl->contr, ARG_OBJECT (altar), ARG_OBJECT (skill)))
261 return;
262
263 /* If non consecrate altar, don't do anything */
264 if (!altar->other_arch)
265 return;
266
267 /* hmm. what happend depends on pl's current god, level, etc */
268 if (!pl_god)
269 { /*new convert */
270 become_follower (pl, altar->other_arch);
271 return;
272 }
273 else if (!strcmp (&pl_god->name, altar->other_arch->object::name))
274 {
275 /* pray at your gods altar */
276 int bonus = (pl->stats.Wis + skill->level) / 10;
277
278 /* we can get neg grace up faster */
279 if (pl->stats.grace < 0)
280 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
281
282 /* we can super-charge grace to 2x max */
283 if (pl->stats.grace < 2 * pl->stats.maxgrace)
284 pl->stats.grace += bonus / 2;
285 else
286 pl->stats.grace = 2 * pl->stats.maxgrace;
287
288 /* Every once in a while, the god decides to checkup on their
289 * follower, and may intervene to help them out.
290 */
291 bonus = MAX (1, bonus + MAX (pl->stats.luck, -3)); /* -- DAMN -- */
292
293 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
294 god_intervention (pl, pl_god, skill);
295 }
296 else
297 { /* praying to another god! */
298 uint64 loss = 0;
299 int angry = 1;
300
301 /* I believe the logic for detecting opposing gods was completely
302 * broken - I think it should work now. altar->other_arch
303 * points to the god of this altar (which we have
304 * already verified is non null). pl_god->other_arch
305 * is the opposing god - we need to verify that exists before
306 * using its values.
307 */
308 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
309 {
310 angry = 2;
311 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
312 {
313 object *tmp;
314
315 /* you really screwed up */
316 angry = 3;
317 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foul Priest! %s punishes you!", &pl_god->name);
318 tmp = get_archetype (LOOSE_MANA);
319 cast_magic_storm (pl, tmp, pl_god->level + 20);
320 }
321 else
322 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foolish heretic! %s is livid!", &pl_god->name);
323 }
324 else
325 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Heretic! %s is angered!", &pl_god->name);
326
327 /* whether we will be successfull in defecting or not -
328 * we lose experience from the clerical experience obj
329 */
330
331 loss = angry * (skill->stats.exp / 10);
332 if (loss)
333 change_exp (pl, -random_roll64 (0, loss, pl, PREFER_LOW), skill ? &skill->skill : "none", SK_SUBTRACT_SKILL_EXP);
334
335 /* May switch Gods, but its random chance based on our current level
336 * note it gets harder to swap gods the higher we get
337 */
338 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
339 become_follower (pl, altar->other_arch);
340 else
341 {
342 /* toss this player off the altar. He can try again. */
343 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
344 pl->contr->fire_on = 0;
345 pl->speed_left = 1.f;
346 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
347 }
348 }
349}
350
351/**
352 * Removes special prayers given by a god. 227 * Removes special prayers given by a god.
353 */ 228 */
354static void 229static void
355check_special_prayers (object *op, object *god) 230check_special_prayers (object *op, object *god)
356{ 231{
405 do_forget_spell (op, tmp->name); 280 do_forget_spell (op, tmp->name);
406 } 281 }
407} 282}
408 283
409/** 284/**
285 * Unapplies up to number worth of items of type
286 */
287static void
288stop_using_item (object *op, int type, int number)
289{
290 object *tmp;
291
292 for (tmp = op->inv; tmp && number; tmp = tmp->below)
293 if (tmp->type == type && QUERY_FLAG (tmp, FLAG_APPLIED))
294 {
295 apply_special (op, tmp, AP_UNAPPLY | AP_IGNORE_CURSE);
296 number--;
297 }
298}
299
300/**
301 * If the god does/doesnt have this flag, we
302 * give/remove it from the experience object if it doesnt/does
303 * already exist. For players only!
304 */
305static void
306update_priest_flag (object *god, object *exp_ob, uint32 flag)
307{
308 if (QUERY_FLAG (god, flag) && !QUERY_FLAG (exp_ob, flag))
309 SET_FLAG (exp_ob, flag);
310 else if (QUERY_FLAG (exp_ob, flag) && !QUERY_FLAG (god, flag))
311 {
312 /* When this is called with the exp_ob set to the player,
313 * this check is broken, because most all players arch
314 * allow use of weapons. I'm not actually sure why this
315 * check is here - I guess if you had a case where the
316 * value in the archetype (wisdom) should over ride the restrictions
317 * the god places on it, this may make sense. But I don't think
318 * there is any case like that.
319 */
320
321/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
322 CLEAR_FLAG (exp_ob, flag);
323 };
324}
325
326/**
327 * Forbids or let player use something item type.
328 * op is the player.
329 * exp_obj is the widsom experience.
330 * flag is the flag to check against.
331 * string is the string to print out.
332 */
333static int
334worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
335{
336 if (QUERY_FLAG (op->arch, flag))
337 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
338 {
339 update_priest_flag (exp_obj, op, flag);
340 if (QUERY_FLAG (op, flag))
341 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
342 else
343 {
344 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
345 return 1;
346 }
347 }
348
349 return 0;
350}
351
352/**
410 * This function is called whenever a player has 353 * This function is called whenever a player has
411 * switched to a new god. It handles basically all the stat changes 354 * switched to a new god. It handles basically all the stat changes
412 * that happen to the player, including the removal of godgiven 355 * that happen to the player, including the removal of godgiven
413 * items (from the former cult). 356 * items (from the former cult).
414 */ 357 */
449 follower_remove_similar_item (op, tr->item); 392 follower_remove_similar_item (op, tr->item);
450 393
451 if (!op || !new_god) 394 if (!op || !new_god)
452 return; 395 return;
453 396
454 if (op->race && new_god->slaying && strstr (op->race, new_god->slaying)) 397 if (new_god->slaying && op->race.contains (new_god->slaying))
455 { 398 {
456 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name); 399 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name);
457 400
458 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0) 401 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0)
459 { 402 {
575 CLEAR_FLAG (skop, FLAG_APPLIED); 518 CLEAR_FLAG (skop, FLAG_APPLIED);
576 519
577 check_special_prayers (op, new_god); 520 check_special_prayers (op, new_god);
578} 521}
579 522
580/**
581 * Forbids or let player use something item type.
582 * op is the player.
583 * exp_obj is the widsom experience.
584 * flag is the flag to check against.
585 * string is the string to print out.
586 */
587
588int
589worship_forbids_use (object *op, object *exp_obj, uint32 flag, const char *string)
590{
591 if (QUERY_FLAG (op->arch, flag))
592 if (QUERY_FLAG (op, flag) != QUERY_FLAG (exp_obj, flag))
593 {
594 update_priest_flag (exp_obj, op, flag);
595 if (QUERY_FLAG (op, flag))
596 new_draw_info_format (NDI_UNIQUE, 0, op, "You may use %s again.", string);
597 else
598 {
599 new_draw_info_format (NDI_UNIQUE, 0, op, "You are forbidden to use %s.", string);
600 return 1;
601 }
602 }
603
604 return 0;
605}
606
607/**
608 * Unapplies up to number worth of items of type
609 */
610void
611stop_using_item (object *op, int type, int number)
612{
613 object *tmp;
614
615 for (tmp = op->inv; tmp && number; tmp = tmp->below)
616 if (tmp->type == type && QUERY_FLAG (tmp, FLAG_APPLIED))
617 {
618 apply_special (op, tmp, AP_UNAPPLY | AP_IGNORE_CURSE);
619 number--;
620 }
621}
622
623/**
624 * If the god does/doesnt have this flag, we
625 * give/remove it from the experience object if it doesnt/does
626 * already exist. For players only!
627 */
628
629void
630update_priest_flag (object *god, object *exp_ob, uint32 flag)
631{
632 if (QUERY_FLAG (god, flag) && !QUERY_FLAG (exp_ob, flag))
633 SET_FLAG (exp_ob, flag);
634 else if (QUERY_FLAG (exp_ob, flag) && !QUERY_FLAG (god, flag))
635 {
636 /* When this is called with the exp_ob set to the player,
637 * this check is broken, because most all players arch
638 * allow use of weapons. I'm not actually sure why this
639 * check is here - I guess if you had a case where the
640 * value in the archetype (wisdom) should over ride the restrictions
641 * the god places on it, this may make sense. But I don't think
642 * there is any case like that.
643 */
644
645/* if (!(QUERY_FLAG(&(exp_ob->arch->clone),flag)))*/
646 CLEAR_FLAG (exp_ob, flag);
647 };
648}
649
650archetype * 523archetype *
651determine_holy_arch (object *god, const char *type) 524determine_holy_arch (object *god, shstr_cmp type)
652{ 525{
653 treasure *tr; 526 treasure *tr;
654 527
655 if (!god || !god->randomitems) 528 if (!god || !god->randomitems)
656 { 529 {
663 if (!tr->item) 536 if (!tr->item)
664 continue; 537 continue;
665 538
666 object *item = tr->item; 539 object *item = tr->item;
667 540
668 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 541 if (item->type == BOOK && item->invisible && item->name == type)
669 return item->other_arch; 542 return item->other_arch;
670 } 543 }
671 544
672 return 0; 545 return 0;
673} 546}
723 596
724 return (30 + (level - 40) / 4) / difficulty; 597 return (30 + (level - 40) / 4) / difficulty;
725} 598}
726 599
727/** 600/**
601 * God checks item the player is using.
602 * Return either -1 (bad), 0 (neutral) or
603 * 1 (item is ok). If you are using the item of an enemy
604 * god, it can be bad...-b.t.
605 */
606static int
607god_examines_item (object *god, object *item)
608{
609 char buf[MAX_BUF];
610
611 if (!god || !item)
612 return 0;
613
614 if (!item->title)
615 return 1; /* unclaimed item are ok */
616
617 sprintf (buf, "of %s", &god->name);
618 if (!strcmp (&item->title, buf))
619 return 1; /* belongs to that God */
620
621 if (god->title)
622 { /* check if we have any enemy blessed item */
623 sprintf (buf, "of %s", &god->title);
624 if (!strcmp (&item->title, buf))
625 {
626 if (item->env)
627 {
628 char buf[MAX_BUF];
629
630 sprintf (buf, "Heretic! You are using %s!", query_name (item));
631 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf);
632 }
633
634 return -1;
635 }
636 }
637
638 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
639}
640
641/**
728 * God wants to enchant weapon. 642 * God wants to enchant weapon.
729 * Affected weapon is the applied one (weapon or bow). It's checked to make sure 643 * Affected weapon is the applied one (weapon or bow). It's checked to make sure
730 * it isn't a weapon for another god. If all is all right, update weapon with 644 * it isn't a weapon for another god. If all is all right, update weapon with
731 * attacktype, slaying and such. 645 * attacktype, slaying and such.
732 */ 646 */
787 701
788 return 0; 702 return 0;
789} 703}
790 704
791/** 705/**
706 * Checks and maybe punishes someone praying.
707 * All applied items are examined, if player is using more items of other gods,
708 * s/he loses experience in praying or general experience if no praying.
709 */
710static int
711god_examines_priest (object *op, object *god)
712{
713 int reaction = 1;
714 object *item = NULL, *skop;
715
716 for (item = op->inv; item; item = item->below)
717 if (QUERY_FLAG (item, FLAG_APPLIED))
718 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
719
720 /* well, well. Looks like we screwed up. Time for god's revenge */
721 if (reaction < 0)
722 {
723 int loss = 10000000;
724 int angry = abs (reaction);
725
726 for (skop = op->inv; skop; skop = skop->below)
727 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
728 break;
729
730 if (skop)
731 loss = 0.05f * skop->stats.exp;
732
733 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
734
735 if (random_roll (0, angry, op, PREFER_LOW))
736 {
737 object *tmp = get_archetype (LOOSE_MANA);
738
739 cast_magic_storm (op, tmp, op->level + (angry * 3));
740 }
741
742 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
743 }
744
745 return reaction;
746}
747
748/**
792 * Every once in a while the god will intervene to help the worshiper. 749 * Every once in a while the god will intervene to help the worshiper.
793 * Later, this fctn can be used to supply quests, etc for the 750 * Later, this fctn can be used to supply quests, etc for the
794 * priest. -b.t. 751 * priest. -b.t.
795 * called from pray_at_altar() currently. 752 * called from pray_at_altar() currently.
796 */ 753 */
797void 754static void
798god_intervention (object *op, object *god, object *skill) 755god_intervention (object *op, object *god, object *skill)
799{ 756{
800 treasure *tr; 757 treasure *tr;
801 758
802 if (!god || !god->randomitems) 759 if (!god || !god->randomitems)
839 continue; 796 continue;
840 797
841 item = tr->item; 798 item = tr->item;
842 799
843 /* Grace limit */ 800 /* Grace limit */
844 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0) 801 if (item->type == BOOK && item->invisible && item->name == shstr_grace_limit)
845 { 802 {
846 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace) 803 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace)
847 { 804 {
848 object *tmp;
849
850 /* Follower lacks the required grace for the following 805 /* Follower lacks the required grace for the following
851 * treasure list items. */ 806 * treasure list items. */
852 807
853 tmp = get_archetype (HOLY_POSSESSION); 808 object *tmp = get_archetype (HOLY_POSSESSION);
854 cast_change_ability (op, op, tmp, 0, 1); 809 cast_change_ability (op, op, tmp, 0, 1);
855 tmp->destroy (); 810 tmp->destroy ();
856 return; 811 return;
857 } 812 }
858 813
859 continue; 814 continue;
860 } 815 }
861 816
862 /* Restore grace */ 817 /* Restore grace */
863 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0) 818 if (item->type == BOOK && item->invisible && item->name == shstr_restore_grace)
864 { 819 {
865 if (op->stats.grace >= 0) 820 if (op->stats.grace >= 0)
866 continue; 821 continue;
822
867 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH); 823 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH);
868 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace."); 824 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace.");
869 return; 825 return;
870 } 826 }
871 827
872 /* Heal damage */ 828 /* Heal damage */
873 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore hitpoints") == 0) 829 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore hitpoints") == 0)
874 { 830 {
875 if (op->stats.hp >= op->stats.maxhp) 831 if (op->stats.hp >= op->stats.maxhp)
876 continue; 832 continue;
833
877 new_draw_info (NDI_UNIQUE, 0, op, "A white light surrounds and heals you!"); 834 new_draw_info (NDI_UNIQUE, 0, op, "A white light surrounds and heals you!");
878 op->stats.hp = op->stats.maxhp; 835 op->stats.hp = op->stats.maxhp;
879 return; 836 return;
880 } 837 }
881 838
930 { 887 {
931 object *depl; 888 object *depl;
932 archetype *at; 889 archetype *at;
933 int i; 890 int i;
934 891
935 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 892 if ((at = archetype::find (shstr_depletion)) == NULL)
936 { 893 {
937 LOG (llevError, "Could not find archetype depletion.\n"); 894 LOG (llevError, "Could not find archetype depletion.\n");
938 continue; 895 continue;
939 } 896 }
897
940 depl = present_arch_in_ob (at, op); 898 depl = present_arch_in_ob (at, op);
941 899
942 if (depl == NULL) 900 if (depl == NULL)
943 continue; 901 continue;
944 902
1004 962
1005 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture."); 963 new_draw_info (NDI_UNIQUE, 0, op, "You feel rapture.");
1006} 964}
1007 965
1008/** 966/**
1009 * Checks and maybe punishes someone praying. 967 * Player prays at altar.
1010 * All applied items are examined, if player is using more items of other gods, 968 * Checks for god changing, divine intervention, and so on.
1011 * s/he loses experience in praying or general experience if no praying.
1012 */ 969 */
1013int 970void
1014god_examines_priest (object *op, object *god) 971pray_at_altar (object *pl, object *altar, object *skill)
1015{ 972{
1016 int reaction = 1; 973 object *pl_god = find_god (determine_god (pl));
1017 object *item = NULL, *skop;
1018 974
1019 for (item = op->inv; item; item = item->below) 975 if (INVOKE_PLAYER (PRAY_ALTAR, pl->contr, ARG_OBJECT (altar), ARG_OBJECT (skill)))
1020 if (QUERY_FLAG (item, FLAG_APPLIED))
1021 reaction += god_examines_item (god, item) * (item->magic ? abs (item->magic) : 1);
1022
1023 /* well, well. Looks like we screwed up. Time for god's revenge */
1024 if (reaction < 0)
1025 {
1026 int loss = 10000000;
1027 int angry = abs (reaction);
1028
1029 for (skop = op->inv; skop; skop = skop->below)
1030 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
1031 break;
1032
1033 if (skop)
1034 loss = 0.05f * skop->stats.exp;
1035
1036 change_exp (op, -random_roll (0, loss * angry - 1, op, PREFER_LOW), skop ? &skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
1037
1038 if (random_roll (0, angry, op, PREFER_LOW))
1039 {
1040 object *tmp = get_archetype (LOOSE_MANA);
1041
1042 cast_magic_storm (op, tmp, op->level + (angry * 3));
1043 }
1044
1045 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "%s becomes angry and punishes you!", &god->name);
1046 }
1047
1048 return reaction;
1049}
1050
1051/**
1052 * God checks item the player is using.
1053 * Return either -1 (bad), 0 (neutral) or
1054 * 1 (item is ok). If you are using the item of an enemy
1055 * god, it can be bad...-b.t.
1056 */
1057
1058int
1059god_examines_item (object *god, object *item)
1060{
1061 char buf[MAX_BUF];
1062
1063 if (!god || !item)
1064 return 0; 976 return;
1065 977
1066 if (!item->title) 978 /* If non consecrate altar, don't do anything */
1067 return 1; /* unclaimed item are ok */ 979 if (!altar->other_arch)
980 return;
1068 981
1069 sprintf (buf, "of %s", &god->name); 982 /* hmm. what happend depends on pl's current god, level, etc */
1070 if (!strcmp (item->title, buf)) 983 if (!pl_god)
1071 return 1; /* belongs to that God */ 984 { /*new convert */
985 become_follower (pl, altar->other_arch);
986 return;
987 }
988 else if (pl_god->name == altar->other_arch->object::name)
989 {
990 /* pray at your gods altar */
991 /* this leads to very low levels of wis and pray to result in no doubling! */
992 int bonus = (pl->stats.Wis + skill->level) / 10;
1072 993
1073 if (god->title) 994 /* we can get neg grace up faster */
1074 { /* check if we have any enemy blessed item */ 995 if (pl->stats.grace < 0)
1075 sprintf (buf, "of %s", &god->title); 996 pl->stats.grace += (bonus > -1 * (pl->stats.grace / 10) ? bonus : -1 * (pl->stats.grace / 10));
1076 if (!strcmp (item->title, buf)) 997
998 /* we can super-charge grace to 2x max */
999 if (pl->stats.grace < 2 * pl->stats.maxgrace)
1000 pl->stats.grace += bonus / 2;
1001 else
1002 pl->stats.grace = 2 * pl->stats.maxgrace;
1003
1004 /* Every once in a while, the god decides to checkup on their
1005 * follower, and may intervene to help them out.
1077 { 1006 */
1078 if (item->env) 1007 bonus = max (1, bonus + max (pl->stats.luck, -3)); /* -- DAMN -- */
1008
1009 if (((random_roll (0, 399, pl, PREFER_LOW)) - bonus) < 0)
1010 god_intervention (pl, pl_god, skill);
1011 }
1012 else
1013 { /* praying to another god! */
1014 uint64 loss = 0;
1015 int angry = 1;
1016
1017 /* I believe the logic for detecting opposing gods was completely
1018 * broken - I think it should work now. altar->other_arch
1019 * points to the god of this altar (which we have
1020 * already verified is non null). pl_god->other_arch
1021 * is the opposing god - we need to verify that exists before
1022 * using its values.
1023 */
1024 if (pl_god->other_arch && (altar->other_arch->archname == pl_god->other_arch->archname))
1025 {
1026 angry = 2;
1027 if (random_roll (0, skill->level + 2, pl, PREFER_LOW) - 5 > 0)
1079 { 1028 {
1080 char buf[MAX_BUF]; 1029 object *tmp;
1081 1030
1082 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1031 /* you really screwed up */
1083 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf); 1032 angry = 3;
1033 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foul Priest! %s punishes you!", &pl_god->name);
1034 tmp = get_archetype (LOOSE_MANA);
1035 cast_magic_storm (pl, tmp, pl_god->level + 20);
1084 } 1036 }
1085 return -1; 1037 else
1086 } 1038 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Foolish heretic! %s is livid!", &pl_god->name);
1087 }
1088
1089 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1090}
1091
1092/**
1093 * Returns priest's god's id.
1094 * Straight calls lookup_god_by_name
1095 */
1096
1097int
1098get_god (object *priest)
1099{
1100 int godnr = lookup_god_by_name (determine_god (priest));
1101
1102 return godnr;
1103}
1104
1105/**
1106 * Returns a string that is the name of the god that should be natively worshipped by a
1107 * creature of who has race *race
1108 * if we can't find a god that is appropriate, we return NULL
1109 */
1110const char *
1111get_god_for_race (const char *race)
1112{
1113 godlink *gl = first_god;
1114 const char *godname = NULL;
1115
1116 if (race == NULL)
1117 return NULL;
1118 while (gl)
1119 {
1120 if (!strcasecmp (gl->arch->race, race))
1121 { 1039 }
1122 godname = gl->name; 1040 else
1123 break; 1041 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, pl, "Heretic! %s is angered!", &pl_god->name);
1042
1043 /* whether we will be successfull in defecting or not -
1044 * we lose experience from the clerical experience obj
1045 */
1046
1047 loss = angry * (skill->stats.exp / 10);
1048 if (loss)
1049 change_exp (pl, -random_roll64 (0, loss, pl, PREFER_LOW), skill ? &skill->skill : "none", SK_SUBTRACT_SKILL_EXP);
1050
1051 /* May switch Gods, but its random chance based on our current level
1052 * note it gets harder to swap gods the higher we get
1053 */
1054 if ((angry == 1) && !(random_roll (0, skill->level, pl, PREFER_LOW)))
1055 become_follower (pl, altar->other_arch);
1056 else
1124 } 1057 {
1125 gl = gl->next; 1058 /* toss this player off the altar. He can try again. */
1059 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, pl, "A divine force pushes you off the altar.");
1060 pl->contr->fire_on = 0;
1061 pl->speed_left = 1.f;
1062 move_player (pl, absdir (pl->facing + 4)); /* back him off the way he came. */
1063 }
1126 } 1064 }
1127 return godname;
1128} 1065}
1129 1066
1130/** 1067/**
1131 * Changes the attributes of cone, smite, and ball spells as needed by the code. 1068 * Changes the attributes of cone, smite, and ball spells as needed by the code.
1132 * Returns false if there was no race to assign to the slaying field of the spell, but 1069 * 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