ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/gods.C
(Generate patch)

Comparing deliantra/server/server/gods.C (file contents):
Revision 1.40 by root, Mon Sep 29 10:32:50 2008 UTC vs.
Revision 1.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
449 follower_remove_similar_item (op, tr->item); 423 follower_remove_similar_item (op, tr->item);
450 424
451 if (!op || !new_god) 425 if (!op || !new_god)
452 return; 426 return;
453 427
454 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))
455 { 429 {
456 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);
457 431
458 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)
459 { 433 {
646 CLEAR_FLAG (exp_ob, flag); 620 CLEAR_FLAG (exp_ob, flag);
647 }; 621 };
648} 622}
649 623
650archetype * 624archetype *
651determine_holy_arch (object *god, const char *type) 625determine_holy_arch (object *god, shstr_cmp type)
652{ 626{
653 treasure *tr; 627 treasure *tr;
654 628
655 if (!god || !god->randomitems) 629 if (!god || !god->randomitems)
656 { 630 {
663 if (!tr->item) 637 if (!tr->item)
664 continue; 638 continue;
665 639
666 object *item = tr->item; 640 object *item = tr->item;
667 641
668 if (item->type == BOOK && item->invisible && strcmp (item->name, type) == 0) 642 if (item->type == BOOK && item->invisible && item->name == type)
669 return item->other_arch; 643 return item->other_arch;
670 } 644 }
671 645
672 return 0; 646 return 0;
673} 647}
839 continue; 813 continue;
840 814
841 item = tr->item; 815 item = tr->item;
842 816
843 /* Grace limit */ 817 /* Grace limit */
844 if (item->type == BOOK && item->invisible && strcmp (item->name, "grace limit") == 0) 818 if (item->type == BOOK && item->invisible && item->name == shstr_grace_limit)
845 { 819 {
846 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)
847 { 821 {
848 object *tmp;
849
850 /* Follower lacks the required grace for the following 822 /* Follower lacks the required grace for the following
851 * treasure list items. */ 823 * treasure list items. */
852 824
853 tmp = get_archetype (HOLY_POSSESSION); 825 object *tmp = get_archetype (HOLY_POSSESSION);
854 cast_change_ability (op, op, tmp, 0, 1); 826 cast_change_ability (op, op, tmp, 0, 1);
855 tmp->destroy (); 827 tmp->destroy ();
856 return; 828 return;
857 } 829 }
858 830
859 continue; 831 continue;
860 } 832 }
861 833
862 /* Restore grace */ 834 /* Restore grace */
863 if (item->type == BOOK && item->invisible && strcmp (item->name, "restore grace") == 0) 835 if (item->type == BOOK && item->invisible && item->name == shstr_restore_grace)
864 { 836 {
865 if (op->stats.grace >= 0) 837 if (op->stats.grace >= 0)
866 continue; 838 continue;
839
867 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH); 840 op->stats.grace = random_roll (0, 9, op, PREFER_HIGH);
868 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace."); 841 new_draw_info (NDI_UNIQUE, 0, op, "You are returned to a state of grace.");
869 return; 842 return;
870 } 843 }
871 844
872 /* Heal damage */ 845 /* Heal damage */
873 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)
874 { 847 {
875 if (op->stats.hp >= op->stats.maxhp) 848 if (op->stats.hp >= op->stats.maxhp)
876 continue; 849 continue;
850
877 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!");
878 op->stats.hp = op->stats.maxhp; 852 op->stats.hp = op->stats.maxhp;
879 return; 853 return;
880 } 854 }
881 855
935 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 909 if ((at = archetype::find (ARCH_DEPLETION)) == NULL)
936 { 910 {
937 LOG (llevError, "Could not find archetype depletion.\n"); 911 LOG (llevError, "Could not find archetype depletion.\n");
938 continue; 912 continue;
939 } 913 }
914
940 depl = present_arch_in_ob (at, op); 915 depl = present_arch_in_ob (at, op);
941 916
942 if (depl == NULL) 917 if (depl == NULL)
943 continue; 918 continue;
944 919
1052 * God checks item the player is using. 1027 * God checks item the player is using.
1053 * Return either -1 (bad), 0 (neutral) or 1028 * Return either -1 (bad), 0 (neutral) or
1054 * 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
1055 * god, it can be bad...-b.t. 1030 * god, it can be bad...-b.t.
1056 */ 1031 */
1057
1058int 1032int
1059god_examines_item (object *god, object *item) 1033god_examines_item (object *god, object *item)
1060{ 1034{
1061 char buf[MAX_BUF]; 1035 char buf[MAX_BUF];
1062 1036
1065 1039
1066 if (!item->title) 1040 if (!item->title)
1067 return 1; /* unclaimed item are ok */ 1041 return 1; /* unclaimed item are ok */
1068 1042
1069 sprintf (buf, "of %s", &god->name); 1043 sprintf (buf, "of %s", &god->name);
1070 if (!strcmp (item->title, buf)) 1044 if (!strcmp (&item->title, buf))
1071 return 1; /* belongs to that God */ 1045 return 1; /* belongs to that God */
1072 1046
1073 if (god->title) 1047 if (god->title)
1074 { /* check if we have any enemy blessed item */ 1048 { /* check if we have any enemy blessed item */
1075 sprintf (buf, "of %s", &god->title); 1049 sprintf (buf, "of %s", &god->title);
1076 if (!strcmp (item->title, buf)) 1050 if (!strcmp (&item->title, buf))
1077 { 1051 {
1078 if (item->env) 1052 if (item->env)
1079 { 1053 {
1080 char buf[MAX_BUF]; 1054 char buf[MAX_BUF];
1081 1055
1082 sprintf (buf, "Heretic! You are using %s!", query_name (item)); 1056 sprintf (buf, "Heretic! You are using %s!", query_name (item));
1083 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf); 1057 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, item->env, buf);
1084 } 1058 }
1059
1085 return -1; 1060 return -1;
1086 } 1061 }
1087 } 1062 }
1088 1063
1089 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 */
1091 1066
1092/** 1067/**
1093 * Returns priest's god's id. 1068 * Returns priest's god's id.
1094 * Straight calls lookup_god_by_name 1069 * Straight calls lookup_god_by_name
1095 */ 1070 */
1096
1097int 1071int
1098get_god (object *priest) 1072get_god (object *priest)
1099{ 1073{
1100 int godnr = lookup_god_by_name (determine_god (priest)); 1074 return lookup_god_by_name (determine_god (priest));
1101
1102 return godnr;
1103}
1104
1105/**
1106 * Returns a string that is the name of the god that should be natively worshipped by a
1107 * creature of who has race *race
1108 * if we can't find a god that is appropriate, we return NULL
1109 */
1110const char *
1111get_god_for_race (const char *race)
1112{
1113 godlink *gl = first_god;
1114 const char *godname = NULL;
1115
1116 if (race == NULL)
1117 return NULL;
1118 while (gl)
1119 {
1120 if (!strcasecmp (gl->arch->race, race))
1121 {
1122 godname = gl->name;
1123 break;
1124 }
1125 gl = gl->next;
1126 }
1127 return godname;
1128} 1075}
1129 1076
1130/** 1077/**
1131 * 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.
1132 * 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