… | |
… | |
131 | /* Dumps all the spells - now also dumps skill associated with the spell. |
131 | /* Dumps all the spells - now also dumps skill associated with the spell. |
132 | * not sure what this would be used for, as the data seems pretty |
132 | * not sure what this would be used for, as the data seems pretty |
133 | * minimal, but easy enough to keep around. |
133 | * minimal, but easy enough to keep around. |
134 | */ |
134 | */ |
135 | void |
135 | void |
136 | dump_spells (void) |
136 | dump_spells () |
137 | { |
137 | { |
138 | archetype *at; |
|
|
139 | |
|
|
140 | for_all_archetypes (at) |
138 | for_all_archetypes (at) |
141 | { |
|
|
142 | if (at->type == SPELL) |
139 | if (at->type == SPELL) |
143 | { |
|
|
144 | fprintf (stderr, "%s:%s:%s:%s:%d\n", &at->object::name, |
140 | fprintf (stderr, "%s:%s:%s:%s:%d\n", &at->object::name, |
145 | &at->archname, at->other_arch ? &at->other_arch->archname : "<nil>", &at->skill, at->level); |
141 | &at->archname, at->other_arch ? &at->other_arch->archname : "<nil>", &at->skill, at->level); |
146 | } |
|
|
147 | } |
|
|
148 | } |
142 | } |
149 | |
143 | |
150 | /* pretty basic function - basically just takes |
144 | /* pretty basic function - basically just takes |
151 | * an object, sets the x,y, and calls insert_ob_in_map |
145 | * an object, sets the x,y, and calls insert_ob_in_map |
152 | */ |
146 | */ |
… | |
… | |
457 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
451 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
458 | new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); |
452 | new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); |
459 | dir = 0; |
453 | dir = 0; |
460 | } |
454 | } |
461 | |
455 | |
|
|
456 | SET_FLAG (new_op, FLAG_IDENTIFIED); |
462 | op->map->insert (new_op, |
457 | op->map->insert (new_op, |
463 | op->x + freearr_x[dir], op->y + freearr_y[dir], |
458 | op->x + freearr_x[dir], op->y + freearr_y[dir], |
464 | op, |
459 | op, |
465 | dir ? 0 : INS_BELOW_ORIGINATOR); |
460 | dir ? 0 : INS_BELOW_ORIGINATOR); |
466 | |
461 | |
… | |
… | |
556 | * dir: direction to fire in. |
551 | * dir: direction to fire in. |
557 | * spell: spell that is being fired. It uses other_arch for the archetype |
552 | * spell: spell that is being fired. It uses other_arch for the archetype |
558 | * to fire. |
553 | * to fire. |
559 | * returns 0 on failure, 1 on success. |
554 | * returns 0 on failure, 1 on success. |
560 | */ |
555 | */ |
561 | |
|
|
562 | int |
556 | int |
563 | fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) |
557 | fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) |
564 | { |
558 | { |
565 | object *tmp; |
559 | object *tmp; |
566 | int mflags; |
560 | int mflags; |
… | |
… | |
994 | if (!spell_ob->other_arch) |
988 | if (!spell_ob->other_arch) |
995 | { |
989 | { |
996 | LOG (llevError, "cast_party_spell: empty other arch\n"); |
990 | LOG (llevError, "cast_party_spell: empty other arch\n"); |
997 | return 0; |
991 | return 0; |
998 | } |
992 | } |
|
|
993 | |
999 | spell = arch_to_object (spell_ob->other_arch); |
994 | spell = arch_to_object (spell_ob->other_arch); |
1000 | |
995 | |
1001 | /* Always cast spell on caster */ |
996 | /* Always cast spell on caster */ |
1002 | success = cast_spell (op, caster, dir, spell, stringarg); |
997 | success = cast_spell (op, caster, dir, spell, stringarg); |
1003 | |
998 | |
1004 | if (caster->contr->party == NULL) |
999 | if (caster->contr->party == NULL) |
1005 | { |
1000 | { |
1006 | spell->remove (); |
1001 | spell->remove (); |
1007 | return success; |
1002 | return success; |
1008 | } |
1003 | } |
|
|
1004 | |
1009 | for_all_players (pl) |
1005 | for_all_players (pl) |
1010 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1006 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1011 | { |
|
|
1012 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1007 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1013 | } |
1008 | |
1014 | spell->remove (); |
1009 | spell->remove (); |
1015 | return success; |
1010 | return success; |
1016 | } |
1011 | } |
1017 | |
1012 | |
1018 | /* This is where the main dispatch when someone casts a spell. |
1013 | /* This is where the main dispatch when someone casts a spell. |
… | |
… | |
1044 | */ |
1039 | */ |
1045 | int |
1040 | int |
1046 | cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) |
1041 | cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) |
1047 | { |
1042 | { |
1048 | const char *godname; |
1043 | const char *godname; |
1049 | int success = 0, mflags, cast_level = 0; |
1044 | int success = 0, cast_level = 0; |
1050 | object *skill = NULL; |
1045 | object *skill = NULL; |
1051 | |
1046 | |
1052 | if (!spell_ob) |
1047 | if (!spell_ob) |
1053 | { |
1048 | { |
1054 | LOG (llevError, "cast_spell: null spell object passed\n"); |
1049 | LOG (llevError, "cast_spell: null spell object passed\n"); |
… | |
… | |
1091 | { |
1086 | { |
1092 | skill = find_skill_by_name (op, spell_ob->skill); |
1087 | skill = find_skill_by_name (op, spell_ob->skill); |
1093 | |
1088 | |
1094 | if (!skill) |
1089 | if (!skill) |
1095 | { |
1090 | { |
1096 | new_draw_info_format (NDI_UNIQUE, 0, op, "You need the skill %s to cast %s.", &spell_ob->skill, &spell_ob->name); |
1091 | op->failmsg (format ("You need the skill %s to cast %s!", &spell_ob->skill, &spell_ob->name)); |
1097 | return 0; |
1092 | return 0; |
1098 | } |
1093 | } |
1099 | |
1094 | |
1100 | if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) |
1095 | if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) |
1101 | { |
1096 | { |
1102 | new_draw_info (NDI_UNIQUE, 0, op, "You lack enough skill to cast that spell."); |
1097 | op->failmsg ("You lack enough skill to cast that spell!"); |
1103 | return 0; |
1098 | return 0; |
1104 | } |
1099 | } |
1105 | } |
1100 | } |
1106 | |
1101 | |
1107 | /* If the caster is the wiz, they don't ever fail, and don't have |
1102 | /* If the caster is the wiz, they don't ever fail, and don't have |
… | |
… | |
1110 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
1105 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
1111 | { |
1106 | { |
1112 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && |
1107 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && |
1113 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1108 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1114 | { |
1109 | { |
1115 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
1110 | op->failmsg ("You don't have enough mana!"); |
1116 | return 0; |
1111 | return 0; |
1117 | } |
1112 | } |
1118 | |
1113 | |
1119 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1114 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1120 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) |
1115 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) |
1121 | { |
1116 | { |
1122 | if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - |
1117 | if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - |
1123 | 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) |
1118 | 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) |
1124 | { |
|
|
1125 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s grants your prayer, though you are unworthy.", godname); |
1119 | op->statusmsg (format ("%s grants your prayer, though you are unworthy.", godname)); |
1126 | } |
|
|
1127 | else |
1120 | else |
1128 | { |
1121 | { |
1129 | prayer_failure (op, op->stats.grace, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) - op->stats.grace); |
1122 | prayer_failure (op, op->stats.grace, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) - op->stats.grace); |
1130 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s ignores your prayer.", godname); |
1123 | op->failmsg (format ("%s ignores your prayer.", godname)); |
1131 | return 0; |
1124 | return 0; |
1132 | } |
1125 | } |
1133 | } |
1126 | } |
1134 | |
1127 | |
1135 | /* player/monster is trying to cast the spell. might fumble it */ |
1128 | /* player/monster is trying to cast the spell. might fumble it */ |
1136 | if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < |
1129 | if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < |
1137 | (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) |
1130 | (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) |
1138 | { |
1131 | { |
1139 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1132 | op->contr->play_sound (sound_find ("fumble_spell")); |
1140 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the prayer."); |
1133 | op->failmsg ("You fumble the prayer."); |
1141 | |
1134 | |
1142 | op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); |
1135 | op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); |
1143 | return 0; |
1136 | return 0; |
1144 | } |
1137 | } |
1145 | else if (spell_ob->stats.sp) |
1138 | else if (spell_ob->stats.sp) |
1146 | { |
1139 | { |
1147 | int failure = random_roll (0, 199, op, PREFER_HIGH) - op->contr->encumbrance + op->level - spell_ob->level + 35; |
1140 | int failure = random_roll (0, 199, op, PREFER_HIGH) - op->contr->encumbrance + op->level - spell_ob->level + 35; |
1148 | |
1141 | |
1149 | if (failure < 0) |
1142 | if (failure < 0) |
1150 | { |
1143 | { |
1151 | new_draw_info (NDI_UNIQUE, 0, op, "You bungle the spell because you have too much heavy equipment in use."); |
1144 | op->failmsg ("You bungle the spell because you have too much heavy equipment in use."); |
1152 | if (settings.spell_failure_effects == TRUE) |
1145 | if (settings.spell_failure_effects == TRUE) |
1153 | spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill); |
1146 | spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill); |
1154 | |
1147 | |
1155 | op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW); |
1148 | op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW); |
1156 | return 0; |
1149 | return 0; |
1157 | } |
1150 | } |
1158 | } |
1151 | } |
1159 | } |
1152 | } |
1160 | } |
1153 | } |
1161 | |
1154 | |
1162 | mflags = get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL); |
1155 | int mflags = op->ms ().flags (); |
1163 | |
1156 | |
1164 | /* See if we can cast a spell here. If the caster and op are |
1157 | /* See if we can cast a spell here. If the caster and op are |
1165 | * not alive, then this would mean that the mapmaker put the |
1158 | * not alive, then this would mean that the mapmaker put the |
1166 | * objects on the space - presume that they know what they are |
1159 | * objects on the space - presume that they know what they are |
1167 | * doing. |
1160 | * doing. |
1168 | */ |
1161 | */ |
1169 | |
1162 | |
1170 | if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)! |
1163 | if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)! |
1171 | { |
1164 | { |
1172 | new_draw_info (NDI_UNIQUE, 0, op, "This ground is sacred! The gods prevent any magical effects done by you here!."); |
1165 | op->failmsg ("This ground is sacred! The gods prevent any magical effects done by you here!"); |
1173 | return 0; |
1166 | return 0; |
1174 | } |
1167 | } |
1175 | |
1168 | |
1176 | if ((spell_ob->type == SPELL) |
1169 | if ((spell_ob->type == SPELL) |
1177 | && (caster->type != POTION) |
1170 | && (caster->type != POTION) |
… | |
… | |
1182 | { |
1175 | { |
1183 | if (op->type != PLAYER) |
1176 | if (op->type != PLAYER) |
1184 | return 0; |
1177 | return 0; |
1185 | |
1178 | |
1186 | if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) |
1179 | if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) |
1187 | new_draw_info_format (NDI_UNIQUE, 0, op, "This ground is unholy! %s ignores you.", godname); |
1180 | op->failmsg (format ("This ground is unholy! %s ignores you.", godname)); |
1188 | else if (object *item = op->contr->ranged_ob) |
1181 | else if (object *item = op->contr->ranged_ob) |
1189 | { |
1182 | { |
1190 | if (item->type == SPELL) |
1183 | if (item->type == SPELL) |
1191 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your spellcasting."); |
1184 | op->failmsg ("Something blocks your spellcasting."); |
1192 | else if (item->type == SCROLL) |
1185 | else if (item->type == SCROLL) |
1193 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your scroll."); |
1186 | op->failmsg ("Something blocks the magic of your scroll."); |
1194 | else |
1187 | else |
1195 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your item."); |
1188 | op->failmsg ("Something blocks the magic of your item."); |
1196 | } |
1189 | } |
1197 | else |
1190 | else |
1198 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the spell!"); |
1191 | op->failmsg ("Something blocks the spell!"); |
1199 | |
1192 | |
1200 | return 0; |
1193 | return 0; |
1201 | } |
1194 | } |
1202 | |
1195 | |
1203 | /* Take into account how long it takes to cast the spell. |
1196 | /* Take into account how long it takes to cast the spell. |
… | |
… | |
1233 | if (op != caster && !skill && caster->skill) |
1226 | if (op != caster && !skill && caster->skill) |
1234 | { |
1227 | { |
1235 | skill = find_skill_by_name (op, caster->skill); |
1228 | skill = find_skill_by_name (op, caster->skill); |
1236 | if (!skill) |
1229 | if (!skill) |
1237 | { |
1230 | { |
1238 | new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the skill %s to use the %s", &caster->skill, query_name (caster)); |
1231 | op->failmsg (format ("You lack the skill %s to use the %s!", &caster->skill, query_name (caster))); |
1239 | return 0; |
1232 | return 0; |
1240 | } |
1233 | } |
1241 | |
1234 | |
1242 | op->change_skill (skill); /* needed for proper exp credit */ |
1235 | op->change_skill (skill); /* needed for proper exp credit */ |
1243 | } |
1236 | } |
… | |
… | |
1372 | #ifdef NO_POLYMORPH |
1365 | #ifdef NO_POLYMORPH |
1373 | /* Not great, but at least provide feedback so if players do have |
1366 | /* Not great, but at least provide feedback so if players do have |
1374 | * polymorph (ie, find it as a preset item or left over from before |
1367 | * polymorph (ie, find it as a preset item or left over from before |
1375 | * it was disabled), they get some feedback. |
1368 | * it was disabled), they get some feedback. |
1376 | */ |
1369 | */ |
1377 | new_draw_info (NDI_UNIQUE, 0, op, "The spell fizzles"); |
1370 | op->failmsg ("The spell fizzles!"); |
1378 | success = 0; |
1371 | success = 0; |
1379 | #else |
1372 | #else |
1380 | success = cast_polymorph (op, caster, spell_ob, dir); |
1373 | success = cast_polymorph (op, caster, spell_ob, dir); |
1381 | #endif |
1374 | #endif |
1382 | break; |
1375 | break; |
… | |
… | |
1402 | break; |
1395 | break; |
1403 | |
1396 | |
1404 | case SP_MOVING_BALL: |
1397 | case SP_MOVING_BALL: |
1405 | if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled) |
1398 | if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled) |
1406 | { |
1399 | { |
1407 | new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the proper attunement to cast %s", &spell_ob->name); |
1400 | op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name)); |
1408 | success = 0; |
1401 | success = 0; |
1409 | } |
1402 | } |
1410 | else |
1403 | else |
1411 | success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); |
1404 | success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); |
1412 | break; |
1405 | break; |
… | |
… | |
1462 | |
1455 | |
1463 | default: |
1456 | default: |
1464 | LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); |
1457 | LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); |
1465 | } |
1458 | } |
1466 | |
1459 | |
1467 | /* FIXME - we need some better sound suppport */ |
1460 | op->play_sound ( |
1468 | // yes, for example, augment map info with the spell effect |
1461 | success |
1469 | // so clients can calculate the sounds themselves |
1462 | ? spell_ob->sound |
1470 | //play_sound_map(op->map, op->x, op->y, SOUND_CAST_SPELL_0 + spell_ob->subtype); |
1463 | ? spell_ob->sound |
|
|
1464 | : sound_find ("spell_success") |
|
|
1465 | : sound_find ("fumble_spell") |
|
|
1466 | ); |
1471 | |
1467 | |
1472 | return success; |
1468 | return success; |
1473 | } |
1469 | } |
1474 | |
1470 | |
1475 | |
|
|
1476 | /* This is called from time.c/process_object(). That function |
1471 | /* This is called from time.c/process_object(). That function |
1477 | * calls this for any SPELL_EFFECT type objects. This function |
1472 | * calls this for any SPELL_EFFECT type objects. This function |
1478 | * then dispatches them to the appropriate specific routines. |
1473 | * then dispatches them to the appropriate specific routines. |
1479 | */ |
1474 | */ |
1480 | void |
1475 | void |
1481 | move_spell_effect (object *op) |
1476 | move_spell_effect (object *op) |
1482 | { |
1477 | { |
… | |
… | |
1573 | else if (victim->materialname) |
1568 | else if (victim->materialname) |
1574 | save_throw_object (victim, spell->attacktype, spell); |
1569 | save_throw_object (victim, spell->attacktype, spell); |
1575 | break; |
1570 | break; |
1576 | } |
1571 | } |
1577 | } |
1572 | } |
|
|
1573 | |