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

Comparing deliantra/server/server/spell_util.C (file contents):
Revision 1.78 by root, Sun Sep 28 15:51:04 2008 UTC vs.
Revision 1.79 by root, Mon Sep 29 06:32:09 2008 UTC

36 */ 36 */
37object * 37object *
38find_random_spell_in_ob (object *ob, const char *skill) 38find_random_spell_in_ob (object *ob, const char *skill)
39{ 39{
40 int k = 0, s; 40 int k = 0, s;
41 object *tmp;
42 41
43 for (tmp = ob->inv; tmp; tmp = tmp->below) 42 for (object *tmp = ob->inv; tmp; tmp = tmp->below)
44 if (tmp->type == SPELL && (!skill || tmp->skill == skill)) 43 if (tmp->type == SPELL && (!skill || tmp->skill == skill))
45 k++; 44 k++;
46 45
47 /* No spells, no need to progess further */ 46 /* No spells, no need to progess further */
48 if (!k) 47 if (!k)
49 return NULL; 48 return NULL;
50 49
51 s = RANDOM () % k; 50 s = RANDOM () % k;
52 51
53 for (tmp = ob->inv; tmp; tmp = tmp->below) 52 for (object *tmp = ob->inv; tmp; tmp = tmp->below)
54 if (tmp->type == SPELL && (!skill || tmp->skill == skill)) 53 if (tmp->type == SPELL && (!skill || tmp->skill == skill))
55 {
56 if (!s) 54 if (!s)
57 return tmp; 55 return tmp;
58 else 56 else
59 s--; 57 s--;
60 } 58
61 /* Should never get here, but just in case */ 59 /* Should never get here, but just in case */
62 return NULL; 60 return 0;
63} 61}
64 62
65/* Relatively simple function that gets used a lot. 63/* Relatively simple function that gets used a lot.
66 * Basically, it sets up the skill pointer for the spell being 64 * Basically, it sets up the skill pointer for the spell being
67 * cast. If op is really casting the spell, then the skill 65 * cast. If op is really casting the spell, then the skill
112 return max (1, new_level); 110 return max (1, new_level);
113} 111}
114 112
115/* This function returns the effective level the spell 113/* This function returns the effective level the spell
116 * is being cast at. 114 * is being cast at.
117 * Note that I changed the repelled/attuned bonus to 2 from 5.
118 * This is because the new code compares casting_level against
119 * min_caster_level, so the difference is effectively 4
120 */ 115 */
121int 116int
122caster_level (object *caster, object *spell) 117casting_level (object *caster, object *spell)
123{ 118{
124 int level = caster->level; 119 int level = caster->level;
125 120
126 /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ 121 /* if a rod is fired by a player, take the use_magic_item skill in consideration. */
127 if (caster->type == ROD && caster->env && caster->env->type == PLAYER) 122 if (caster->type == ROD && caster->env && caster->env->type == PLAYER)
129 object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); 124 object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM);
130 int sk_level = skill ? skill->level : 1; 125 int sk_level = skill ? skill->level : 1;
131 126
132 level = min (level, sk_level + level / 10 + 1); 127 level = min (level, sk_level + level / 10 + 1);
133 } 128 }
134 else if (caster->type == PLAYER && spell->skill) /* If this is a player, try to find the matching skill */ 129 else if (caster->type == PLAYER) /* If this is a player, try to find the matching skill */
135 for (int i = 0; i < NUM_SKILLS; i++) 130 if (object *skill = caster->contr->find_skill (spell->skill))
136 if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) 131 level = skill->level;
137 { 132
138 level = caster->contr->last_skill_ob[i]->level; 133 // now scale the effective level from the startinglevel..100 range to 1..100
139 break; 134 if (level < 100)
140 } 135 level = lerp (level, (int)spell->level, 100, 1, 100);
141 136
142 /* Got valid caster level. Now adjust for attunement */ 137 /* Got valid caster level. Now adjust for attunement */
143 level += caster->path_repelled & spell->path_attuned ? -ATTUNE_REPELL : 0; 138 // attuned only increases up to 2 times the original level */
144 level += caster->path_attuned & spell->path_attuned ? +ATTUNE_REPELL : 0; 139 if (caster->path_attuned & spell->path_attuned)
140 level = min (level * 2, level + ATTUNE_REPELL);
141
142 // repell has no such quarrels
143 if (caster->path_repelled & spell->path_attuned)
144 level -= ATTUNE_REPELL;
145 145
146 /* Always make this at least 1. If this is zero, we get divide by zero 146 /* Always make this at least 1. If this is zero, we get divide by zero
147 * errors in various places. 147 * errors in various places.
148 */ 148 */
149 return max (level, 1); 149 return max (level, 1);
158 * caster is what is casting the spell, can be op. 158 * caster is what is casting the spell, can be op.
159 * spell is the spell object. 159 * spell is the spell object.
160 * Note that it is now possible for a spell to cost both grace and 160 * Note that it is now possible for a spell to cost both grace and
161 * mana. In that case, we return which ever value is higher. 161 * mana. In that case, we return which ever value is higher.
162 */ 162 */
163
164sint16 163sint16
165SP_level_spellpoint_cost (object *caster, object *spell, int flags) 164SP_level_spellpoint_cost (object *caster, object *spell, int flags)
166{ 165{
167 int sp, grace, level = caster_level (caster, spell); 166 int sp, grace, level = casting_level (caster, spell);
168 167
169 if (settings.spellpoint_level_depend == TRUE) 168 if (settings.spellpoint_level_depend == TRUE)
170 { 169 {
171 if (spell->stats.sp && spell->stats.maxsp) 170 if (spell->stats.sp && spell->stats.maxsp)
172 { 171 {
214 } 213 }
215} 214}
216 215
217/* 216/*
218 * Return the effective casting level of the spell. 217 * Return the effective casting level of the spell.
218 * To make spells independent of their starting level, this function
219 * scales the range spellstartlevel .. 100 into the range 1..100
219 */ 220 */
220static int 221static int
221SP_casting_level (object *caster, object *spell) 222SP_casting_level (object *caster, object *spell)
222{ 223{
223 int level = caster_level (caster, spell);
224 return max (0, level - min_casting_level (caster, spell)); 224 return casting_level (caster, spell);
225} 225}
226 226
227/* SP_level_dam_adjust: Returns adjusted damage based on the caster. 227/* SP_level_dam_adjust: Returns adjusted damage based on the caster.
228 * spob is the spell we are adjusting. 228 * spob is the spell we are adjusting.
229 */ 229 */
257SP_level_range_adjust (object *caster, object *spob) 257SP_level_range_adjust (object *caster, object *spob)
258{ 258{
259 if (!spob->range_modifier) 259 if (!spob->range_modifier)
260 return 0; 260 return 0;
261 261
262 int level = caster_level (caster, spob);
263 return SP_casting_level (caster, spob) / spob->range_modifier; 262 return SP_casting_level (caster, spob) / spob->range_modifier;
264} 263}
265 264
266/* Checks to see if player knows the spell. If the name is the same 265/* Checks to see if player knows the spell. If the name is the same
267 * as an existing spell, we presume they know it. 266 * as an existing spell, we presume they know it.
343 * eg, updated for tiled maps. 342 * eg, updated for tiled maps.
344 */ 343 */
345int 344int
346reflwall (maptile *m, int x, int y, object *sp_op) 345reflwall (maptile *m, int x, int y, object *sp_op)
347{ 346{
348 object *op;
349
350 if (OUT_OF_REAL_MAP (m, x, y)) 347 if (OUT_OF_REAL_MAP (m, x, y))
351 return 0; 348 return 0;
349
352 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) 350 for (object *op = GET_MAP_OB (m, x, y); op; op = op->above)
353 if (QUERY_FLAG (op, FLAG_REFL_SPELL) 351 if (QUERY_FLAG (op, FLAG_REFL_SPELL)
354 && (!QUERY_FLAG (op, FLAG_ALIVE) 352 && (!QUERY_FLAG (op, FLAG_ALIVE)
355 || (rndm (0, 99)) < 90 - (sp_op->level / 10))) 353 || (rndm (0, 99)) < 90 - (sp_op->level / 10)))
356 return 1; 354 return 1;
357 355
498 tmp->stats.food = tmp->duration; 496 tmp->stats.food = tmp->duration;
499 tmp->range = spell->range + SP_level_range_adjust (caster, spell); 497 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
500 tmp->attacktype = spell->attacktype; 498 tmp->attacktype = spell->attacktype;
501 tmp->direction = dir; 499 tmp->direction = dir;
502 tmp->set_owner (op); 500 tmp->set_owner (op);
503 tmp->level = caster_level (caster, spell); 501 tmp->level = casting_level (caster, spell);
504 set_spell_skill (op, caster, spell, tmp); 502 set_spell_skill (op, caster, spell, tmp);
505 503
506 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ 504 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */
507 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 505 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
508 if (!tailor_god_spell (tmp, op)) 506 if (!tailor_god_spell (tmp, op))
979 * need to have the right skill pointer passed, so we need to 977 * need to have the right skill pointer passed, so we need to
980 * at least process that code. 978 * at least process that code.
981 */ 979 */
982 if (op->type == PLAYER && op == caster) 980 if (op->type == PLAYER && op == caster)
983 { 981 {
984 cast_level = caster_level (caster, spell_ob);
985
986 if (spell_ob->skill) 982 if (spell_ob->skill)
987 { 983 {
988 skill = find_skill_by_name (op, spell_ob->skill); 984 skill = find_skill_by_name (op, spell_ob->skill);
989 985
990 if (!skill) 986 if (!skill)
991 { 987 {
992 op->failmsg (format ("You need the skill %s to cast %s! " 988 op->failmsg (format ("You need the skill %s to cast %s! "
993 "H<You either need to learn the skill via a skill scroll " 989 "H<You either need to learn the skill via a skill scroll "
994 "or you need to wear a talisman or holy symbol.>", 990 "or you need to wear a talisman or holy symbol.>",
995 &spell_ob->skill, &spell_ob->name)); 991 &spell_ob->skill, &spell_ob->name));
996 return 0; 992 return 0;
997 } 993 }
998 994
995 const char *msg = "";
996
997 int caster_level = skill->level;
998
999 if (op->path_attuned & spell_ob->path_attuned)
1000 {
1001 caster_level += ATTUNE_REPELL;
1002 msg = " (attuned)";
1003 }
1004
1005 if (op->path_repelled & spell_ob->path_attuned)
1006 {
1007 caster_level = ATTUNE_REPELL; // negative is ok
1008 msg = " (repelled)";
1009 }
1010
999 int casting_level = min_casting_level (op, spell_ob); 1011 int casting_level = min_casting_level (op, spell_ob);
1000 1012
1001 if (casting_level > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) 1013 if (casting_level > caster_level)
1002 { 1014 {
1003 op->failmsg (format ("You lack enough skill to cast that spell! " 1015 op->failmsg (format ("You lack enough skill to cast that spell! "
1004 "H<Your cast level is %d, but level %d is required. Maybe you are repelled?>", 1016 "H<Your effective cast level is %d%s, but level %d is required.>",
1005 cast_level, casting_level)); 1017 caster_level, msg, casting_level));
1018 if (!op->is_wiz ())
1006 return 0; 1019 return 0;
1007 } 1020 }
1008 } 1021 }
1009 1022
1010 /* If the caster is the wiz, they don't ever fail, and don't have 1023 /* If the caster is the wiz, they don't ever fail, and don't have
1011 * to have sufficient grace/mana. 1024 * to have sufficient grace/mana.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines