… | |
… | |
183 | min_casting_level (object *caster, object *spell) |
183 | min_casting_level (object *caster, object *spell) |
184 | { |
184 | { |
185 | int new_level; |
185 | int new_level; |
186 | |
186 | |
187 | if (caster->path_denied & spell->path_attuned) |
187 | if (caster->path_denied & spell->path_attuned) |
188 | { |
|
|
189 | /* This case is not a bug, just the fact that this function is |
|
|
190 | * usually called BEFORE checking for path_deny. -AV |
|
|
191 | */ |
|
|
192 | #if 0 |
|
|
193 | LOG (llevError, "BUG: path_level_mod (arch %s, name %s): casting denied " "spell\n", caster->arch->name, caster->name); |
|
|
194 | #endif |
|
|
195 | return 1; |
188 | return 1; |
196 | } |
189 | |
197 | new_level = spell->level |
190 | new_level = spell->level |
198 | + ((caster->path_repelled & spell->path_attuned) ? +2 : 0) + ((caster->path_attuned & spell->path_attuned) ? -2 : 0); |
191 | + ((caster->path_repelled & spell->path_attuned) ? +2 : 0) + ((caster->path_attuned & spell->path_attuned) ? -2 : 0); |
|
|
192 | |
199 | return (new_level < 1) ? 1 : new_level; |
193 | return (new_level < 1) ? 1 : new_level; |
200 | } |
194 | } |
201 | |
195 | |
202 | |
196 | |
203 | /* This function returns the effective level the spell |
197 | /* This function returns the effective level the spell |
… | |
… | |
212 | { |
206 | { |
213 | int level = caster->level; |
207 | int level = caster->level; |
214 | |
208 | |
215 | /* If this is a player, try to find the matching skill */ |
209 | /* If this is a player, try to find the matching skill */ |
216 | if (caster->type == PLAYER && spell->skill) |
210 | if (caster->type == PLAYER && spell->skill) |
217 | { |
|
|
218 | int i; |
|
|
219 | |
|
|
220 | for (i = 0; i < NUM_SKILLS; i++) |
211 | for (int i = 0; i < NUM_SKILLS; i++) |
221 | if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) |
212 | if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) |
222 | { |
213 | { |
223 | level = caster->contr->last_skill_ob[i]->level; |
214 | level = caster->contr->last_skill_ob[i]->level; |
224 | break; |
215 | break; |
225 | } |
216 | } |
226 | } |
|
|
227 | |
217 | |
228 | /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ |
218 | /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ |
229 | if (caster->type == ROD && caster->env && caster->env->type == PLAYER) |
219 | if (caster->type == ROD && caster->env && caster->env->type == PLAYER) |
230 | { |
220 | { |
231 | object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); |
221 | object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); |
… | |
… | |
240 | /* Always make this at least 1. If this is zero, we get divide by zero |
230 | /* Always make this at least 1. If this is zero, we get divide by zero |
241 | * errors in various places. |
231 | * errors in various places. |
242 | */ |
232 | */ |
243 | if (level < 1) |
233 | if (level < 1) |
244 | level = 1; |
234 | level = 1; |
|
|
235 | |
245 | return level; |
236 | return level; |
246 | } |
237 | } |
247 | |
238 | |
248 | /* The following function scales the spellpoint cost of |
239 | /* The following function scales the spellpoint cost of |
249 | * a spell by it's increased effectiveness. Some of the |
240 | * a spell by it's increased effectiveness. Some of the |
… | |
… | |
450 | { |
441 | { |
451 | object *op; |
442 | object *op; |
452 | |
443 | |
453 | if (OUT_OF_REAL_MAP (m, x, y)) |
444 | if (OUT_OF_REAL_MAP (m, x, y)) |
454 | return 0; |
445 | return 0; |
455 | for (op = get_map_ob (m, x, y); op != NULL; op = op->above) |
446 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
456 | if (QUERY_FLAG (op, FLAG_REFL_SPELL) && (!QUERY_FLAG (op, FLAG_ALIVE) || |
447 | if (QUERY_FLAG (op, FLAG_REFL_SPELL) |
457 | sp_op->type == LIGHTNING || (rndm (0, 99)) < 90 - (sp_op->level / 10))) |
448 | && (!QUERY_FLAG (op, FLAG_ALIVE) |
|
|
449 | || sp_op->type == LIGHTNING // XXX: elmex: why is LIGHTNING special cased here? |
|
|
450 | // most spells use subtypes for bolts today... |
|
|
451 | || (rndm (0, 99)) < 90 - (sp_op->level / 10))) |
458 | return 1; |
452 | return 1; |
459 | |
453 | |
460 | return 0; |
454 | return 0; |
461 | } |
455 | } |
462 | |
456 | |
… | |
… | |
513 | return 0; |
507 | return 0; |
514 | |
508 | |
515 | if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (mp, x, y))) |
509 | if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (mp, x, y))) |
516 | return 0; |
510 | return 0; |
517 | |
511 | |
518 | for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) |
512 | for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above) |
519 | { |
513 | { |
520 | /* If there is a counterspell on the space, and this |
514 | /* If there is a counterspell on the space, and this |
521 | * object is using magic, don't progress. I believe we could |
515 | * object is using magic, don't progress. I believe we could |
522 | * leave this out and let in progress, and other areas of the code |
516 | * leave this out and let in progress, and other areas of the code |
523 | * will then remove it, but that would seem to to use more |
517 | * will then remove it, but that would seem to to use more |
… | |
… | |
598 | return 0; |
592 | return 0; |
599 | |
593 | |
600 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) |
594 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) |
601 | { |
595 | { |
602 | new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); |
596 | new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); |
603 | free_object (tmp); |
597 | tmp->destroy (); |
604 | return 0; |
598 | return 0; |
605 | } |
599 | } |
606 | |
|
|
607 | |
|
|
608 | |
600 | |
609 | tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); |
601 | tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); |
610 | tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); |
602 | tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); |
611 | /* code in time.c uses food for some things, duration for others */ |
603 | /* code in time.c uses food for some things, duration for others */ |
612 | tmp->stats.food = tmp->duration; |
604 | tmp->stats.food = tmp->duration; |
613 | tmp->range = spell->range + SP_level_range_adjust (caster, spell); |
605 | tmp->range = spell->range + SP_level_range_adjust (caster, spell); |
614 | tmp->attacktype = spell->attacktype; |
606 | tmp->attacktype = spell->attacktype; |
615 | tmp->x = x; |
607 | tmp->x = x; |
616 | tmp->y = y; |
608 | tmp->y = y; |
617 | tmp->direction = dir; |
609 | tmp->direction = dir; |
618 | if (get_owner (op) != NULL) |
610 | if (op->owner != NULL) |
619 | copy_owner (tmp, op); |
611 | tmp->set_owner (op); |
620 | else |
612 | else |
621 | set_owner (tmp, op); |
613 | tmp->set_owner (op); |
622 | tmp->level = caster_level (caster, spell); |
614 | tmp->level = caster_level (caster, spell); |
623 | set_spell_skill (op, caster, spell, tmp); |
615 | set_spell_skill (op, caster, spell, tmp); |
624 | |
616 | |
625 | /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ |
617 | /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ |
626 | if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) |
618 | if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) |
… | |
… | |
688 | * we then make the owner of this object the target. |
680 | * we then make the owner of this object the target. |
689 | * The owner could very well be no where near op. |
681 | * The owner could very well be no where near op. |
690 | */ |
682 | */ |
691 | if (op->type != PLAYER && op->type != RUNE) |
683 | if (op->type != PLAYER && op->type != RUNE) |
692 | { |
684 | { |
693 | tmp = get_owner (op); |
685 | tmp = op->owner; |
694 | /* If the owner does not exist, or is not a monster, than apply the spell |
686 | /* If the owner does not exist, or is not a monster, than apply the spell |
695 | * to the caster. |
687 | * to the caster. |
696 | */ |
688 | */ |
697 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
689 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
698 | tmp = op; |
690 | tmp = op; |
… | |
… | |
707 | |
699 | |
708 | if (mflags & P_OUT_OF_MAP) |
700 | if (mflags & P_OUT_OF_MAP) |
709 | tmp = NULL; |
701 | tmp = NULL; |
710 | else |
702 | else |
711 | { |
703 | { |
712 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
704 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
713 | if (tmp->type == PLAYER) |
705 | if (tmp->type == PLAYER) |
714 | break; |
706 | break; |
715 | } |
707 | } |
716 | } |
708 | } |
717 | /* didn't find a player there, look in current square for a player */ |
709 | /* didn't find a player there, look in current square for a player */ |
718 | if (tmp == NULL) |
710 | if (tmp == NULL) |
719 | for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
711 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
720 | { |
712 | { |
721 | if (tmp->type == PLAYER) |
713 | if (tmp->type == PLAYER) |
722 | break; |
714 | break; |
723 | } |
715 | } |
724 | |
716 | |
… | |
… | |
760 | mp = m; |
752 | mp = m; |
761 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
753 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
762 | if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) |
754 | if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) |
763 | continue; |
755 | continue; |
764 | |
756 | |
765 | tmp = get_map_ob (mp, nx, ny); |
757 | tmp = GET_MAP_OB (mp, nx, ny); |
766 | |
758 | |
767 | while (tmp != NULL && (((owner_type == PLAYER && |
759 | while (tmp != NULL && (((owner_type == PLAYER && |
768 | !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || |
760 | !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || |
769 | (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude)))) |
761 | (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude)))) |
770 | tmp = tmp->above; |
762 | tmp = tmp->above; |
… | |
… | |
966 | if (failure <= -20 && failure > -40) /* wonder */ |
958 | if (failure <= -20 && failure > -40) /* wonder */ |
967 | { |
959 | { |
968 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname); |
960 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname); |
969 | tmp = get_archetype (SPELL_WONDER); |
961 | tmp = get_archetype (SPELL_WONDER); |
970 | cast_cone (op, op, 0, tmp); |
962 | cast_cone (op, op, 0, tmp); |
971 | free_object (tmp); |
963 | tmp->destroy (); |
972 | } |
964 | } |
973 | |
965 | |
974 | else if (failure <= -40 && failure > -60) /* confusion */ |
966 | else if (failure <= -40 && failure > -60) /* confusion */ |
975 | { |
967 | { |
976 | new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!"); |
968 | new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!"); |
… | |
… | |
1010 | if (failure <= -20 && failure > -40) /* wonder */ |
1002 | if (failure <= -20 && failure > -40) /* wonder */ |
1011 | { |
1003 | { |
1012 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect."); |
1004 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect."); |
1013 | tmp = get_archetype (SPELL_WONDER); |
1005 | tmp = get_archetype (SPELL_WONDER); |
1014 | cast_cone (op, op, 0, tmp); |
1006 | cast_cone (op, op, 0, tmp); |
1015 | free_object (tmp); |
1007 | tmp->destroy (); |
1016 | } |
1008 | } |
1017 | |
1009 | |
1018 | else if (failure <= -40 && failure > -60) /* confusion */ |
1010 | else if (failure <= -40 && failure > -60) /* confusion */ |
1019 | { |
1011 | { |
1020 | new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!"); |
1012 | new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!"); |
… | |
… | |
1075 | /* Always cast spell on caster */ |
1067 | /* Always cast spell on caster */ |
1076 | success = cast_spell (op, caster, dir, spell, stringarg); |
1068 | success = cast_spell (op, caster, dir, spell, stringarg); |
1077 | |
1069 | |
1078 | if (caster->contr->party == NULL) |
1070 | if (caster->contr->party == NULL) |
1079 | { |
1071 | { |
1080 | remove_ob (spell); |
1072 | spell->remove (); |
1081 | return success; |
1073 | return success; |
1082 | } |
1074 | } |
1083 | for (pl = first_player; pl != NULL; pl = pl->next) |
1075 | for (pl = first_player; pl != NULL; pl = pl->next) |
1084 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1076 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1085 | { |
1077 | { |
1086 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1078 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1087 | } |
1079 | } |
1088 | remove_ob (spell); |
1080 | spell->remove (); |
1089 | return success; |
1081 | return success; |
1090 | } |
1082 | } |
1091 | |
1083 | |
1092 | /* This is where the main dispatch when someone casts a spell. |
1084 | /* This is where the main dispatch when someone casts a spell. |
1093 | * |
1085 | * |
… | |
… | |
1143 | } |
1135 | } |
1144 | |
1136 | |
1145 | /* if caster is a spell casting object, this normally shouldn't be |
1137 | /* if caster is a spell casting object, this normally shouldn't be |
1146 | * an issue, because they don't have any spellpaths set up. |
1138 | * an issue, because they don't have any spellpaths set up. |
1147 | */ |
1139 | */ |
1148 | if (caster->path_denied & spell_ob->path_attuned) |
1140 | if (caster->path_denied & spell_ob->path_attuned && !QUERY_FLAG (caster, FLAG_WIZCAST)) |
1149 | { |
1141 | { |
1150 | new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); |
1142 | new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); |
1151 | return 0; |
1143 | return 0; |
1152 | } |
1144 | } |
1153 | |
1145 | |
… | |
… | |
1288 | * spell is actually cast, it knows about the stringarg. |
1280 | * spell is actually cast, it knows about the stringarg. |
1289 | * necessary for the invoke command spells. |
1281 | * necessary for the invoke command spells. |
1290 | */ |
1282 | */ |
1291 | if (stringarg) |
1283 | if (stringarg) |
1292 | { |
1284 | { |
1293 | op->spellarg = strdup_local (stringarg); |
1285 | op->spellarg = strdup (stringarg); |
1294 | } |
1286 | } |
1295 | else |
1287 | else |
1296 | op->spellarg = NULL; |
1288 | op->spellarg = NULL; |
1297 | return 0; |
1289 | return 0; |
1298 | } |
1290 | } |
… | |
… | |
1691 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1683 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1692 | { |
1684 | { |
1693 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1685 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1694 | |
1686 | |
1695 | if (!spell->destroyed ()) |
1687 | if (!spell->destroyed ()) |
1696 | { |
1688 | spell->destroy (); |
1697 | remove_ob (spell); |
|
|
1698 | free_object (spell); |
|
|
1699 | } |
|
|
1700 | } |
1689 | } |
1701 | break; |
1690 | break; |
1702 | |
1691 | |
1703 | case SP_MOVING_BALL: |
1692 | case SP_MOVING_BALL: |
1704 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1693 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |