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.37 by root, Sat Sep 6 06:40:19 2008 UTC vs.
Revision 1.45 by root, Thu Jan 1 16:05:13 2009 UTC

36 36
37/** 37/**
38 * Returns the id of specified god. 38 * Returns the id of specified god.
39 */ 39 */
40int 40int
41lookup_god_by_name (const char *name) 41lookup_god_by_name (shstr_cmp name)
42{ 42{
43 int godnr = -1; 43 if (name)
44 size_t nmlen = strlen (name);
45
46 if (name && strcmp (name, "none"))
47 {
48 godlink *gl;
49
50 for (gl = first_god; gl; gl = gl->next) 44 for (godlink *gl = first_god; gl; gl = gl->next)
51 if (!strncmp (name, gl->name, MIN ((size_t) strlen (gl->name), nmlen))) 45 if (gl->name == name)
52 break;
53
54 if (gl)
55 godnr = gl->id; 46 return gl->id;
56 }
57 47
58 return godnr; 48 return -1;
59} 49}
60 50
61/** 51/**
62 * Returns pointer to specified god's object through pntr_to_god_obj.. 52 * Returns pointer to specified god's object through pntr_to_god_obj..
63 */ 53 */
64object * 54object *
65find_god (const char *name) 55find_god (shstr_cmp name)
66{ 56{
67 object *god = NULL;
68
69 if (name) 57 if (name)
70 {
71 godlink *gl;
72
73 for (gl = first_god; gl; gl = gl->next) 58 for (godlink *gl = first_god; gl; gl = gl->next)
74 if (!strcmp (name, gl->name)) 59 if (gl->name == name)
75 break;
76 if (gl)
77 god = pntr_to_god_obj (gl); 60 return pntr_to_god_obj (gl);
78 } 61
79 return god; 62 return 0;
63}
64
65/**
66 * Returns a string that is the name of the god that should be natively worshipped by a
67 * creature of who has race *race
68 * if we can't find a god that is appropriate, we return NULL
69 */
70static shstr_tmp
71get_god_for_race (shstr_cmp race)
72{
73 if (race)
74 for (godlink *gl = first_god; gl; gl = gl->next)
75 if (gl->arch->race == race)
76 return gl->name;
77
78 return shstr_tmp ();
80} 79}
81 80
82/** 81/**
83 * Determines if op worships a god. 82 * Determines if op worships a god.
84 * Returns the godname if they do or "none" if they have no god. 83 * Returns the godname if they do or "none" if they have no god.
85 * In the case of an NPC, if they have no god, we try and guess 84 * In the case of an NPC, if they have no god, we try and guess
86 * who they should worship based on their race. If that fails we 85 * who they should worship based on their race. If that fails we
87 * give them a random one. 86 * give them a random one.
88 */ 87 */
89 88shstr_tmp
90const char *
91determine_god (object *op) 89determine_god (object *op)
92{ 90{
93 int godnr = -1;
94 const char *godname;
95
96 /* spells */ 91 /* spells */
97 if ((op->type == SPELL || op->type == SPELL_EFFECT) && op->title) 92 if ((op->type == SPELL || op->type == SPELL_EFFECT) && op->title)
98 {
99 if (lookup_god_by_name (op->title) >= 0) 93 if (lookup_god_by_name (op->title) >= 0)
100 return op->title; 94 return op->title;
95
96 if (!op->is_player () && op->flag [FLAG_ALIVE])
101 } 97 {
102
103 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_ALIVE))
104 {
105
106 /* find a god based on race */ 98 /* find a god based on race */
107 if (!op->title) 99 if (!op->title)
108 {
109 if (op->race)
110 {
111 godname = get_god_for_race (op->race); 100 op->title = get_god_for_race (op->race);
112
113 if (godname)
114 op->title = godname;
115 }
116 }
117 101
118 /* find a random god */ 102 /* find a random god */
119 if (!op->title) 103 if (!op->title)
120 { 104 {
121 godlink *gl = first_god;
122
123 godnr = rndm (1, gl->id); 105 int godnr = rndm (1, first_god->id);
124 while (gl) 106
125 { 107 for (godlink *gl = first_god; gl && gl->id != godnr; gl = gl->next)
126 if (gl->id == godnr) 108 if (gl->id == godnr)
109 {
110 op->title = gl->name;
127 break; 111 break;
128
129 gl = gl->next;
130 } 112 }
131
132 op->title = gl->name;
133 } 113 }
134 114
135 return op->title; 115 return op->title;
136 } 116 }
137
138 117
139 /* The god the player worships is in the praying skill (native skill 118 /* The god the player worships is in the praying skill (native skill
140 * not skill tool). Since a player can only have one instance of 119 * not skill tool). Since a player can only have one instance of
141 * that skill, once we find it, we can return, either with the 120 * that skill, once we find it, we can return, either with the
142 * title or "none". 121 * title or "none".
143 */ 122 */
144 if (op->type == PLAYER) 123 if (op->type == PLAYER)
145 {
146 for (object *tmp = op->inv; tmp; tmp = tmp->below) 124 for (object *tmp = op->inv; tmp; tmp = tmp->below)
147 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING) 125 if (tmp->type == SKILL && tmp->subtype == SK_PRAYING)
148 { 126 {
149 if (tmp->title) 127 if (tmp->title)
150 return tmp->title; 128 return tmp->title;
151 else 129
152 return "none"; 130 break;
153 } 131 }
154 }
155 132
156 return "none"; 133 return shstr_none;
157} 134}
158 135
159/** 136/**
160 * Returns 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0 137 * Returns 1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0
161 */ 138 */
162static int 139static int
163same_string (const char *s1, const char *s2) 140same_string (const char *s1, const char *s2)
164{ 141{
165 if (s1 == NULL) 142 if (s1 == s2)
166 if (s2 == NULL)
167 return 1; 143 return 1;
144 else if (s1 && s2)
145 return !strcmp (s1, s2);
168 else 146 else
169 return 0;
170 else if (s2 == NULL)
171 return 0; 147 return 0;
172 else
173 return strcmp (s1, s2) == 0;
174} 148}
175 149
176/** 150/**
177 * Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively). 151 * Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively).
178 * Any matching items in the inventory are deleted, and a 152 * Any matching items in the inventory are deleted, and a
192 166
193 if (tmp->type == item->type 167 if (tmp->type == item->type
194 && same_string (tmp->name, item->name) 168 && same_string (tmp->name, item->name)
195 && same_string (tmp->title, item->title) && same_string (tmp->msg, item->msg) && same_string (tmp->slaying, item->slaying)) 169 && same_string (tmp->title, item->title) && same_string (tmp->msg, item->msg) && same_string (tmp->slaying, item->slaying))
196 { 170 {
197
198 /* message */ 171 /* message */
199 if (tmp->nrof > 1) 172 new_draw_info_format (NDI_UNIQUE, 0, op,
200 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumble to dust!", query_short_name (tmp)); 173 tmp->nrof > 1 ? "The %s crumble to dust!" : "The %s crumbles to dust!",
201 else 174 query_short_name (tmp));
202 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s crumbles to dust!", query_short_name (tmp));
203 175
204 tmp->destroy (); 176 tmp->destroy ();
205 } 177 }
206 178
207 if (tmp->inv) 179 if (tmp->inv)
451 follower_remove_similar_item (op, tr->item); 423 follower_remove_similar_item (op, tr->item);
452 424
453 if (!op || !new_god) 425 if (!op || !new_god)
454 return; 426 return;
455 427
456 if (op->race && new_god->slaying && strstr (op->race, new_god->slaying)) 428 if (op->race && new_god->slaying && op->race.contains (new_god->slaying))
457 { 429 {
458 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name); 430 new_draw_info_format (NDI_UNIQUE | NDI_NAVY, 0, op, "Fool! %s detests your kind!", &new_god->name);
459 431
460 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0) 432 if (random_roll (0, op->level - 1, op, PREFER_LOW) - 5 > 0)
461 { 433 {
481 if (skop->type == SKILL && skop->subtype == SK_PRAYING) 453 if (skop->type == SKILL && skop->subtype == SK_PRAYING)
482 break; 454 break;
483 455
484 /* Player has no skill - give them the skill */ 456 /* Player has no skill - give them the skill */
485 if (!skop) 457 if (!skop)
486 {
487 /* The archetype should always be defined - if we crash here because it doesn't, 458 /* The archetype should always be defined - if we crash here because it doesn't,
488 * things are really messed up anyways. 459 * things are really messed up anyways.
489 */ 460 */
490 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill); 461 skop = give_skill_by_name (op, get_archetype_by_type_subtype (SKILL, SK_PRAYING)->skill);
491 link_player_skills (op);
492 }
493 462
494 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */ 463 sk_applied = QUERY_FLAG (skop, FLAG_APPLIED); /* save skill status */
495 464
496 /* Clear the "undead" status. We also need to force a call to change_abil, 465 /* Clear the "undead" status. We also need to force a call to change_abil,
497 * so I set undeadified for that. 466 * so I set undeadified for that.
498 * - gros, 21th July 2006. 467 * - gros, 21th July 2006.
499 */ 468 */
500 if ((old_god) && (QUERY_FLAG (old_god, FLAG_UNDEAD))) 469 if (old_god && QUERY_FLAG (old_god, FLAG_UNDEAD))
501 { 470 {
502 CLEAR_FLAG (skop, FLAG_UNDEAD); 471 CLEAR_FLAG (skop, FLAG_UNDEAD);
503 undeadified = 1; 472 undeadified = 1;
504 } 473 }
505 474
651 CLEAR_FLAG (exp_ob, flag); 620 CLEAR_FLAG (exp_ob, flag);
652 }; 621 };
653} 622}
654 623
655archetype * 624archetype *
656determine_holy_arch (object *god, const char *type) 625determine_holy_arch (object *god, shstr_cmp type)
657{ 626{
658 treasure *tr; 627 treasure *tr;
659 628
660 if (!god || !god->randomitems) 629 if (!god || !god->randomitems)
661 { 630 {
668 if (!tr->item) 637 if (!tr->item)
669 continue; 638 continue;
670 639
671 object *item = tr->item; 640 object *item = tr->item;
672 641
673 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 642 if (item->type == BOOK && item->invisible && item->name == type)
674 return item->other_arch; 643 return item->other_arch;
675 } 644 }
676 645
677 return 0; 646 return 0;
678} 647}
844 continue; 813 continue;
845 814
846 item = tr->item; 815 item = tr->item;
847 816
848 /* Grace limit */ 817 /* Grace limit */
849 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0) 818 if (item->type == BOOK && item->invisible && item->name == shstr_grace_limit)
850 { 819 {
851 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace) 820 if (op->stats.grace < item->stats.grace || op->stats.grace < op->stats.maxgrace)
852 { 821 {
853 object *tmp;
854
855 /* Follower lacks the required grace for the following 822 /* Follower lacks the required grace for the following
856 * treasure list items. */ 823 * treasure list items. */
857 824
858 tmp = get_archetype (HOLY_POSSESSION); 825 object *tmp = get_archetype (HOLY_POSSESSION);
859 cast_change_ability (op, op, tmp, 0, 1); 826 cast_change_ability (op, op, tmp, 0, 1);
860 tmp->destroy (); 827 tmp->destroy ();
861 return; 828 return;
862 } 829 }
863 830
864 continue; 831 continue;
865 } 832 }
866 833
867 /* Restore grace */ 834 /* Restore grace */
868 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0) 835 if (item->type == BOOK && item->invisible && item->name == shstr_restore_grace)
869 { 836 {
870 if (op->stats.grace >= 0) 837 if (op->stats.grace >= 0)
871 continue; 838 continue;
839
872 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH); 840 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH);
873 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace."); 841 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace.");
874 return; 842 return;
875 } 843 }
876 844
877 /* Heal damage */ 845 /* Heal damage */
878 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore hitpoints") == 0) 846 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore hitpoints") == 0)
879 { 847 {
880 if (op->stats.hp >= op->stats.maxhp) 848 if (op->stats.hp >= op->stats.maxhp)
881 continue; 849 continue;
850
882 new_draw_info (NDI_UNIQUE, 0, op, "A white light surrounds and heals you!"); 851 new_draw_info (NDI_UNIQUE, 0, op, "A white light surrounds and heals you!");
883 op->stats.hp = op->stats.maxhp; 852 op->stats.hp = op->stats.maxhp;
884 return; 853 return;
885 } 854 }
886 855
940 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 909 if ((at = archetype::find (ARCH_DEPLETION)) == NULL)
941 { 910 {
942 LOG (llevError, "Could not find archetype depletion.\n"); 911 LOG (llevError, "Could not find archetype depletion.\n");
943 continue; 912 continue;
944 } 913 }
914
945 depl = present_arch_in_ob (at, op); 915 depl = present_arch_in_ob (at, op);
946 916
947 if (depl == NULL) 917 if (depl == NULL)
948 continue; 918 continue;
949 919
1057 * God checks item the player is using. 1027 * God checks item the player is using.
1058 * Return either -1 (bad), 0 (neutral) or 1028 * Return either -1 (bad), 0 (neutral) or
1059 * 1 (item is ok). If you are using the item of an enemy 1029 * 1 (item is ok). If you are using the item of an enemy
1060 * god, it can be bad...-b.t. 1030 * god, it can be bad...-b.t.
1061 */ 1031 */
1062
1063int 1032int
1064god_examines_item (object *god, object *item) 1033god_examines_item (object *god, object *item)
1065{ 1034{
1066 char buf[MAX_BUF]; 1035 char buf[MAX_BUF];
1067 1036
1070 1039
1071 if (!item->title) 1040 if (!item->title)
1072 return 1; /* unclaimed item are ok */ 1041 return 1; /* unclaimed item are ok */
1073 1042
1074 sprintf (buf, "of %s", &god->name); 1043 sprintf (buf, "of %s", &god->name);
1075 if (!strcmp (item->title, buf)) 1044 if (!strcmp (&item->title, buf))
1076 return 1; /* belongs to that God */ 1045 return 1; /* belongs to that God */
1077 1046
1078 if (god->title) 1047 if (god->title)
1079 { /* check if we have any enemy blessed item */ 1048 { /* check if we have any enemy blessed item */
1080 sprintf (buf, "of %s", &god->title); 1049 sprintf (buf, "of %s", &god->title);
1081 if (!strcmp (item->title, buf)) 1050 if (!strcmp (&item->title, buf))
1082 { 1051 {
1083 if (item->env) 1052 if (item->env)
1084 { 1053 {
1085 char buf[MAX_BUF]; 1054 char buf[MAX_BUF];
1086 1055
1087 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1056 sprintf (buf, "Heretic! You are using %s!", query_name (item));
1088 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf); 1057 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf);
1089 } 1058 }
1059
1090 return -1; 1060 return -1;
1091 } 1061 }
1092 } 1062 }
1093 1063
1094 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */ 1064 return 0; /* item is sacred to a non-enemy god/or is otherwise magical */
1096 1066
1097/** 1067/**
1098 * Returns priest's god's id. 1068 * Returns priest's god's id.
1099 * Straight calls lookup_god_by_name 1069 * Straight calls lookup_god_by_name
1100 */ 1070 */
1101
1102int 1071int
1103get_god (object *priest) 1072get_god (object *priest)
1104{ 1073{
1105 int godnr = lookup_god_by_name (determine_god (priest)); 1074 return lookup_god_by_name (determine_god (priest));
1106
1107 return godnr;
1108}
1109
1110/**
1111 * Returns a string that is the name of the god that should be natively worshipped by a
1112 * creature of who has race *race
1113 * if we can't find a god that is appropriate, we return NULL
1114 */
1115const char *
1116get_god_for_race (const char *race)
1117{
1118 godlink *gl = first_god;
1119 const char *godname = NULL;
1120
1121 if (race == NULL)
1122 return NULL;
1123 while (gl)
1124 {
1125 if (!strcasecmp (gl->arch->race, race))
1126 {
1127 godname = gl->name;
1128 break;
1129 }
1130 gl = gl->next;
1131 }
1132 return godname;
1133} 1075}
1134 1076
1135/** 1077/**
1136 * Changes the attributes of cone, smite, and ball spells as needed by the code. 1078 * Changes the attributes of cone, smite, and ball spells as needed by the code.
1137 * Returns false if there was no race to assign to the slaying field of the spell, but 1079 * Returns false if there was no race to assign to the slaying field of the spell, but

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines