Crossfire Server, Trunk
gods.c
Go to the documentation of this file.
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 <crossfire@metalforge.org>.
12  */
13 
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 void remove_special_prayers(object *op, const object *god);
42 
55 const char *determine_god(object *op) {
56  const char *godname;
57 
58  /* spells */
59  if ((op->type == SPELL || op->type == SPELL_EFFECT)
60  && op->title) {
61  if (find_god(op->title) != NULL)
62  return op->title;
63  }
64 
65  if (op->type != PLAYER && QUERY_FLAG(op, FLAG_ALIVE)) {
66  /* find a god based on race */
67  if (!op->title) {
68  if (op->race != NULL) {
69  godname = get_god_for_race(op->race);
70  if (godname != NULL) {
71  op->title = add_string(godname);
72  }
73  }
74  }
75 
76  /* find a random god */
77  if (!op->title) {
78  const object *god = get_rand_god();
79  if (god) {
80  op->title = add_string(god->name);
81  }
82  }
83 
84  return op->title;
85  }
86 
87  /* The god the player worships is in the praying skill (native skill
88  * not skill tool). Since a player can only have one instance of
89  * that skill, once we find it, we can return, either with the
90  * title or "none".
91  */
92  if (op->type == PLAYER) {
93  object *tmp;
94 
96  if (tmp != NULL) {
97  return tmp->title != NULL ? tmp->title : "none";
98  }
99  }
100  return ("none");
101 }
102 
111 static int same_string(const char *s1, const char *s2) {
112  if (s1 == NULL)
113  return s2 == NULL;
114  else
115  return s2 != NULL && strcmp(s1, s2) == 0;
116 }
117 
133 static void follower_remove_given_items(object *pl, object *op, const object *god) {
134  const char *given_by;
135 
136  /* search the inventory */
138  given_by = object_get_value(tmp, "divine_giver_name");
139  if (given_by == god->name) {
140  char name[HUGE_BUF];
141 
143  /* Send the client a message. */
144  if (tmp->nrof > 1)
146  "The %s crumble to dust!",
147  name);
148  else
150  "The %s crumbles to dust!",
151  name);
152 
153  object_remove(tmp); /* remove obj from players inv. */
155  } else if (tmp->inv)
157  } FOR_INV_FINISH();
158 }
159 
169 static int follower_has_similar_item(object *op, object *item) {
171  if (tmp->type == item->type
172  && same_string(tmp->name, item->name)
173  && same_string(tmp->title, item->title)
174  && tmp->msg == item->msg
175  && same_string(tmp->slaying, item->slaying))
176  return 1;
177  if (tmp->inv && follower_has_similar_item(tmp, item))
178  return 1;
179  } FOR_INV_FINISH();
180  return 0;
181 }
182 
195 static int god_gives_present(object *op, const object *god, treasure *tr) {
196  object *tmp;
197  char name[HUGE_BUF];
198 
200  return 0;
201 
202  tmp = arch_to_object(tr->item);
203 
204  /*
205  * Give inventory if needed, for instance Lythander's pipe.
206  * Use high level and magic so something IS put in inventory.
207  */
208  fix_generated_item(tmp, NULL, 120, 120, GT_ONLY_GOOD);
209 
210  /* And just in case nothing was put and something is needed, bail out. */
211  if ((tmp->type == ROD || tmp->type == WAND) && (tmp->inv == NULL)) {
212  object_free(tmp, 0);
213  return 0;
214  }
215 
218  "%s lets %s appear in your hands.",
219  god->name, name);
223  object_set_value(tmp, "divine_giver_name", god->name, TRUE);
225  return 1;
226 }
227 
232 static bool try_leave_cult(object* pl, object* skill, int angry) {
233  const uint64_t loss = angry * (skill->stats.exp / 10);
234  if (loss)
236 
237  /* random chance based on our current level
238  * note it gets harder the higher we get
239  */
240  if ((angry == 1) && !(random_roll(0, skill->level, pl, PREFER_LOW))) {
241  return true;
242  } else {
243  return false;
244  }
245 }
246 
258 void pray_at_altar(object *pl, object *altar, object *skill) {
259  const object *pl_god = find_god(determine_god(pl));
260 
262  return;
263 
264  /* If non consecrate altar, don't do anything */
265  if (!altar->other_arch)
266  return;
267 
268  /* hmm. what happend depends on pl's current god, level, etc */
269  if (!pl_god) { /*new convert */
270  become_follower(pl, &altar->other_arch->clone);
271  return;
272  }
273 
274  if (!strcmp(pl_god->name, altar->other_arch->clone.name)) {
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  /* we can super-charge grace to 2x max */
282  if (pl->stats.grace < (2*pl->stats.maxgrace)) {
283  pl->stats.grace += bonus/2;
284  }
285  if (pl->stats.grace > (2*pl->stats.maxgrace)) {
286  pl->stats.grace = (2*pl->stats.maxgrace);
287  }
288 
289  /* Every once in a while, the god decides to checkup on their
290  * follower, and may intervene to help them out.
291  */
292  bonus = MAX(1, bonus+MAX(pl->stats.luck, -3)); /* -- DAMN -- */
293 
294  if (((random_roll(0, 399, pl, PREFER_LOW))-bonus) < 0)
295  god_intervention(pl, pl_god, skill, altar);
296  } else { /* praying to another god! */
297  int angry = 1;
298 
299  /* I believe the logic for detecting opposing gods was completely
300  * broken - I think it should work now. altar->other_arch
301  * points to the god of this altar (which we have
302  * already verified is non null). pl_god->other_arch
303  * is the opposing god - we need to verify that exists before
304  * using its values.
305  */
306  if (pl_god->other_arch
307  && (altar->other_arch->name == pl_god->other_arch->name)) {
308  angry = 2;
309  if (random_roll(0, skill->level+2, pl, PREFER_LOW)-5 > 0) {
310  object *tmp;
311 
312  /* you really screwed up */
313  angry = 3;
315  "Foul Priest! %s punishes you!",
316  pl_god->name);
318  cast_magic_storm(pl, tmp, pl_god->level+20);
319  } else
321  "Foolish heretic! %s is livid!",
322  pl_god->name);
323  } else
325  "Heretic! %s is angered!",
326  pl_god->name);
327 
328  if (try_leave_cult(pl, skill, angry)) {
329  become_follower(pl, &altar->other_arch->clone);
330  } else {
331  /* toss this player off the altar. He can try again. */
333  "A divine force pushes you off the altar.");
334 
335  move_player(pl, absdir(pl->facing+4)); /* back him off the way he came. */
336  }
337  }
338 }
339 
350 static void remove_special_prayers(object *op, const object *god) {
351  treasure *tr;
352  int remove = 0;
353 
354  if (god->randomitems == NULL) {
355  LOG(llevError, "BUG: remove_special_prayers(): god %s without randomitems\n", god->name);
356  return;
357  }
358 
359 
360  /* Outer loop iterates over all special prayer marks */
362  /* we mark special prayers with the STARTEQUIP flag, so if it isn't
363  * in that category, not something we need to worry about.
364  */
365  if (tmp->type != SPELL || !QUERY_FLAG(tmp, FLAG_STARTEQUIP))
366  continue;
367 
368  /* Inner loop tries to find the special prayer in the god's treasure
369  * list. We default that the spell should not be removed.
370  */
371  remove = 0;
372  for (tr = god->randomitems->items; tr; tr = tr->next) {
373  if (tr->item == NULL)
374  continue;
375 
376  /* Basically, see if the matching spell is granted by this god. */
377 
378  if (tr->item->clone.type == SPELL && tr->item->clone.name == tmp->name) {
379  remove = 1;
380  break;
381  }
382  }
383  if (remove) {
384  /* just do the work of removing the spell ourselves - we already
385  * know that the player knows the spell
386  */
389  "You lose knowledge of %s.",
390  tmp->name);
391  player_unready_range_ob(op->contr, tmp);
394  }
395  } FOR_INV_FINISH();
396 }
397 
413 int become_follower(object *op, const object *new_god) {
414  /* take away any special god-characteristic items. */
416  /* remove all invisible startequip items which are
417  * not skill, exp or force
418  */
420  && item->invisible
421  && (item->type != SKILL)
422  && (item->type != FORCE)
423  && (item->type != SPELL)) {
427  }
428  } FOR_INV_FINISH();
429 
430  /* remove any items given by the old god */
431  const object *old_god = find_god(determine_god(op));
432  if (old_god) {
433  /* Changed to use the new "divine_giver_name" key_value
434  * so it can reliably delete enchanted items. Now it loops
435  * through the player's inventory, instead of the god's
436  * treasure list.
437  */
438  follower_remove_given_items(op, op, old_god);
439  remove_special_prayers(op, old_god);
440  }
441 
442  if (!op || !new_god)
443  return 0;
444 
445  if (op->race && new_god->slaying && strstr(op->race, new_god->slaying)) {
447  "Fool! %s detests your kind!",
448  new_god->name);
449  if (random_roll(0, op->level-1, op, PREFER_LOW)-5 > 0) {
450  object *tmp = create_archetype(LOOSE_MANA);
451  cast_magic_storm(op, tmp, new_god->level+10);
452  }
453  return 0;
454  }
455 
456  /* give the player any special god-characteristic-items. */
457  for (treasure *tr = new_god->randomitems->items; tr != NULL; tr = tr->next) {
458  if (tr->item
459  && tr->item->clone.invisible
460  && tr->item->clone.type != SPELLBOOK
461  && tr->item->clone.type != BOOK
462  && tr->item->clone.type != SPELL)
463  god_gives_present(op, new_god, tr);
464  }
465 
467  "You become a follower of %s!",
468  new_god->name);
469 
471  /* Player has no skill - give them the skill */
472  if (!skop) {
473  /* The archetype should always be defined - if we crash here because it doesn't,
474  * things are really messed up anyways.
475  */
478  }
479 
480  int sk_applied = QUERY_FLAG(skop, FLAG_APPLIED); /* save skill status */
481 
482  int undeadified = 0; /* Turns to true if changing god can changes the undead
483  * status of the player.*/
484  /* Clear the "undead" status. We also need to force a call to change_abil,
485  * so I set undeadified for that.
486  * - gros, 21th July 2006.
487  */
488  if ((old_god) && (QUERY_FLAG(old_god, FLAG_UNDEAD))) {
489  CLEAR_FLAG(skop, FLAG_UNDEAD);
490  undeadified = 1;
491  }
492 
493  if (skop->title) { /* get rid of old god */
495  "%s's blessing is withdrawn from you.",
496  skop->title);
497 
498  /* The point of this is to really show what abilities the player just lost */
499  if (sk_applied || undeadified) {
500  CLEAR_FLAG(skop, FLAG_APPLIED);
501  (void)change_abil(op, skop);
502  }
503  free_string(skop->title);
504  }
505 
506  /* now change to the new gods attributes to exp_obj */
507  skop->title = add_string(new_god->name);
508  skop->path_attuned = new_god->path_attuned;
509  skop->path_repelled = new_god->path_repelled;
510  skop->path_denied = new_god->path_denied;
511  /* copy god's resistances */
512  memcpy(skop->resist, new_god->resist, sizeof(new_god->resist));
513 
514  /* make sure that certain immunities do NOT get passed
515  * to the follower!
516  */
517  for (int i = 0; i < NROFATTACKS; i++)
518  if (skop->resist[i] > 30
519  && (i == ATNR_FIRE || i == ATNR_COLD || i == ATNR_ELECTRICITY || i == ATNR_POISON))
520  skop->resist[i] = 30;
521 
522  skop->stats.hp = (int16_t)new_god->last_heal;
523  skop->stats.sp = (int16_t)new_god->last_sp;
524  skop->stats.grace = (int16_t)new_god->last_grace;
525  skop->stats.food = (int16_t)new_god->last_eat;
526  skop->stats.luck = (int8_t)new_god->stats.luck;
527  /* gods may pass on certain flag properties */
528  update_priest_flag(new_god, skop, FLAG_SEE_IN_DARK);
529  update_priest_flag(new_god, skop, FLAG_REFL_SPELL);
530  update_priest_flag(new_god, skop, FLAG_REFL_MISSILE);
531  update_priest_flag(new_god, skop, FLAG_STEALTH);
532  update_priest_flag(new_god, skop, FLAG_MAKE_INVIS);
533  update_priest_flag(new_god, skop, FLAG_UNDEAD);
534  update_priest_flag(new_god, skop, FLAG_BLIND);
535  update_priest_flag(new_god, skop, FLAG_XRAYS); /* better have this if blind! */
536  update_priest_flag(new_god, skop, FLAG_USE_WEAPON);
537  update_priest_flag(new_god, skop, FLAG_USE_ARMOUR);
538  update_priest_flag(new_god, skop, FLAG_USE_SHIELD);
539 
541  "You are bathed in %s's aura.",
542  new_god->name);
543 
544  /* Weapon/armour use are special...handle flag toggles here as this can
545  * only happen when gods are worshipped and if the new priest could
546  * have used armour/weapons in the first place.
547  *
548  * This also can happen for monks which cannot use weapons. In this case
549  * do not allow to use weapons even if the god otherwise would allow it.
550  */
551  if (!object_present_in_ob_by_name(FORCE, "no weapon force", op)) {
552  if (worship_forbids_use(op, skop, FLAG_USE_WEAPON, "weapons"))
554  }
555  update_priest_flag(new_god, skop, FLAG_USE_ARMOUR);
556 
557  if (worship_forbids_use(op, skop, FLAG_USE_ARMOUR, "armour")) {
560  stop_using_item(op, BOOTS, 1);
562  }
563 
564  if (worship_forbids_use(op, skop, FLAG_USE_SHIELD, "shield"))
566 
567  SET_FLAG(skop, FLAG_APPLIED);
568  (void)change_abil(op, skop);
569 
570  /* return to previous skill status */
571  if (!sk_applied)
572  CLEAR_FLAG(skop, FLAG_APPLIED);
573 
574  return 1;
575 }
576 
590 static int worship_forbids_use(object *op, object *exp_obj, uint32_t flag, const char *string) {
591  if (QUERY_FLAG(&op->arch->clone, flag)) {
592  if (QUERY_FLAG(op, flag) != QUERY_FLAG(exp_obj, flag)) {
593  update_priest_flag(exp_obj, op, flag);
594  if (QUERY_FLAG(op, flag))
596  "You may use %s again.",
597  string);
598  else {
600  "You are forbidden to use %s.",
601  string);
602  return 1;
603  }
604  }
605  }
606  return 0;
607 }
608 
620 static void stop_using_item(object *op, int type, int number) {
622  if (tmp->type == type && QUERY_FLAG(tmp, FLAG_APPLIED)) {
624  number--;
625  if (number <= 0)
626  break;
627  }
628  FOR_INV_FINISH();
629 }
630 
643 static void update_priest_flag(const object *god, object *exp_ob, uint32_t flag) {
644  if (QUERY_FLAG(god, flag) && !QUERY_FLAG(exp_ob, flag))
645  SET_FLAG(exp_ob, flag);
646  else if (QUERY_FLAG(exp_ob, flag) && !QUERY_FLAG(god, flag)) {
647  /* When this is called with the exp_ob set to the player,
648  * this check is broken, because most all players arch
649  * allow use of weapons. I'm not actually sure why this
650  * check is here - I guess if you had a case where the
651  * value in the archetype (wisdom) should over ride the restrictions
652  * the god places on it, this may make sense. But I don't think
653  * there is any case like that.
654  */
655 
656 /* if (!(QUERY_FLAG(&(exp_ob->arch->clone), flag)))*/
657  CLEAR_FLAG(exp_ob, flag);
658  }
659 }
660 
661 
675 archetype *determine_holy_arch(const object *god, const char *type) {
676  treasure *tr;
677  int count;
678  object *item;
679 
680  if (!god || !god->randomitems) {
681  LOG(llevError, "BUG: determine_holy_arch(): no god or god without randomitems\n");
682  return NULL;
683  }
684 
685  count = 0;
686  for (tr = god->randomitems->items; tr != NULL; tr = tr->next) {
687  if (!tr->item)
688  continue;
689  item = &tr->item->clone;
690  if (item->type == BOOK && item->invisible && item->name == type)
691  count++;
692  }
693  if (count == 0) {
694  return NULL;
695  }
696 
697  count = rndm(1, count);
698 
699  for (tr = god->randomitems->items; tr != NULL; tr = tr->next) {
700  if (!tr->item)
701  continue;
702  item = &tr->item->clone;
703  if (item->type == BOOK && item->invisible && item->name == type) {
704  count--;
705  if (count == 0)
706  return item->other_arch;
707  }
708  }
709 
710  return NULL;
711 }
712 
723 static int god_removes_curse(object *op, int remove_damnation) {
724  int success = 0;
725 
727  if (tmp->invisible)
728  continue;
729  if (QUERY_FLAG(tmp, FLAG_DAMNED) && !remove_damnation)
730  continue;
732  success = 1;
736  if (op->type == PLAYER)
738  }
739  } FOR_INV_FINISH();
740 
741  if (success)
743  "You feel like someone is helping you.");
744  return success;
745 }
746 
756 static int follower_level_to_enchantments(int level, int difficulty) {
757  if (difficulty < 1) {
758  LOG(llevError, "follower_level_to_enchantments(): difficulty %d is invalid\n", difficulty);
759  return 0;
760  }
761 
762  if (level <= 20)
763  return level/difficulty;
764  if (level <= 40)
765  return (20+(level-20)/2)/difficulty;
766  return (30+(level-40)/4)/difficulty;
767 }
768 
787 static int improve_weapon_magic(object *op, object *tr, object *weapon, object *skill) {
788  int tmp = follower_level_to_enchantments(skill->level, tr->level);
789 
790  if (weapon->magic < tmp) {
792  "A phosphorescent glow envelops your weapon!");
793  weapon->magic++;
794  if (op->type == PLAYER)
795  esrv_update_item(UPD_NAME, op, weapon);
796  weapon->item_power++;
797  return 1;
798  }
799 
800  return 0;
801 }
802 
820 static int god_enchants_weapon(object *op, const object *god, object *tr, object *skill) {
821  char buf[MAX_BUF];
822  object *weapon;
823  uint32_t attacktype;
824 
826  if (weapon == NULL)
828  if (weapon == NULL || god_examines_item(god, weapon) <= 0)
829  return 0;
830 
831  if (weapon->item_power >= MAX_WEAPON_ITEM_POWER) {
833  "%s considers your %s is not worthy to be enchanted any more.",
834  god->name,
835  weapon->name);
836  return 0;
837  }
838 
839  /* If personalized_blessings is activated, then the god's name is
840  * associated with the weapon, as well as the owner (the one who blesses it),
841  * and a "weapon willpower", which is equivalent to the owner's experience
842  * in praying when the weapon is blessed.
843  * Those values are used later, when another player attempts to wield the
844  * weapon - nasty things may happen to those who do not deserve to use it ! :)
845  */
847  const char *divine_owner = object_get_value(weapon, "divine_blessing_name");
848  const char *owner = object_get_value(weapon, "item_owner");
849  object *skillop = NULL;
850 
851  if (divine_owner != NULL && strcmp(divine_owner, god->name) != 0) {
852  /* Huho... Another god already blessed this one ! */
854  "Your %s already belongs to %s !",
855  weapon->name, divine_owner);
856  return 0;
857  }
858 
859  if ((owner != NULL) && (strcmp(owner, op->name) != 0)) {
860  /* Maybe the weapon itself will not agree ? */
862  "The %s is not yours, and is magically protected against such changes !",
863  weapon->name);
864  return 0;
865  }
866  skillop = find_skill_by_number(op, SK_PRAYING);
867  if (skillop == NULL) {
868  LOG(llevError, "god_enchants_weapon: no praying skill object found ?!\n");
869  snprintf(buf, sizeof(buf), "%d", 1);
870  } else
871  snprintf(buf, sizeof(buf), "%"FMT64, skillop->stats.exp);
872  object_set_value(weapon, "divine_blessing_name", god->name, TRUE);
873  object_set_value(weapon, "item_owner", op->name, TRUE);
874  object_set_value(weapon, "item_willpower", buf, TRUE);
875  }
876 
877  /* First give it a title, so other gods won't touch it */
878  if (!weapon->title) {
879  snprintf(buf, sizeof(buf), "of %s", god->name);
880  weapon->title = add_string(buf);
881  if (op->type == PLAYER)
882  esrv_update_item(UPD_NAME, op, weapon);
884  "Your weapon quivers as if struck!");
885  }
886 
887  /* Allow the weapon to slay enemies */
888  if (!weapon->slaying && god->slaying) {
889  weapon->slaying = add_string(god->slaying);
891  "Your %s now hungers to slay enemies of your god!",
892  weapon->name);
893  weapon->item_power++;
894  return 1;
895  }
896 
897  /* Add the gods attacktype */
898  attacktype = (weapon->attacktype == 0) ? AT_PHYSICAL : weapon->attacktype;
899  if ((attacktype&god->attacktype) != god->attacktype) {
901  "Your weapon suddenly glows!");
902  weapon->attacktype = attacktype|god->attacktype;
903  weapon->item_power++;
904  return 1;
905  }
906 
907  /* Higher magic value */
908  return improve_weapon_magic(op, tr, weapon, skill);
909 }
910 
926 static void god_intervention(object *op, const object *god, object *skill, object *altar) {
927  treasure *tr;
928 
929  if (!god || !god->randomitems) {
930  LOG(llevError, "BUG: god_intervention(): no god or god without randomitems\n");
931  return;
932  }
933 
934  /* lets do some checks of whether we are kosher with our god */
935  if (god_examines_priest(op, god) < 0)
936  return;
937 
939  "You feel a holy presence!");
940 
941  if (altar->anim_suffix != NULL)
942  apply_anim_suffix(altar, altar->anim_suffix);
943 
944  for (tr = god->randomitems->items; tr != NULL; tr = tr->next) {
945  object *item;
946 
947  if (tr->chance <= random_roll(0, 99, op, PREFER_HIGH))
948  continue;
949 
950  /* Treasurelist - generate some treasure for the follower */
951  if (tr->name) {
953  if (tl == NULL)
954  continue;
955 
957  "Something appears before your eyes. You catch it before it falls to the ground.");
958 
960  return;
961  }
962 
963  if (!tr->item) {
964  LOG(llevError, "BUG: empty entry in %s's treasure list\n", god->name);
965  continue;
966  }
967  item = &tr->item->clone;
968 
969  /* Grace limit */
970  if (item->type == BOOK && item->invisible
971  && strcmp(item->name, "grace limit") == 0) {
972  if (op->stats.grace < item->stats.grace
973  || op->stats.grace < op->stats.maxgrace) {
974  object *tmp;
975 
976  /* Follower lacks the required grace for the following
977  * treasure list items. */
978 
980  cast_change_ability(op, op, tmp, 0, 1);
982  return;
983  }
984  continue;
985  }
986 
987  /* Restore grace */
988  if (item->type == BOOK && item->invisible
989  && strcmp(item->name, "restore grace") == 0) {
990  if (op->stats.grace >= 0)
991  continue;
992  op->stats.grace = random_roll(0, 9, op, PREFER_HIGH);
994  "You are returned to a state of grace.");
995  return;
996  }
997 
998  /* Heal damage */
999  if (item->type == BOOK && item->invisible
1000  && strcmp(item->name, "restore hitpoints") == 0) {
1001  if (op->stats.hp >= op->stats.maxhp)
1002  continue;
1004  "A white light surrounds and heals you!");
1005  op->stats.hp = op->stats.maxhp;
1006  return;
1007  }
1008 
1009  /* Restore spellpoints */
1010  if (item->type == BOOK
1011  && item->invisible
1012  && strcmp(item->name, "restore spellpoints") == 0) {
1013  int max = op->stats.maxsp*(item->stats.maxsp/100.0);
1014  /* Restore to 50 .. 100%, if sp < 50% */
1015  int new_sp = random_roll(1000, 1999, op, PREFER_HIGH)/2000.0*max;
1016  if (op->stats.sp >= max/2)
1017  continue;
1019  "A blue lightning strikes your head but doesn't hurt you!");
1020  op->stats.sp = new_sp;
1021  }
1022 
1023  /* Various heal spells */
1024  if (item->type == BOOK && item->invisible
1025  && strcmp(item->name, "heal spell") == 0) {
1026  object *tmp;
1027  int success;
1028 
1030 
1031  success = cast_heal(op, op, tmp, 0);
1033  if (success)
1034  return;
1035 
1036  continue;
1037  }
1038 
1039  /* Remove curse */
1040  if (item->type == BOOK && item->invisible
1041  && strcmp(item->name, "remove curse") == 0) {
1042  if (god_removes_curse(op, 0))
1043  return;
1044 
1045  continue;
1046  }
1047 
1048  /* Remove damnation */
1049  if (item->type == BOOK && item->invisible
1050  && strcmp(item->name, "remove damnation") == 0) {
1051  if (god_removes_curse(op, 1))
1052  return;
1053 
1054  continue;
1055  }
1056 
1057  /* Heal depletion */
1058  if (item->type == BOOK && item->invisible
1059  && strcmp(item->name, "heal depletion") == 0) {
1060  if (remove_depletion(op, -1)) {
1062  "Shimmering light surrounds and restores you!");
1063  }
1064  }
1065 
1066  /* Voices */
1067  if (item->type == BOOK && item->invisible
1068  && strcmp(item->name, "voice_behind") == 0) {
1070  "You hear a voice from behind you, but you don't dare to "
1071  "turn around:");
1073  item->msg);
1074  return;
1075  }
1076 
1077  /* Messages */
1078  if (item->type == BOOK && item->invisible
1079  && strcmp(item->name, "message") == 0) {
1081  item->msg);
1082  return;
1083  }
1084 
1085  /* Enchant weapon */
1086  if (item->type == BOOK && item->invisible
1087  && strcmp(item->name, "enchant weapon") == 0) {
1088  if (god_enchants_weapon(op, god, item, skill))
1089  return;
1090 
1091  continue;
1092  }
1093 
1094  /* Spellbooks - works correctly only for prayers */
1095  if (item->type == SPELL) {
1096  if (check_spell_known(op, item->name))
1097  continue;
1098  if (item->level > skill->level)
1099  continue;
1100 
1102  "%s grants you use of a special prayer!",
1103  god->name);
1104  do_learn_spell(op, item, 1);
1105  return;
1106  }
1107 
1108  /* Other gifts */
1109  if (!item->invisible) {
1110  if (god_gives_present(op, god, tr))
1111  return;
1112 
1113  continue;
1114  }
1115  /* else ignore it */
1116  }
1117 
1119  "You feel rapture.");
1120 }
1121 
1134 static int god_examines_priest(object *op, const object *god) {
1135  int reaction = 1;
1136  object *skop;
1137 
1139  if (QUERY_FLAG(item, FLAG_APPLIED)) {
1140  reaction += god_examines_item(god, item)*(item->magic ? abs(item->magic) : 1);
1141  }
1142  FOR_INV_FINISH();
1143 
1144  /* well, well. Looks like we screwed up. Time for god's revenge */
1145  if (reaction < 0) {
1146  int loss = 10000000;
1147  int angry = abs(reaction);
1148 
1150  if (skop)
1151  loss = 0.05*(float)skop->stats.exp;
1152  change_exp(op, -random_roll(0, loss*angry-1, op, PREFER_LOW), skop ? skop->skill : "none", SK_SUBTRACT_SKILL_EXP);
1153  if (random_roll(0, angry, op, PREFER_LOW)) {
1154  object *tmp = create_archetype(LOOSE_MANA);
1155 
1156  cast_magic_storm(op, tmp, op->level+(angry*3));
1157  }
1159  "%s becomes angry and punishes you!",
1160  god->name);
1161  }
1162  return reaction;
1163 }
1164 
1181 static int god_examines_item(const object *god, object *item) {
1182  char buf[MAX_BUF];
1183 
1184  if (!god || !item)
1185  return 0;
1186 
1187  if (!item->title)
1188  return 1; /* unclaimed item are ok */
1189 
1190  snprintf(buf, sizeof(buf), "of %s", god->name);
1191  if (!strcmp(item->title, buf))
1192  return 1; /* belongs to that God */
1193 
1194  if (god->title) { /* check if we have any enemy blessed item*/
1195  snprintf(buf, sizeof(buf), "of %s", god->title);
1196  if (!strcmp(item->title, buf)) {
1197  if (item->env) {
1198  char name[MAX_BUF];
1199 
1202  "Heretic! You are using %s!",
1203  name);
1204  }
1205  return -1;
1206  }
1207  }
1208  return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1209 }
1210 
1222 int tailor_god_spell(object *spellop, object *caster) {
1223  const object *god = find_god(determine_god(caster));
1224  int caster_is_spell = 0;
1225 
1226  if (caster->type == SPELL_EFFECT || caster->type == SPELL)
1227  caster_is_spell = 1;
1228 
1229  /* if caster is a rune or the like, it doesn't worship anything. However,
1230  * if this object is owned by someone, then the god that they worship
1231  * is relevant, so use that.
1232  */
1233  if (!god && object_get_owner(caster))
1234  god = find_god(determine_god(object_get_owner(caster)));
1235 
1236  if (!god || (spellop->attacktype&AT_HOLYWORD && !god->race)) {
1237  if (!caster_is_spell)
1239  "This prayer is useless unless you worship an appropriate god");
1240  else
1241  LOG(llevError, "BUG: tailor_god_spell(): no god\n");
1242  object_free_drop_inventory(spellop);
1243  return 0;
1244  }
1245 
1246  /* either holy word or godpower attacks will set the slaying field */
1247  if (spellop->attacktype&AT_HOLYWORD || spellop->attacktype&AT_GODPOWER) {
1248  if (spellop->slaying) {
1249  free_string(spellop->slaying);
1250  spellop->slaying = NULL;
1251  }
1252  if (!caster_is_spell)
1253  spellop->slaying = god->slaying ? add_string(god->slaying) : NULL;
1254  else if (caster->slaying)
1255  spellop->slaying = add_string(caster->slaying);
1256  }
1257 
1258  /* only the godpower attacktype adds the god's attack onto the spell */
1259  if (spellop->attacktype&AT_GODPOWER)
1260  spellop->attacktype = spellop->attacktype|god->attacktype;
1261 
1262  /* tack on the god's name to the spell */
1263  if (spellop->attacktype&AT_HOLYWORD || spellop->attacktype&AT_GODPOWER) {
1264  if (spellop->title)
1265  free_string(spellop->title);
1266  spellop->title = add_string(god->name);
1267  if (spellop->title) {
1268  char buf[MAX_BUF];
1269 
1270  snprintf(buf, sizeof(buf), "%s of %s", spellop->name, spellop->title);
1271  FREE_AND_COPY(spellop->name, buf);
1272  FREE_AND_COPY(spellop->name_pl, buf);
1273  }
1274  }
1275 
1276  return 1;
1277 }
treasurestruct::item
struct archt * item
Definition: treasure.h:64
treasurestruct::chance
uint8_t chance
Definition: treasure.h:70
god_removes_curse
static int god_removes_curse(object *op, int remove_damnation)
Definition: gods.c:723
PLAYER
@ PLAYER
Definition: object.h:107
global.h
object_free
void object_free(object *ob, int flags)
Definition: object.c:1578
add_string
sstring add_string(const char *str)
Definition: shstr.c:124
MSG_TYPE_SKILL_PRAY
#define MSG_TYPE_SKILL_PRAY
Definition: newclient.h:591
object_remove
void object_remove(object *op)
Definition: object.c:1819
BOW
@ BOW
Definition: object.h:118
llevError
@ llevError
Definition: logger.h:11
find_skill_by_number
object * find_skill_by_number(object *who, int skillno)
Definition: main.c:376
WAND
@ WAND
Definition: object.h:220
FLAG_UNDEAD
#define FLAG_UNDEAD
Definition: define.h:270
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
tailor_god_spell
int tailor_god_spell(object *spellop, object *caster)
Definition: gods.c:1222
GLOVES
@ GLOVES
Definition: object.h:213
FLAG_STARTEQUIP
#define FLAG_STARTEQUIP
Definition: define.h:268
MSG_TYPE_SKILL
#define MSG_TYPE_SKILL
Definition: newclient.h:407
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
FLAG_REFL_MISSILE
#define FLAG_REFL_MISSILE
Definition: define.h:273
obj::race
sstring race
Definition: object.h:321
do_learn_spell
void do_learn_spell(object *op, object *spell, int special_prayer)
Definition: apply.c:484
FLAG_SEE_IN_DARK
#define FLAG_SEE_IN_DARK
Definition: define.h:337
same_string
static int same_string(const char *s1, const char *s2)
Definition: gods.c:111
AT_PHYSICAL
#define AT_PHYSICAL
Definition: attack.h:76
obj::path_attuned
uint32_t path_attuned
Definition: object.h:348
pl
Definition: player.h:105
ARMOUR
@ ARMOUR
Definition: object.h:120
PREFER_LOW
#define PREFER_LOW
Definition: define.h:564
WEAPON
@ WEAPON
Definition: object.h:119
determine_god
const char * determine_god(object *op)
Definition: gods.c:55
LOOSE_MANA
#define LOOSE_MANA
Definition: spells.h:162
SK_PRAYING
@ SK_PRAYING
Definition: skills.h:49
liv::hp
int16_t hp
Definition: living.h:40
MSG_TYPE_ATTRIBUTE
#define MSG_TYPE_ATTRIBUTE
Definition: newclient.h:405
GT_ONLY_GOOD
@ GT_ONLY_GOOD
Definition: treasure.h:34
move_player
int move_player(object *op, int dir)
Definition: player.c:2923
SKILL
@ SKILL
Definition: object.h:143
object_find_by_type_applied
object * object_find_by_type_applied(const object *who, int type)
Definition: object.c:4054
find_treasurelist
treasurelist * find_treasurelist(const char *name)
Definition: assets.cpp:263
obj::path_denied
uint32_t path_denied
Definition: object.h:350
Ice.tmp
int tmp
Definition: Ice.py:207
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:244
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:17
HOLY_POSSESSION
#define HOLY_POSSESSION
Definition: spells.h:168
random_roll64
int64_t random_roll64(int64_t min, int64_t max, const object *op, int goodbad)
Definition: utils.c:77
create_treasure
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:241
FLAG_APPLIED
#define FLAG_APPLIED
Definition: define.h:235
remove_special_prayers
static void remove_special_prayers(object *op, const object *god)
Definition: gods.c:350
FLAG_STEALTH
#define FLAG_STEALTH
Definition: define.h:312
events_execute_object_event
int events_execute_object_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: events.cpp:274
FLAG_BLIND
#define FLAG_BLIND
Definition: define.h:336
GT_STARTEQUIP
@ GT_STARTEQUIP
Definition: treasure.h:33
obj::randomitems
struct treasureliststruct * randomitems
Definition: object.h:390
HUGE_BUF
#define HUGE_BUF
Definition: define.h:37
treasurestruct
Definition: treasure.h:63
MAX
#define MAX(x, y)
Definition: compat.h:24
find_god
const object * find_god(const char *name)
Definition: holy.cpp:321
cast_magic_storm
void cast_magic_storm(object *op, object *tmp, int lvl)
Definition: spell_effect.c:46
archt
Definition: object.h:469
settings
struct Settings settings
Definition: init.c:39
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
obj::last_heal
int32_t last_heal
Definition: object.h:362
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4317
obj::slaying
sstring slaying
Definition: object.h:322
free_string
void free_string(sstring str)
Definition: shstr.c:280
liv::luck
int8_t luck
Definition: living.h:39
god_gives_present
static int god_gives_present(object *op, const object *god, treasure *tr)
Definition: gods.c:195
object_find_by_type_subtype
object * object_find_by_type_subtype(const object *who, int type, int subtype)
Definition: object.c:4272
liv::exp
int64_t exp
Definition: living.h:47
FMT64
#define FMT64
Definition: compat.h:16
PREFER_HIGH
#define PREFER_HIGH
Definition: define.h:563
cast_heal
int cast_heal(object *op, object *caster, object *spell, int dir)
Definition: spell_effect.c:1754
HELMET
@ HELMET
Definition: object.h:136
link_player_skills
void link_player_skills(object *op)
Definition: player.c:287
get_rand_god
const object * get_rand_god(void)
Definition: holy.cpp:77
god_examines_item
static int god_examines_item(const object *god, object *item)
Definition: gods.c:1181
obj::name
sstring name
Definition: object.h:314
query_name
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:585
FLAG_KNOWN_CURSED
#define FLAG_KNOWN_CURSED
Definition: define.h:320
obj::path_repelled
uint32_t path_repelled
Definition: object.h:349
improve_weapon_magic
static int improve_weapon_magic(object *op, object *tr, object *weapon, object *skill)
Definition: gods.c:787
remove_depletion
int remove_depletion(object *op, int level)
Definition: living.c:756
obj::name_pl
sstring name_pl
Definition: object.h:318
stop_using_item
static void stop_using_item(object *op, int type, int number)
Definition: gods.c:620
ROD
@ ROD
Definition: object.h:109
MSG_TYPE_ITEM
#define MSG_TYPE_ITEM
Definition: newclient.h:412
SCRIPT_FIX_ALL
#define SCRIPT_FIX_ALL
Definition: global.h:377
query_short_name
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:510
AP_IGNORE_CURSE
#define AP_IGNORE_CURSE
Definition: define.h:582
FLAG_MAKE_INVIS
#define FLAG_MAKE_INVIS
Definition: define.h:328
absdir
int absdir(int d)
Definition: object.c:3685
FREE_AND_COPY
#define FREE_AND_COPY(sv, nv)
Definition: global.h:201
worship_forbids_use
static int worship_forbids_use(object *op, object *exp_obj, uint32_t flag, const char *string)
Definition: gods.c:590
FLAG_DAMNED
#define FLAG_DAMNED
Definition: define.h:317
god_intervention
static void god_intervention(object *op, const object *god, object *skill, object *altar)
Definition: gods.c:926
UPD_FLAGS
#define UPD_FLAGS
Definition: newclient.h:315
FLAG_USE_SHIELD
#define FLAG_USE_SHIELD
Definition: define.h:237
god_enchants_weapon
static int god_enchants_weapon(object *op, const object *god, object *tr, object *skill)
Definition: gods.c:820
obj::other_arch
struct archt * other_arch
Definition: object.h:418
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
object_set_value
int object_set_value(object *op, const char *key, const char *value, int add_key)
Definition: object.c:4470
rndm
int rndm(int min, int max)
Definition: utils.c:162
disinfect.count
int count
Definition: disinfect.py:7
say.max
dictionary max
Definition: say.py:148
get_god_for_race
const char * get_god_for_race(const char *race)
Definition: holy.cpp:94
ATNR_POISON
#define ATNR_POISON
Definition: attack.h:59
FLAG_USE_WEAPON
#define FLAG_USE_WEAPON
Definition: define.h:296
sproto.h
liv::food
int32_t food
Definition: living.h:48
BOOK
@ BOOK
Definition: object.h:114
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
follower_remove_given_items
static void follower_remove_given_items(object *pl, object *op, const object *god)
Definition: gods.c:133
follower_has_similar_item
static int follower_has_similar_item(object *op, object *item)
Definition: gods.c:169
MAX_BUF
#define MAX_BUF
Definition: define.h:35
fix_generated_item
void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags)
Definition: treasure.c:876
obj::item_power
int8_t item_power
Definition: object.h:367
create_archetype
object * create_archetype(const char *name)
Definition: arch.cpp:281
ATNR_FIRE
#define ATNR_FIRE
Definition: attack.h:51
random_roll
int random_roll(int min, int max, const object *op, int goodbad)
Definition: utils.c:42
MSG_TYPE_ITEM_ADD
#define MSG_TYPE_ITEM_ADD
Definition: newclient.h:643
obj::title
sstring title
Definition: object.h:320
treasureliststruct::items
struct treasurestruct * items
Definition: treasure.h:89
become_follower
int become_follower(object *op, const object *new_god)
Definition: gods.c:413
sounds.h
FLAG_REFL_SPELL
#define FLAG_REFL_SPELL
Definition: define.h:275
altar_valkyrie.altar
altar
Definition: altar_valkyrie.py:27
obj::type
uint8_t type
Definition: object.h:343
obj::last_grace
int16_t last_grace
Definition: object.h:364
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
spells.h
obj::stats
living stats
Definition: object.h:373
archt::clone
object clone
Definition: object.h:473
apply_anim_suffix
void apply_anim_suffix(object *who, const char *suffix)
Definition: anim.c:149
FLAG_USE_ARMOUR
#define FLAG_USE_ARMOUR
Definition: define.h:295
item
Definition: item.py:1
MSG_TYPE_ITEM_REMOVE
#define MSG_TYPE_ITEM_REMOVE
Definition: newclient.h:642
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
create_archetype_by_object_name
object * create_archetype_by_object_name(const char *name)
Definition: arch.cpp:118
follower_level_to_enchantments
static int follower_level_to_enchantments(int level, int difficulty)
Definition: gods.c:756
check_spell_known
object * check_spell_known(object *op, const char *name)
Definition: spell_util.c:393
liv::grace
int16_t grace
Definition: living.h:44
give.op
op
Definition: give.py:33
Settings::personalized_blessings
uint8_t personalized_blessings
Definition: global.h:307
determine_holy_arch
archetype * determine_holy_arch(const object *god, const char *type)
Definition: gods.c:675
MSG_TYPE_ATTRIBUTE_GOD
#define MSG_TYPE_ATTRIBUTE_GOD
Definition: newclient.h:575
esrv_update_item
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:360
SPELL_EFFECT
@ SPELL_EFFECT
Definition: object.h:215
obj::last_sp
int32_t last_sp
Definition: object.h:363
NDI_WHITE
#define NDI_WHITE
Definition: newclient.h:243
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
SK_SUBTRACT_SKILL_EXP
#define SK_SUBTRACT_SKILL_EXP
Definition: skills.h:81
apply_special
int apply_special(object *who, object *op, int aflags)
Definition: apply.c:1156
buf
StringBuffer * buf
Definition: readable.c:1610
change_exp
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2168
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2833
obj::last_eat
int32_t last_eat
Definition: object.h:361
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
try_leave_cult
static bool try_leave_cult(object *pl, object *skill, int angry)
Definition: gods.c:232
update_priest_flag
static void update_priest_flag(const object *god, object *exp_ob, uint32_t flag)
Definition: gods.c:643
object_present_in_ob_by_name
object * object_present_in_ob_by_name(int type, const char *str, const object *op)
Definition: object.c:3174
UPD_NAME
#define UPD_NAME
Definition: newclient.h:318
obj::skill
sstring skill
Definition: object.h:324
treasurestruct::next
struct treasurestruct * next
Definition: treasure.h:66
pray_at_altar
void pray_at_altar(object *pl, object *altar, object *skill)
Definition: gods.c:258
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:309
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1546
AT_GODPOWER
#define AT_GODPOWER
Definition: attack.h:96
get_archetype_by_type_subtype
archetype * get_archetype_by_type_subtype(int type, int subtype)
Definition: arch.cpp:101
cast_change_ability
int cast_change_ability(object *op, object *caster, object *spell_ob, int dir, int silent)
Definition: spell_effect.c:1909
MSG_TYPE_ITEM_CHANGE
#define MSG_TYPE_ITEM_CHANGE
Definition: newclient.h:644
archt::name
sstring name
Definition: object.h:470
ATNR_COLD
#define ATNR_COLD
Definition: attack.h:53
god_examines_priest
static int god_examines_priest(object *op, const object *god)
Definition: gods.c:1134
FLAG_XRAYS
#define FLAG_XRAYS
Definition: define.h:300
say.item
dictionary item
Definition: say.py:149
GT_UPDATE_INV
@ GT_UPDATE_INV
Definition: treasure.h:35
AP_UNAPPLY
#define AP_UNAPPLY
Definition: define.h:575
obj::attacktype
uint32_t attacktype
Definition: object.h:347
BOOTS
@ BOOTS
Definition: object.h:212
MAX_WEAPON_ITEM_POWER
#define MAX_WEAPON_ITEM_POWER
Definition: define.h:459
give_skill_by_name
object * give_skill_by_name(object *op, const char *skill_name)
Definition: living.c:1779
TRUE
#define TRUE
Definition: compat.h:11
ATNR_ELECTRICITY
#define ATNR_ELECTRICITY
Definition: attack.h:52
AT_HOLYWORD
#define AT_HOLYWORD
Definition: attack.h:97
change_abil
int change_abil(object *op, object *tmp)
Definition: living.c:395
SPELL
@ SPELL
Definition: object.h:214
liv::sp
int16_t sp
Definition: living.h:42
player_unready_range_ob
void player_unready_range_ob(player *pl, object *ob)
Definition: player.c:4421
SHIELD
@ SHIELD
Definition: object.h:135
FLAG_CURSED
#define FLAG_CURSED
Definition: define.h:316
treasurestruct::name
sstring name
Definition: treasure.h:65
living.h
obj::magic
int8_t magic
Definition: object.h:353
obj::resist
int16_t resist[NROFATTACKS]
Definition: object.h:346
if
if(!(yy_init))
Definition: loader.c:2626
SPELLBOOK
@ SPELLBOOK
Definition: object.h:203
MSG_TYPE_ITEM_INFO
#define MSG_TYPE_ITEM_INFO
Definition: newclient.h:645
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
FORCE
@ FORCE
Definition: object.h:224
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:319
object.h
obj::level
int16_t level
Definition: object.h:356
treasureliststruct
Definition: treasure.h:82
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25
give.name
name
Definition: give.py:27
EVENT_APPLY
#define EVENT_APPLY
Definition: events.h:19
object_get_owner
object * object_get_owner(object *op)
Definition: object.c:808
level
Definition: level.py:1