… | |
… | |
85 | { |
85 | { |
86 | if (spob->other_arch) |
86 | if (spob->other_arch) |
87 | map->insert (arch_to_object (spob->other_arch), x, y, originator); |
87 | map->insert (arch_to_object (spob->other_arch), x, y, originator); |
88 | } |
88 | } |
89 | |
89 | |
|
|
90 | static int |
|
|
91 | attuned_bonus (object *caster, object *spell, int level) |
|
|
92 | { |
|
|
93 | // compute the attuned/repelled bonus |
|
|
94 | // attuned only increases up to 2 times the original level (i.e. bonus <= level) */ |
|
|
95 | // repell has no such quarrels |
|
|
96 | return (caster->path_attuned & spell->path_attuned ? min (level, +ATTUNE_REPELL) : 0) |
|
|
97 | + (caster->path_repelled & spell->path_attuned ? -ATTUNE_REPELL : 0); |
|
|
98 | } |
|
|
99 | |
90 | /* |
100 | /* |
91 | * This function takes a caster and spell and presents the |
101 | * This function takes a caster and spell and presents the |
92 | * effective level the caster needs to be to cast the spell. |
102 | * effective level the caster needs to be to cast the spell. |
93 | * basically, it just adjusts the spell->level with attuned/repelled |
103 | * basically, it just adjusts the spell->level with attuned/repelled |
94 | * spellpaths. Was called path_level_mod. |
104 | * spellpaths. Was called path_level_mod. |
… | |
… | |
99 | */ |
109 | */ |
100 | int |
110 | int |
101 | min_casting_level (object *caster, object *spell) |
111 | min_casting_level (object *caster, object *spell) |
102 | { |
112 | { |
103 | if (caster->path_denied & spell->path_attuned) |
113 | if (caster->path_denied & spell->path_attuned) |
104 | return 1; |
114 | return 500; |
105 | |
115 | |
106 | int new_level = spell->level |
116 | return max (1, spell->level + attuned_bonus (caster, spell, spell->level)); |
107 | + (caster->path_repelled & spell->path_attuned ? +ATTUNE_REPELL : 0) |
|
|
108 | + (caster->path_attuned & spell->path_attuned ? -ATTUNE_REPELL : 0); |
|
|
109 | |
|
|
110 | return max (1, new_level); |
|
|
111 | } |
117 | } |
112 | |
118 | |
113 | /* This function returns the effective level the spell |
119 | /* This function returns the effective level the spell |
114 | * is being cast at. |
120 | * is being cast at. |
115 | */ |
121 | */ |
… | |
… | |
128 | } |
134 | } |
129 | else if (caster->type == PLAYER) /* If this is a player, try to find the matching skill */ |
135 | else if (caster->type == PLAYER) /* If this is a player, try to find the matching skill */ |
130 | if (object *skill = caster->contr->find_skill (spell->skill)) |
136 | if (object *skill = caster->contr->find_skill (spell->skill)) |
131 | level = skill->level; |
137 | level = skill->level; |
132 | |
138 | |
|
|
139 | int bonus = attuned_bonus (caster, spell, level); |
|
|
140 | |
|
|
141 | level += bonus; |
|
|
142 | |
133 | // now scale the effective level from the startinglevel..100 range to 1..100 |
143 | // now scale the effective level from the startinglevel..100 range to 1..100 |
134 | if (level < 100) |
144 | if (level < 100) |
135 | level = lerp (level, (int)spell->level, 100, 1, 100); |
145 | level = lerp (level, (int)spell->level, 100, 1, 100); |
136 | |
|
|
137 | /* Got valid caster level. Now adjust for attunement */ |
|
|
138 | // attuned only increases up to 2 times the original level */ |
|
|
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 | |
146 | |
146 | /* Always make this at least 1. If this is zero, we get divide by zero |
147 | /* Always make this at least 1. If this is zero, we get divide by zero |
147 | * errors in various places. |
148 | * errors in various places. |
148 | */ |
149 | */ |
149 | return max (level, 1); |
150 | return max (level, 1); |
… | |
… | |
277 | return spop; |
278 | return spop; |
278 | |
279 | |
279 | return 0; |
280 | return 0; |
280 | } |
281 | } |
281 | |
282 | |
282 | |
|
|
283 | /* |
283 | /* |
284 | * Look at object 'op' and see if they know the spell |
284 | * Look at object 'op' and see if they know the spell |
285 | * spname. This is pretty close to check_spell_known |
285 | * spname. This is pretty close to check_spell_known |
286 | * above, but it uses a looser matching mechanism. |
286 | * above, but it uses a looser matching mechanism. |
287 | * returns the matching spell object, or NULL. |
287 | * returns the matching spell object, or NULL. |
288 | * If we match multiple spells but don't get an |
288 | * If we match multiple spells but don't get an |
289 | * exact match, we also return NULL. |
289 | * exact match, we also return NULL. |
290 | */ |
290 | */ |
291 | |
|
|
292 | object * |
291 | object * |
293 | lookup_spell_by_name (object *op, const char *spname) |
292 | lookup_spell_by_name (object *op, const char *spname) |
294 | { |
293 | { |
295 | object *spob1 = NULL, *spob2 = NULL, *spob; |
294 | object *spob1 = NULL, *spob2 = NULL, *spob; |
296 | int nummatch = 0; |
295 | int nummatch = 0; |
… | |
… | |
996 | |
995 | |
997 | int caster_level = skill->level; |
996 | int caster_level = skill->level; |
998 | |
997 | |
999 | if (op->path_attuned & spell_ob->path_attuned) |
998 | if (op->path_attuned & spell_ob->path_attuned) |
1000 | { |
999 | { |
1001 | caster_level += ATTUNE_REPELL; |
1000 | caster_level += min (cast_level * 2, ATTUNE_REPELL); |
1002 | msg = " (attuned)"; |
1001 | msg = " (attuned)"; |
1003 | } |
1002 | } |
1004 | |
1003 | |
1005 | if (op->path_repelled & spell_ob->path_attuned) |
1004 | if (op->path_repelled & spell_ob->path_attuned) |
1006 | { |
1005 | { |
1007 | caster_level = ATTUNE_REPELL; // negative is ok |
1006 | caster_level = ATTUNE_REPELL; // negative is ok |
1008 | msg = " (repelled)"; |
1007 | msg = " (repelled)"; |
1009 | } |
1008 | } |
1010 | |
1009 | |
1011 | int casting_level = min_casting_level (op, spell_ob); |
|
|
1012 | |
|
|
1013 | if (casting_level > caster_level) |
1010 | if (spell_ob->level > caster_level) |
1014 | { |
1011 | { |
1015 | op->failmsg (format ("You lack enough skill to cast that spell! " |
1012 | op->failmsg (format ("You lack enough skill to cast that spell! " |
1016 | "H<Your effective cast level is %d%s, but level %d is required.>", |
1013 | "H<Your effective cast level is %d%s, but level %d is required.>", |
1017 | caster_level, msg, casting_level)); |
1014 | caster_level, msg, spell_ob->level)); |
1018 | if (!op->is_wiz ()) |
1015 | if (!op->is_wiz ()) |
1019 | return 0; |
1016 | return 0; |
1020 | } |
1017 | } |
1021 | } |
1018 | } |
1022 | |
1019 | |