Debian Codegraph @

server/gods.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file
16 * All this functions handle gods: give presents, punish, and so on.
17 *
18 * Oct 3, 1995 - Code laid down for initial gods, priest alignment, and
19 * monster race initialization. b.t.
20 *
21 * Sept 1996 - moved code over to object -oriented gods -b.t.
22 */
23
24 #include "global.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "living.h"
30 #include "object.h"
31 #include "sounds.h"
32 #include "spells.h"
33 #include "sproto.h"
34
35 static int worship_forbids_use(object *op, object *exp_obj, uint32_t flag, const char *string);
36 static void stop_using_item(object *op, int type, int number);
37 static void update_priest_flag(const object *god, object *exp_ob, uint32_t flag);
38 static void god_intervention(object *op, const object *god, object *skill, object *altar);
39 static int god_examines_priest(object *op, const object *god);
40 static int god_examines_item(const object *god, object *item);
41 static const char *get_god_for_race(const char *race);
42 static void remove_special_prayers(object *op, const object *god);
43
44 /**
45 * Returns the id of specified god.
46 *
47 * @param name
48 * god to search for.
49 * @return
50 * identifier of god, -1 if not found.
51 * @todo
52 * couldn't == be used for comparison, if name is a shared string?
53 */
54 static int lookup_god_by_name(const char *name) {
55 int godnr = -1;
56 size_t nmlen = strlen(name);
57
58 if (name && strcmp(name, "none")) {
59 godlink *gl;
60 for (gl = first_god; gl; gl = gl->next)
61 if (!strncmp(name, gl->name, MIN(strlen(gl->name), nmlen)))
62 break;
63 if (gl)
64 godnr = gl->id;
65 }
66 return godnr;
67 }
68
69 /**
70 * Returns pointer to specified god's object through pntr_to_god_obj().
71 *
72 * @note
73 * returned object shouldn't be modified.
74 *
75 * @param name
76 * god's name.
77 * @return
78 * pointer to god's object, NULL if doesn't match any god.
79 */
80 const object *find_god(const char *name) {
81 godlink *gl;
82
83 if (!name)
84 return NULL;
85
86 for (gl = first_god; gl; gl = gl->next) {
87 if (!strcmp(name, gl->name))
88 return pntr_to_god_obj(gl);
89 }
90
91 return NULL;
92 }
93
94 /**
95 * Determines if op worships a god.
96 * Returns the godname if they do or "none" if they have no god.
97 * In the case of an NPC, if they have no god, we try and guess
98 * who they should worship based on their race. If that fails we
99 * give them a random one.
100 *
101 * @param op
102 * object to get name of.
103 * @return
104 * god name, "none" if nothing suitable.
105 */
106 const char *determine_god(object *op) {
107 int godnr = -1;
108 const char *godname;
109
110 /* spells */
111 if ((op->type == SPELL || op->type == SPELL_EFFECT)
112 && op->title) {
113 if (lookup_god_by_name(op->title) >= 0)
114 return op->title;
115 }
116
117 if (op->type != PLAYER && QUERY_FLAG(op, FLAG_ALIVE)) {
118 /* find a god based on race */
119 if (!op->title) {
120 if (op->race != NULL) {
121 godname = get_god_for_race(op->race);
122 if (godname != NULL) {
123 op->title = add_string(godname);
124 }
125 }
126 }
127
128 /* find a random god */
129 if (!op->title) {
130 godlink *gl = first_god;
131
132 godnr = rndm(1, gl->id);
133 while (gl) {
134 if (gl->id == godnr)
135 {
136 // This used to be after the loop, but if we do not find a god,
137 // it would have made a null pointer dereference. Moved here
138 // for better clarity and (hopefully) fewer bugs.
139 // SilverNexus 2018-01-17
140 op->title = add_string(gl->name);
141
142 break;
143 }
144 gl = gl->next;
145 }
146 }
147
148 return op->title;
149 }
150
151 /* The god the player worships is in the praying skill (native skill
152 * not skill tool). Since a player can only have one instance of
153 * that skill, once we find it, we can return, either with the
154 * title or "none".
155 */
156 if (op->type == PLAYER) {
157 object *tmp;
158
159 tmp = object_find_by_type_subtype(op, SKILL, SK_PRAYING);
160 if (tmp != NULL) {
161 return tmp->title != NULL ? tmp->title : "none";
162 }
163 }
164 return ("none");
165 }
166
167 /**
168 * Compares 2 strings.
169 * @param s1
170 * @param s2
171 * strings to compare.
172 * @return
173 * 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0.
174 */
175 static int same_string(const char *s1, const char *s2) {
176 if (s1 == NULL)
177 return s2 == NULL;
178 else
179 return s2 != NULL && strcmp(s1, s2) == 0;
180 }
181
182 /**
183 * Removes from a player's inventory all items bestowed by
184 * a particular god. Intended mainly for use in punishing
185 * characters for switching gods.
186 *
187 * @param pl
188 * the player object
189 *
190 * @param op
191 * the object to be searched for items
192 *
193 * @param god
194 * the god whose objects to remove
195 *
196 */
197 static void follower_remove_given_items(object *pl, object *op, const object *god) {
198 const char *given_by;
199
200 /* search the inventory */
201 FOR_INV_PREPARE(op, tmp) {
202 given_by = object_get_value(tmp, "divine_giver_name");
203 if (given_by == god->name) {
204 char name[HUGE_BUF];
205
206 query_short_name(tmp, name, HUGE_BUF);
207 /* Send the client a message. */
208 if (tmp->nrof > 1)
209 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE,
210 "The %s crumble to dust!",
211 name);
212 else
213 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE,
214 "The %s crumbles to dust!",
215 name);
216
217 object_remove(tmp); /* remove obj from players inv. */
218 object_free_drop_inventory(tmp);
219 } else if (tmp->inv)
220 follower_remove_given_items(pl, tmp, god);
221 } FOR_INV_FINISH();
222 }
223
224 /**
225 * Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively).
226 * @param op
227 * object to check.
228 * @param item
229 * object to check for.
230 * @return
231 * 1 if found, else 0.
232 */
233 static int follower_has_similar_item(object *op, object *item) {
234 FOR_INV_PREPARE(op, tmp) {
235 if (tmp->type == item->type
236 && same_string(tmp->name, item->name)
237 && same_string(tmp->title, item->title)
238 && tmp->msg == item->msg
239 && same_string(tmp->slaying, item->slaying))
240 return 1;
241 if (tmp->inv && follower_has_similar_item(tmp, item))
242 return 1;
243 } FOR_INV_FINISH();
244 return 0;
245 }
246
247 /**
248 * God gives an item to the player. Inform player of the present.
249 *
250 * @param op
251 * who is getting the treasure.
252 * @param god
253 * god giving the present.
254 * @param tr
255 * object to give. Should be a single object on list.
256 * @return
257 * 0 if nothing was given, 1 else.
258 */
259 static int god_gives_present(object *op, const object *god, treasure *tr) {
260 object *tmp;
261 char name[HUGE_BUF];
262
263 if (follower_has_similar_item(op, &tr->item->clone))
264 return 0;
265
266 tmp = arch_to_object(tr->item);
267
268 /*
269 * Give inventory if needed, for instance Lythander's pipe.
270 * Use high level and magic so something IS put in inventory.
271 */
272 fix_generated_item(tmp, NULL, 120, 120, GT_ONLY_GOOD);
273
274 /* And just in case nothing was put and something is needed, bail out. */
275 if ((tmp->type == ROD || tmp->type == WAND) && (tmp->inv == NULL)) {
276 object_free(tmp, 0);
277 return 0;
278 }
279
280 query_short_name(tmp, name, HUGE_BUF);
281 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_ADD,
282 "%s lets %s appear in your hands.",
283 god->name, name);
284 /**
285 * Mark what god gave it, so it can be taken vengefully later!
286 */
287 object_set_value(tmp, "divine_giver_name", god->name, TRUE);
288 object_insert_in_ob(tmp, op);
289 return 1;
290 }
291
292 /**
293 * Try to leave a cult. Deducts experience from 'skill' proportional to 'angry'.
294 * Returns true if successful (only when 'angry' is 1) or false otherwise.
295 */
296 static bool try_leave_cult(object* pl, object* skill, int angry) {
297 const uint64_t loss = angry * (skill->stats.exp / 10);
298 if (loss)
299 change_exp(pl, -random_roll64(0, loss, pl, PREFER_LOW),
300 skill ? skill->skill : "none", SK_SUBTRACT_SKILL_EXP);
301
302 /* random chance based on our current level
303 * note it gets harder the higher we get
304 */
305 if ((angry == 1) && !(random_roll(0, skill->level, pl, PREFER_LOW))) {
306 return true;
307 } else {
308 return false;
309 }
310 }
311
312 /**
313 * Player prays at altar.
314 * Checks for god changing, divine intervention, and so on.
315 *
316 * @param pl
317 * player praying.
318 * @param altar
319 * altar player's praying on. Doesn't need to be consecrated.
320 * @param skill
321 * praying skill.
322 */
323 void pray_at_altar(object *pl, object *altar, object *skill) {
324 const object *pl_god = find_god(determine_god(pl));
325
326 /* Lauwenmark: Handle for plugin altar-praying (apply) event */
327 if (execute_event(altar, EVENT_APPLY, pl, NULL, NULL, SCRIPT_FIX_ALL) != 0)
328 return;
329
330 /* If non consecrate altar, don't do anything */
331 if (!altar->other_arch)
332 return;
333
334 /* hmm. what happend depends on pl's current god, level, etc */
335 if (!pl_god) { /*new convert */
336 become_follower(pl, &altar->other_arch->clone);
337 return;
338 }
339
340 if (!strcmp(pl_god->name, altar->other_arch->clone.name)) {
341 /* pray at your gods altar */
342 int bonus = (pl->stats.Wis+skill->level)/10;
343
344 /* we can get neg grace up faster */
345 if (pl->stats.grace < 0)
346 pl->stats.grace += (bonus > -1*(pl->stats.grace/10) ? bonus : -1*(pl->stats.grace/10));
347 /* we can super-charge grace to 2x max */
348 if (pl->stats.grace < (2*pl->stats.maxgrace)) {
349 pl->stats.grace += bonus/2;
350 }
351 if (pl->stats.grace > (2*pl->stats.maxgrace)) {
352 pl->stats.grace = (2*pl->stats.maxgrace);
353 }
354
355 /* Every once in a while, the god decides to checkup on their
356 * follower, and may intervene to help them out.
357 */
358 bonus = MAX(1, bonus+MAX(pl->stats.luck, -3)); /* -- DAMN -- */
359
360 if (((random_roll(0, 399, pl, PREFER_LOW))-bonus) < 0)
361 god_intervention(pl, pl_god, skill, altar);
362 } else { /* praying to another god! */
363 int angry = 1;
364
365 /* I believe the logic for detecting opposing gods was completely
366 * broken - I think it should work now. altar->other_arch
367 * points to the god of this altar (which we have
368 * already verified is non null). pl_god->other_arch
369 * is the opposing god - we need to verify that exists before
370 * using its values.
371 */
372 if (pl_god->other_arch
373 && (altar->other_arch->name == pl_god->other_arch->name)) {
374 angry = 2;
375 if (random_roll(0, skill->level+2, pl, PREFER_LOW)-5 > 0) {
376 object *tmp;
377
378 /* you really screwed up */
379 angry = 3;
380 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, pl, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
381 "Foul Priest! %s punishes you!",
382 pl_god->name);
383 tmp = create_archetype(LOOSE_MANA);
384 cast_magic_storm(pl, tmp, pl_god->level+20);
385 } else
386 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, pl, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
387 "Foolish heretic! %s is livid!",
388 pl_god->name);
389 } else
390 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, pl, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
391 "Heretic! %s is angered!",
392 pl_god->name);
393
394 if (try_leave_cult(pl, skill, angry)) {
395 become_follower(pl, &altar->other_arch->clone);
396 } else {
397 /* toss this player off the altar. He can try again. */
398 draw_ext_info(NDI_UNIQUE|NDI_NAVY, 0, pl, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
399 "A divine force pushes you off the altar.");
400
401 move_player(pl, absdir(pl->facing+4)); /* back him off the way he came. */
402 }
403 }
404 }
405
406 /**
407 * Removes special prayers given by a god.
408 * After this function, op shouldn't know any prayer granted by god.
409 * Prayers will be given when player prays on god's altar, so not handled now.
410 *
411 * @param op
412 * player to remove prayers from.
413 * @param god
414 * god we're removing the prayers.
415 */
416 static void remove_special_prayers(object *op, const object *god) {
417 treasure *tr;
418 int remove = 0;
419
420 if (god->randomitems == NULL) {
421 LOG(llevError, "BUG: remove_special_prayers(): god %s without randomitems\n", god->name);
422 return;
423 }
424
425
426 /* Outer loop iterates over all special prayer marks */
427 FOR_INV_PREPARE(op, tmp) {
428 /* we mark special prayers with the STARTEQUIP flag, so if it isn't
429 * in that category, not something we need to worry about.
430 */
431 if (tmp->type != SPELL || !QUERY_FLAG(tmp, FLAG_STARTEQUIP))
432 continue;
433
434 /* Inner loop tries to find the special prayer in the god's treasure
435 * list. We default that the spell should not be removed.
436 */
437 remove = 0;
438 for (tr = god->randomitems->items; tr; tr = tr->next) {
439 if (tr->item == NULL)
440 continue;
441
442 /* Basically, see if the matching spell is granted by this god. */
443
444 if (tr->item->clone.type == SPELL && tr->item->clone.name == tmp->name) {
445 remove = 1;
446 break;
447 }
448 }
449 if (remove) {
450 /* just do the work of removing the spell ourselves - we already
451 * know that the player knows the spell
452 */
453 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op,
454 MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
455 "You lose knowledge of %s.",
456 tmp->name);
457 player_unready_range_ob(op->contr, tmp);
458 object_remove(tmp);
459 object_free_drop_inventory(tmp);
460 }
461 } FOR_INV_FINISH();
462 }
463
464 /**
465 * This function is called whenever a player has
466 * switched to a new god. It handles basically all the stat changes
467 * that happen to the player, including the removal of godgiven
468 * items (from the former cult).
469 * Handles race restrictions on god, and will punish player if needed.
470 *
471 * @param op
472 * player switching cults.
473 * @param new_god
474 * new god to worship.
475 * @return
476 * 1 if successfully converted, 0 if the god doesn't like the race, or something else.
477 * @todo split the check to make this function only actually become follower
478 */
479 int become_follower(object *op, const object *new_god) {
480 /* take away any special god-characteristic items. */
481 FOR_INV_PREPARE(op, item) {
482 /* remove all invisible startequip items which are
483 * not skill, exp or force
484 */
485 if (QUERY_FLAG(item, FLAG_STARTEQUIP)
486 && item->invisible
487 && (item->type != SKILL)
488 && (item->type != FORCE)
489 && (item->type != SPELL)) {
490 player_unready_range_ob(op->contr, item);
491 object_remove(item);
492 object_free_drop_inventory(item);
493 }
494 } FOR_INV_FINISH();
495
496 /* remove any items given by the old god */
497 const object *old_god = find_god(determine_god(op));
498 if (old_god) {
499 /* Changed to use the new "divine_giver_name" key_value
500 * so it can reliably delete enchanted items. Now it loops
501 * through the player's inventory, instead of the god's
502 * treasure list.
503 */
504 follower_remove_given_items(op, op, old_god);
505 remove_special_prayers(op, old_god);
506 }
507
508 if (!op || !new_god)
509 return 0;
510
511 if (op->race && new_god->slaying && strstr(op->race, new_god->slaying)) {
512 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
513 "Fool! %s detests your kind!",
514 new_god->name);
515 if (random_roll(0, op->level-1, op, PREFER_LOW)-5 > 0) {
516 object *tmp = create_archetype(LOOSE_MANA);
517 cast_magic_storm(op, tmp, new_god->level+10);
518 }
519 return 0;
520 }
521
522 /* give the player any special god-characteristic-items. */
523 for (treasure *tr = new_god->randomitems->items; tr != NULL; tr = tr->next) {
524 if (tr->item
525 && tr->item->clone.invisible
526 && tr->item->clone.type != SPELLBOOK
527 && tr->item->clone.type != BOOK
528 && tr->item->clone.type != SPELL)
529 god_gives_present(op, new_god, tr);
530 }
531
532 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
533 "You become a follower of %s!",
534 new_god->name);
535
536 object *skop = object_find_by_type_subtype(op, SKILL, SK_PRAYING);
537 /* Player has no skill - give them the skill */
538 if (!skop) {
539 /* The archetype should always be defined - if we crash here because it doesn't,
540 * things are really messed up anyways.
541 */
542 skop = give_skill_by_name(op, get_archetype_by_type_subtype(SKILL, SK_PRAYING)->clone.skill);
543 link_player_skills(op);
544 }
545
546 int sk_applied = QUERY_FLAG(skop, FLAG_APPLIED); /* save skill status */
547
548 int undeadified = 0; /* Turns to true if changing god can changes the undead
549 * status of the player.*/
550 /* Clear the "undead" status. We also need to force a call to change_abil,
551 * so I set undeadified for that.
552 * - gros, 21th July 2006.
553 */
554 if ((old_god) && (QUERY_FLAG(old_god, FLAG_UNDEAD))) {
555 CLEAR_FLAG(skop, FLAG_UNDEAD);
556 undeadified = 1;
557 }
558
559 if (skop->title) { /* get rid of old god */
560 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
561 "%s's blessing is withdrawn from you.",
562 skop->title);
563
564 /* The point of this is to really show what abilities the player just lost */
565 if (sk_applied || undeadified) {
566 CLEAR_FLAG(skop, FLAG_APPLIED);
567 (void)change_abil(op, skop);
568 }
569 free_string(skop->title);
570 }
571
572 /* now change to the new gods attributes to exp_obj */
573 skop->title = add_string(new_god->name);
574 skop->path_attuned = new_god->path_attuned;
575 skop->path_repelled = new_god->path_repelled;
576 skop->path_denied = new_god->path_denied;
577 /* copy god's resistances */
578 memcpy(skop->resist, new_god->resist, sizeof(new_god->resist));
579
580 /* make sure that certain immunities do NOT get passed
581 * to the follower!
582 */
583 for (int i = 0; i < NROFATTACKS; i++)
584 if (skop->resist[i] > 30
585 && (i == ATNR_FIRE || i == ATNR_COLD || i == ATNR_ELECTRICITY || i == ATNR_POISON))
586 skop->resist[i] = 30;
587
588 skop->stats.hp = (int16_t)new_god->last_heal;
589 skop->stats.sp = (int16_t)new_god->last_sp;
590 skop->stats.grace = (int16_t)new_god->last_grace;
591 skop->stats.food = (int16_t)new_god->last_eat;
592 skop->stats.luck = (int8_t)new_god->stats.luck;
593 /* gods may pass on certain flag properties */
594 update_priest_flag(new_god, skop, FLAG_SEE_IN_DARK);
595 update_priest_flag(new_god, skop, FLAG_REFL_SPELL);
596 update_priest_flag(new_god, skop, FLAG_REFL_MISSILE);
597 update_priest_flag(new_god, skop, FLAG_STEALTH);
598 update_priest_flag(new_god, skop, FLAG_MAKE_INVIS);
599 update_priest_flag(new_god, skop, FLAG_UNDEAD);
600 update_priest_flag(new_god, skop, FLAG_BLIND);
601 update_priest_flag(new_god, skop, FLAG_XRAYS); /* better have this if blind! */
602 update_priest_flag(new_god, skop, FLAG_USE_WEAPON);
603 update_priest_flag(new_god, skop, FLAG_USE_ARMOUR);
604 update_priest_flag(new_god, skop, FLAG_USE_SHIELD);
605
606 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
607 "You are bathed in %s's aura.",
608 new_god->name);
609
610 /* Weapon/armour use are special...handle flag toggles here as this can
611 * only happen when gods are worshipped and if the new priest could
612 * have used armour/weapons in the first place.
613 *
614 * This also can happen for monks which cannot use weapons. In this case
615 * do not allow to use weapons even if the god otherwise would allow it.
616 */
617 if (!object_present_in_ob_by_name(FORCE, "no weapon force", op)) {
618 if (worship_forbids_use(op, skop, FLAG_USE_WEAPON, "weapons"))
619 stop_using_item(op, WEAPON, 2);
620 }
621 update_priest_flag(new_god, skop, FLAG_USE_ARMOUR);
622
623 if (worship_forbids_use(op, skop, FLAG_USE_ARMOUR, "armour")) {
624 stop_using_item(op, ARMOUR, 1);
625 stop_using_item(op, HELMET, 1);
626 stop_using_item(op, BOOTS, 1);
627 stop_using_item(op, GLOVES, 1);
628 }
629
630 if (worship_forbids_use(op, skop, FLAG_USE_SHIELD, "shield"))
631 stop_using_item(op, SHIELD, 1);
632
633 SET_FLAG(skop, FLAG_APPLIED);
634 (void)change_abil(op, skop);
635
636 /* return to previous skill status */
637 if (!sk_applied)
638 CLEAR_FLAG(skop, FLAG_APPLIED);
639
640 return 1;
641 }
642
643 /**
644 * Forbids or let player use something item type.
645 * @param op
646 * player.
647 * @param exp_obj
648 * praying skill.
649 * @param flag
650 * FLAG_xxx to check against.
651 * @param string
652 * what flag corresponds to ("weapons", "shield", ...).
653 * @return
654 * 1 if player was changed, 0 if no change.
655 */
656 static int worship_forbids_use(object *op, object *exp_obj, uint32_t flag, const char *string) {
657 if (QUERY_FLAG(&op->arch->clone, flag)) {
658 if (QUERY_FLAG(op, flag) != QUERY_FLAG(exp_obj, flag)) {
659 update_priest_flag(exp_obj, op, flag);
660 if (QUERY_FLAG(op, flag))
661 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
662 "You may use %s again.",
663 string);
664 else {
665 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
666 "You are forbidden to use %s.",
667 string);
668 return 1;
669 }
670 }
671 }
672 return 0;
673 }
674
675 /**
676 * Unapplies up to number worth of items of type type, ignoring curse status.
677 * This is used when the player gets forbidden to use eg weapons.
678 *
679 * @param op
680 * player we're considering.
681 * @param type
682 * item type to remove.
683 * @param number
684 * maximum number of items to unapply. Must be positive.
685 */
686 static void stop_using_item(object *op, int type, int number) {
687 FOR_INV_PREPARE(op, tmp)
688 if (tmp->type == type && QUERY_FLAG(tmp, FLAG_APPLIED)) {
689 apply_special(op, tmp, AP_UNAPPLY|AP_IGNORE_CURSE);
690 number--;
691 if (number <= 0)
692 break;
693 }
694 FOR_INV_FINISH();
695 }
696
697 /**
698 * If the god does/doesnt have this flag, we
699 * give/remove it from the experience object if it doesnt/does
700 * already exist.
701 *
702 * @param god
703 * god object.
704 * @param exp_ob
705 * player's praying skill object.
706 * @param flag
707 * flag to consider.
708 */
709 static void update_priest_flag(const object *god, object *exp_ob, uint32_t flag) {
710 if (QUERY_FLAG(god, flag) && !QUERY_FLAG(exp_ob, flag))
711 SET_FLAG(exp_ob, flag);
712 else if (QUERY_FLAG(exp_ob, flag) && !QUERY_FLAG(god, flag)) {
713 /* When this is called with the exp_ob set to the player,
714 * this check is broken, because most all players arch
715 * allow use of weapons. I'm not actually sure why this
716 * check is here - I guess if you had a case where the
717 * value in the archetype (wisdom) should over ride the restrictions
718 * the god places on it, this may make sense. But I don't think
719 * there is any case like that.
720 */
721
722 /* if (!(QUERY_FLAG(&(exp_ob->arch->clone), flag)))*/
723 CLEAR_FLAG(exp_ob, flag);
724 }
725 }
726
727
728 /**
729 * Determines the archetype for holy servant and god avatar.
730 *
731 * Possible monsters are stored as invisible books in god's inventory,
732 * one having the right name is selected randomly.
733 *
734 * @param god
735 * god for which we want something.
736 * @param type
737 * what the summon type is. Must be a shared string.
738 * @return
739 * random archetype matching the type, NULL if none found.
740 */
741 archetype *determine_holy_arch(const object *god, const char *type) {
742 treasure *tr;
743 int count;
744 object *item;
745
746 if (!god || !god->randomitems) {
747 LOG(llevError, "BUG: determine_holy_arch(): no god or god without randomitems\n");
748 return NULL;
749 }
750
751 count = 0;
752 for (tr = god->randomitems->items; tr != NULL; tr = tr->next) {
753 if (!tr->item)
754 continue;
755 item = &tr->item->clone;
756 if (item->type == BOOK && item->invisible && item->name == type)
757 count++;
758 }
759 if (count == 0) {
760 return NULL;
761 }
762
763 count = rndm(1, count);
764
765 for (tr = god->randomitems->items; tr != NULL; tr = tr->next) {
766 if (!tr->item)
767 continue;
768 item = &tr->item->clone;
769 if (item->type == BOOK && item->invisible && item->name == type) {
770 count--;
771 if (count == 0)
772 return item->other_arch;
773 }
774 }
775
776 return NULL;
777 }
778
779 /**
780 * God helps player by removing curse and/or damnation.
781 *
782 * @param op
783 * player to help.
784 * @param remove_damnation
785 * if set, also removes damned items.
786 * @return
787 * 1 if at least one item was uncursed, 0 else.
788 */
789 static int god_removes_curse(object *op, int remove_damnation) {
790 int success = 0;
791
792 FOR_INV_PREPARE(op, tmp) {
793 if (tmp->invisible)
794 continue;
795 if (QUERY_FLAG(tmp, FLAG_DAMNED) && !remove_damnation)
796 continue;
797 if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) {
798 success = 1;
799 CLEAR_FLAG(tmp, FLAG_DAMNED);
800 CLEAR_FLAG(tmp, FLAG_CURSED);
801 CLEAR_FLAG(tmp, FLAG_KNOWN_CURSED);
802 if (op->type == PLAYER)
803 esrv_update_item(UPD_FLAGS, op, tmp);
804 }
805 } FOR_INV_FINISH();
806
807 if (success)
808 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
809 "You feel like someone is helping you.");
810 return success;
811 }
812
813 /**
814 * Converts a level and difficulty to a magic/enchantment value for eg weapons.
815 * @param level
816 * level
817 * @param difficulty
818 * difficulty. Must be 1 or more.
819 * @return
820 * number of enchantments for level and difficulty.
821 */
822 static int follower_level_to_enchantments(int level, int difficulty) {
823 if (difficulty < 1) {
824 LOG(llevError, "follower_level_to_enchantments(): difficulty %d is invalid\n", difficulty);
825 return 0;
826 }
827
828 if (level <= 20)
829 return level/difficulty;
830 if (level <= 40)
831 return (20+(level-20)/2)/difficulty;
832 return (30+(level-40)/4)/difficulty;
833 }
834
835 /**
836 * Utility function for improving the magic on a weapon.
837 * Affected weapon is the applied one (weapon or bow). This utility function
838 * improves the weapon magic on a weapon being enchanted by a god. This was
839 * necessary because the same block of the code was being called from two
840 * places in the god_enchants_weapon(...) function.
841 *
842 * @param op
843 * player
844 * @param tr
845 * treasure list item for enchanting weapon, contains the enchantment level.
846 * @param weapon
847 * weapon being modified
848 * @param skill
849 * praying skill of op.
850 * @return
851 * 0 if weapon wasn't changed, 1 if changed.
852 */
853 static int improve_weapon_magic(object *op, object *tr, object *weapon, object *skill) {
854 int tmp = follower_level_to_enchantments(skill->level, tr->level);
855
856 if (weapon->magic < tmp) {
857 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE,
858 "A phosphorescent glow envelops your weapon!");
859 weapon->magic++;
860 if (op->type == PLAYER)
861 esrv_update_item(UPD_NAME, op, weapon);
862 weapon->item_power++;
863 return 1;
864 }
865
866 return 0;
867 }
868
869 /**
870 * God wants to enchant weapon.
871 * Affected weapon is the applied one (weapon or bow). It's checked to make sure
872 * it isn't a weapon for another god. If all is all right, update weapon with
873 * attacktype, slaying and such.
874 *
875 * @param op
876 * player
877 * @param god
878 * god enchanting weapon.
879 * @param tr
880 * treasure list item for enchanting weapon, contains the enchantment level.
881 * @param skill
882 * praying skill of op.
883 * @return
884 * 0 if weapon wasn't changed, 1 if changed.
885 */
886 static int god_enchants_weapon(object *op, const object *god, object *tr, object *skill) {
887 char buf[MAX_BUF];
888 object *weapon;
889 uint32_t attacktype;
890
891 weapon = object_find_by_type_applied(op, WEAPON);
892 if (weapon == NULL)
893 weapon = object_find_by_type_applied(op, BOW);
894 if (weapon == NULL || god_examines_item(god, weapon) <= 0)
895 return 0;
896
897 if (weapon->item_power >= MAX_WEAPON_ITEM_POWER) {
898 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO,
899 "%s considers your %s is not worthy to be enchanted any more.",
900 god->name,
901 weapon->name);
902 return 0;
903 }
904
905 /* If personalized_blessings is activated, then the god's name is
906 * associated with the weapon, as well as the owner (the one who blesses it),
907 * and a "weapon willpower", which is equivalent to the owner's experience
908 * in praying when the weapon is blessed.
909 * Those values are used later, when another player attempts to wield the
910 * weapon - nasty things may happen to those who do not deserve to use it ! :)
911 */
912 if (settings.personalized_blessings) {
913 const char *divine_owner = object_get_value(weapon, "divine_blessing_name");
914 const char *owner = object_get_value(weapon, "item_owner");
915 object *skillop = NULL;
916
917 if (divine_owner != NULL && strcmp(divine_owner, god->name) != 0) {
918 /* Huho... Another god already blessed this one ! */
919 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO,
920 "Your %s already belongs to %s !",
921 weapon->name, divine_owner);
922 return 0;
923 }
924
925 if ((owner != NULL) && (strcmp(owner, op->name) != 0)) {
926 /* Maybe the weapon itself will not agree ? */
927 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO,
928 "The %s is not yours, and is magically protected against such changes !",
929 weapon->name);
930 return 0;
931 }
932 skillop = find_skill_by_number(op, SK_PRAYING);
933 if (skillop == NULL) {
934 LOG(llevError, "god_enchants_weapon: no praying skill object found ?!\n");
935 snprintf(buf, sizeof(buf), "%d", 1);
936 } else
937 snprintf(buf, sizeof(buf), "%"FMT64, skillop->stats.exp);
938 object_set_value(weapon, "divine_blessing_name", god->name, TRUE);
939 object_set_value(weapon, "item_owner", op->name, TRUE);
940 object_set_value(weapon, "item_willpower", buf, TRUE);
941 }
942
943 /* First give it a title, so other gods won't touch it */
944 if (!weapon->title) {
945 snprintf(buf, sizeof(buf), "of %s", god->name);
946 weapon->title = add_string(buf);
947 if (op->type == PLAYER)
948 esrv_update_item(UPD_NAME, op, weapon);
949 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE,
950 "Your weapon quivers as if struck!");
951 }
952
953 /* Allow the weapon to slay enemies */
954 if (!weapon->slaying && god->slaying) {
955 weapon->slaying = add_string(god->slaying);
956 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE,
957 "Your %s now hungers to slay enemies of your god!",
958 weapon->name);
959 weapon->item_power++;
960 return 1;
961 }
962
963 /* Add the gods attacktype */
964 attacktype = (weapon->attacktype == 0) ? AT_PHYSICAL : weapon->attacktype;
965 if ((attacktype&god->attacktype) != god->attacktype) {
966 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE,
967 "Your weapon suddenly glows!");
968 weapon->attacktype = attacktype|god->attacktype;
969 weapon->item_power++;
970 return 1;
971 }
972
973 /* Higher magic value */
974 return improve_weapon_magic(op, tr, weapon, skill);
975 }
976
977 /**
978 * Every once in a while the god will intervene to help the worshiper.
979 * Later, this fctn can be used to supply quests, etc for the
980 * priest. -b.t.
981 * called from pray_at_altar() currently.
982 *
983 * @param op
984 * player praying.
985 * @param god
986 * god player is praying to.
987 * @param skill
988 * player's praying skill.
989 * @param altar
990 * where the player is praying.
991 */
992 static void god_intervention(object *op, const object *god, object *skill, object *altar) {
993 treasure *tr;
994
995 if (!god || !god->randomitems) {
996 LOG(llevError, "BUG: god_intervention(): no god or god without randomitems\n");
997 return;
998 }
999
1000 /* lets do some checks of whether we are kosher with our god */
1001 if (god_examines_priest(op, god) < 0)
1002 return;
1003
1004 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1005 "You feel a holy presence!");
1006
1007 if (altar->anim_suffix != NULL)
1008 apply_anim_suffix(altar, altar->anim_suffix);
1009
1010 for (tr = god->randomitems->items; tr != NULL; tr = tr->next) {
1011 object *item;
1012
1013 if (tr->chance <= random_roll(0, 99, op, PREFER_HIGH))
1014 continue;
1015
1016 /* Treasurelist - generate some treasure for the follower */
1017 if (tr->name) {
1018 treasurelist *tl = find_treasurelist(tr->name);
1019 if (tl == NULL)
1020 continue;
1021
1022 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_ADD,
1023 "Something appears before your eyes. You catch it before it falls to the ground.");
1024
1025 create_treasure(tl, op, GT_STARTEQUIP|GT_ONLY_GOOD|GT_UPDATE_INV, skill->level, 0);
1026 return;
1027 }
1028
1029 if (!tr->item) {
1030 LOG(llevError, "BUG: empty entry in %s's treasure list\n", god->name);
1031 continue;
1032 }
1033 item = &tr->item->clone;
1034
1035 /* Grace limit */
1036 if (item->type == BOOK && item->invisible
1037 && strcmp(item->name, "grace limit") == 0) {
1038 if (op->stats.grace < item->stats.grace
1039 || op->stats.grace < op->stats.maxgrace) {
1040 object *tmp;
1041
1042 /* Follower lacks the required grace for the following
1043 * treasure list items. */
1044
1045 tmp = create_archetype(HOLY_POSSESSION);
1046 cast_change_ability(op, op, tmp, 0, 1);
1047 object_free_drop_inventory(tmp);
1048 return;
1049 }
1050 continue;
1051 }
1052
1053 /* Restore grace */
1054 if (item->type == BOOK && item->invisible
1055 && strcmp(item->name, "restore grace") == 0) {
1056 if (op->stats.grace >= 0)
1057 continue;
1058 op->stats.grace = random_roll(0, 9, op, PREFER_HIGH);
1059 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1060 "You are returned to a state of grace.");
1061 return;
1062 }
1063
1064 /* Heal damage */
1065 if (item->type == BOOK && item->invisible
1066 && strcmp(item->name, "restore hitpoints") == 0) {
1067 if (op->stats.hp >= op->stats.maxhp)
1068 continue;
1069 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1070 "A white light surrounds and heals you!");
1071 op->stats.hp = op->stats.maxhp;
1072 return;
1073 }
1074
1075 /* Restore spellpoints */
1076 if (item->type == BOOK
1077 && item->invisible
1078 && strcmp(item->name, "restore spellpoints") == 0) {
1079 int max = op->stats.maxsp*(item->stats.maxsp/100.0);
1080 /* Restore to 50 .. 100%, if sp < 50% */
1081 int new_sp = random_roll(1000, 1999, op, PREFER_HIGH)/2000.0*max;
1082 if (op->stats.sp >= max/2)
1083 continue;
1084 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1085 "A blue lightning strikes your head but doesn't hurt you!");
1086 op->stats.sp = new_sp;
1087 }
1088
1089 /* Various heal spells */
1090 if (item->type == BOOK && item->invisible
1091 && strcmp(item->name, "heal spell") == 0) {
1092 object *tmp;
1093 int success;
1094
1095 tmp = create_archetype_by_object_name(item->slaying);
1096
1097 success = cast_heal(op, op, tmp, 0);
1098 object_free_drop_inventory(tmp);
1099 if (success)
1100 return;
1101
1102 continue;
1103 }
1104
1105 /* Remove curse */
1106 if (item->type == BOOK && item->invisible
1107 && strcmp(item->name, "remove curse") == 0) {
1108 if (god_removes_curse(op, 0))
1109 return;
1110
1111 continue;
1112 }
1113
1114 /* Remove damnation */
1115 if (item->type == BOOK && item->invisible
1116 && strcmp(item->name, "remove damnation") == 0) {
1117 if (god_removes_curse(op, 1))
1118 return;
1119
1120 continue;
1121 }
1122
1123 /* Heal depletion */
1124 if (item->type == BOOK && item->invisible
1125 && strcmp(item->name, "heal depletion") == 0) {
1126 if (remove_depletion(op, -1)) {
1127 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1128 "Shimmering light surrounds and restores you!");
1129 }
1130 }
1131
1132 /* Voices */
1133 if (item->type == BOOK && item->invisible
1134 && strcmp(item->name, "voice_behind") == 0) {
1135 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1136 "You hear a voice from behind you, but you don't dare to "
1137 "turn around:");
1138 draw_ext_info(NDI_WHITE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1139 item->msg);
1140 return;
1141 }
1142
1143 /* Messages */
1144 if (item->type == BOOK && item->invisible
1145 && strcmp(item->name, "message") == 0) {
1146 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1147 item->msg);
1148 return;
1149 }
1150
1151 /* Enchant weapon */
1152 if (item->type == BOOK && item->invisible
1153 && strcmp(item->name, "enchant weapon") == 0) {
1154 if (god_enchants_weapon(op, god, item, skill))
1155 return;
1156
1157 continue;
1158 }
1159
1160 /* Spellbooks - works correctly only for prayers */
1161 if (item->type == SPELL) {
1162 if (check_spell_known(op, item->name))
1163 continue;
1164 if (item->level > skill->level)
1165 continue;
1166
1167 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1168 "%s grants you use of a special prayer!",
1169 god->name);
1170 do_learn_spell(op, item, 1);
1171 return;
1172 }
1173
1174 /* Other gifts */
1175 if (!item->invisible) {
1176 if (god_gives_present(op, god, tr))
1177 return;
1178
1179 continue;
1180 }
1181 /* else ignore it */
1182 }
1183
1184 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY,
1185 "You feel rapture.");
1186 }
1187
1188 /**
1189 * Checks and maybe punishes someone praying.
1190 * All applied items are examined, if player is using more items of other gods,
1191 * s/he loses experience in praying or general experience if no praying.
1192 *
1193 * @param op
1194 * player the god examines.
1195 * @param god
1196 * god examining the player.
1197 * @return
1198 * negative value is god is not pleased, else positive value, the higher the better.
1199 */
1200 static int god_examines_priest(object *op, const object *god) {
1201 int reaction = 1;
1202 object *skop;
1203
1204 FOR_INV_PREPARE(op, item)
1205 if (QUERY_FLAG(item, FLAG_APPLIED)) {
1206 reaction += god_examines_item(god, item)*(item->magic ? abs(item->magic) : 1);
1207 }
1208 FOR_INV_FINISH();
1209
1210 /* well, well. Looks like we screwed up. Time for god's revenge */
1211 if (reaction < 0) {
1212 int loss = 10000000;
1213 int angry = abs(reaction);
1214
1215 skop = object_find_by_type_subtype(op, SKILL, SK_PRAYING);
1216 if (skop)
1217 loss = 0.05*(float)skop->stats.exp;
1218 change_exp(op, -random_roll(0, loss*angry-1, op, PREFER_LOW), skop ? skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
1219 if (random_roll(0, angry, op, PREFER_LOW)) {
1220 object *tmp = create_archetype(LOOSE_MANA);
1221
1222 cast_magic_storm(op, tmp, op->level+(angry*3));
1223 }
1224 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
1225 "%s becomes angry and punishes you!",
1226 god->name);
1227 }
1228 return reaction;
1229 }
1230
1231 /**
1232 * God checks item the player is using.
1233 * If you are using the item of an enemy
1234 * god, it can be bad...-b.t.
1235 *
1236 * @param god
1237 * god checking.
1238 * @param item
1239 * item to check.
1240 * @retval -1
1241 * item is bad.
1242 * @retval 0
1243 * item is neutral.
1244 * @retval 1
1245 * item is good.
1246 */
1247 static int god_examines_item(const object *god, object *item) {
1248 char buf[MAX_BUF];
1249
1250 if (!god || !item)
1251 return 0;
1252
1253 if (!item->title)
1254 return 1; /* unclaimed item are ok */
1255
1256 snprintf(buf, sizeof(buf), "of %s", god->name);
1257 if (!strcmp(item->title, buf))
1258 return 1; /* belongs to that God */
1259
1260 if (god->title) { /* check if we have any enemy blessed item*/
1261 snprintf(buf, sizeof(buf), "of %s", god->title);
1262 if (!strcmp(item->title, buf)) {
1263 if (item->env) {
1264 char name[MAX_BUF];
1265
1266 query_name(item, name, MAX_BUF);
1267 draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, item->env, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
1268 "Heretic! You are using %s!",
1269 name);
1270 }
1271 return -1;
1272 }
1273 }
1274 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1275 }
1276
1277 /**
1278 * Returns a string that is the name of the god that should be natively worshipped by a
1279 * creature of who has race *race
1280 * if we can't find a god that is appropriate, we return NULL
1281 *
1282 * @param race
1283 * race we're getting the god of.
1284 * @return
1285 * NULL if no matching race, else god's name.
1286 */
1287 static const char *get_god_for_race(const char *race) {
1288 godlink *gl = first_god;
1289 const char *godname = NULL;
1290
1291 if (race == NULL)
1292 return NULL;
1293 while (gl) {
1294 if (gl->arch->clone.race && !strcasecmp(gl->arch->clone.race, race)) {
1295 godname = gl->name;
1296 break;
1297 }
1298 gl = gl->next;
1299 }
1300 return godname;
1301 }
1302
1303 /**
1304 * Changes the attributes of cone, smite, and ball spells as needed by the code.
1305 *
1306 * @param spellop
1307 * spell object to change.
1308 * @param caster
1309 * what is casting spellop (player, spell, ...).
1310 * @return
1311 * 0 if there was no race to assign to the slaying field of the spell, but
1312 * the spell attacktype contains AT_HOLYWORD, 1 else.
1313 */
1314 int tailor_god_spell(object *spellop, object *caster) {
1315 const object *god = find_god(determine_god(caster));
1316 int caster_is_spell = 0;
1317
1318 if (caster->type == SPELL_EFFECT || caster->type == SPELL)
1319 caster_is_spell = 1;
1320
1321 /* if caster is a rune or the like, it doesn't worship anything. However,
1322 * if this object is owned by someone, then the god that they worship
1323 * is relevant, so use that.
1324 */
1325 if (!god && object_get_owner(caster))
1326 god = find_god(determine_god(object_get_owner(caster)));
1327
1328 if (!god || (spellop->attacktype&AT_HOLYWORD && !god->race)) {
1329 if (!caster_is_spell)
1330 draw_ext_info(NDI_UNIQUE, 0, caster, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD,
1331 "This prayer is useless unless you worship an appropriate god");
1332 else
1333 LOG(llevError, "BUG: tailor_god_spell(): no god\n");
1334 object_free_drop_inventory(spellop);
1335 return 0;
1336 }
1337
1338 /* either holy word or godpower attacks will set the slaying field */
1339 if (spellop->attacktype&AT_HOLYWORD || spellop->attacktype&AT_GODPOWER) {
1340 if (spellop->slaying) {
1341 free_string(spellop->slaying);
1342 spellop->slaying = NULL;
1343 }
1344 if (!caster_is_spell)
1345 spellop->slaying = god->slaying ? add_string(god->slaying) : NULL;
1346 else if (caster->slaying)
1347 spellop->slaying = add_string(caster->slaying);
1348 }
1349
1350 /* only the godpower attacktype adds the god's attack onto the spell */
1351 if (spellop->attacktype&AT_GODPOWER)
1352 spellop->attacktype = spellop->attacktype|god->attacktype;
1353
1354 /* tack on the god's name to the spell */
1355 if (spellop->attacktype&AT_HOLYWORD || spellop->attacktype&AT_GODPOWER) {
1356 if (spellop->title)
1357 free_string(spellop->title);
1358 spellop->title = add_string(god->name);
1359 if (spellop->title) {
1360 char buf[MAX_BUF];
1361
1362 snprintf(buf, sizeof(buf), "%s of %s", spellop->name, spellop->title);
1363 FREE_AND_COPY(spellop->name, buf);
1364 FREE_AND_COPY(spellop->name_pl, buf);
1365 }
1366 }
1367
1368 return 1;
1369 }