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.54 by root, Sun Jul 1 05:00:20 2007 UTC vs.
Revision 1.62 by root, Sun Oct 21 01:35:14 2007 UTC

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 */
135void 135void
136dump_spells (void) 136dump_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 */
269 sp = 1; 263 sp = 1;
270 grace = (int) (spell->stats.grace * PATH_SP_MULT (caster, spell)); 264 grace = (int) (spell->stats.grace * PATH_SP_MULT (caster, spell));
271 if (spell->stats.grace && !grace) 265 if (spell->stats.grace && !grace)
272 grace = 1; 266 grace = 1;
273 } 267 }
268
274 if (flags == SPELL_HIGHEST) 269 if (flags == SPELL_HIGHEST)
275 return MAX (sp, grace); 270 return MAX (sp, grace);
276 else if (flags == SPELL_GRACE) 271 else if (flags == SPELL_GRACE)
277 return grace; 272 return grace;
278 else if (flags == SPELL_MANA) 273 else if (flags == SPELL_MANA)
282 LOG (llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags); 277 LOG (llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
283 return 0; 278 return 0;
284 } 279 }
285} 280}
286 281
287
288/* SP_level_dam_adjust: Returns adjusted damage based on the caster. 282/* SP_level_dam_adjust: Returns adjusted damage based on the caster.
289 * spob is the spell we are adjusting. 283 * spob is the spell we are adjusting.
290 */ 284 */
291int 285int
292SP_level_dam_adjust (object *caster, object *spob) 286SP_level_dam_adjust (object *caster, object *spob)
293{ 287{
288 if (!spob->dam_modifier)
289 return 0;
290
294 int level = caster_level (caster, spob); 291 int level = caster_level (caster, spob);
295 int adj = level - min_casting_level (caster, spob); 292 return max (0, level - min_casting_level (caster, spob)) / spob->dam_modifier;
296
297 if (adj < 0)
298 adj = 0;
299 if (spob->dam_modifier)
300 adj /= spob->dam_modifier;
301 else
302 adj = 0;
303 return adj;
304} 293}
305 294
306/* Adjust the strength of the spell based on level. 295/* Adjust the strength of the spell based on level.
307 * This is basically the same as SP_level_dam_adjust above, 296 * This is basically the same as SP_level_dam_adjust above,
308 * but instead looks at the level_modifier value. 297 * but instead looks at the level_modifier value.
309 */ 298 */
310int 299int
311SP_level_duration_adjust (object *caster, object *spob) 300SP_level_duration_adjust (object *caster, object *spob)
312{ 301{
302 if (!spob->duration_modifier)
303 return 0;
304
313 int level = caster_level (caster, spob); 305 int level = caster_level (caster, spob);
314 int adj = level - min_casting_level (caster, spob); 306 return max (0, level - min_casting_level (caster, spob)) / spob->duration_modifier;
315
316 if (adj < 0)
317 adj = 0;
318 if (spob->duration_modifier)
319 adj /= spob->duration_modifier;
320 else
321 adj = 0;
322
323 return adj;
324} 307}
325 308
326/* Adjust the strength of the spell based on level. 309/* Adjust the strength of the spell based on level.
327 * This is basically the same as SP_level_dam_adjust above, 310 * This is basically the same as SP_level_dam_adjust above,
328 * but instead looks at the level_modifier value. 311 * but instead looks at the level_modifier value.
329 */ 312 */
330int 313int
331SP_level_range_adjust (object *caster, object *spob) 314SP_level_range_adjust (object *caster, object *spob)
332{ 315{
316 if (!spob->range_modifier)
317 return 0;
318
333 int level = caster_level (caster, spob); 319 int level = caster_level (caster, spob);
334 int adj = level - min_casting_level (caster, spob); 320 return (level - min_casting_level (caster, spob)) / spob->range_modifier;
335
336 if (adj < 0)
337 adj = 0;
338 if (spob->range_modifier)
339 adj /= spob->range_modifier;
340 else
341 adj = 0;
342
343 return adj;
344} 321}
345 322
346/* Checks to see if player knows the spell. If the name is the same 323/* Checks to see if player knows the spell. If the name is the same
347 * as an existing spell, we presume they know it. 324 * as an existing spell, we presume they know it.
348 * returns 1 if they know the spell, 0 if they don't. 325 * returns 1 if they know the spell, 0 if they don't.
457 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 434 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."); 435 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet.");
459 dir = 0; 436 dir = 0;
460 } 437 }
461 438
439 SET_FLAG (new_op, FLAG_IDENTIFIED);
462 op->map->insert (new_op, 440 op->map->insert (new_op,
463 op->x + freearr_x[dir], op->y + freearr_y[dir], 441 op->x + freearr_x[dir], op->y + freearr_y[dir],
464 op, 442 op,
465 dir ? 0 : INS_BELOW_ORIGINATOR); 443 dir ? 0 : INS_BELOW_ORIGINATOR);
466 444
556 * dir: direction to fire in. 534 * dir: direction to fire in.
557 * spell: spell that is being fired. It uses other_arch for the archetype 535 * spell: spell that is being fired. It uses other_arch for the archetype
558 * to fire. 536 * to fire.
559 * returns 0 on failure, 1 on success. 537 * returns 0 on failure, 1 on success.
560 */ 538 */
561
562int 539int
563fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) 540fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
564{ 541{
565 object *tmp; 542 object *tmp;
566 int mflags; 543 int mflags;
994 if (!spell_ob->other_arch) 971 if (!spell_ob->other_arch)
995 { 972 {
996 LOG (llevError, "cast_party_spell: empty other arch\n"); 973 LOG (llevError, "cast_party_spell: empty other arch\n");
997 return 0; 974 return 0;
998 } 975 }
976
999 spell = arch_to_object (spell_ob->other_arch); 977 spell = arch_to_object (spell_ob->other_arch);
1000 978
1001 /* Always cast spell on caster */ 979 /* Always cast spell on caster */
1002 success = cast_spell (op, caster, dir, spell, stringarg); 980 success = cast_spell (op, caster, dir, spell, stringarg);
1003 981
1004 if (caster->contr->party == NULL) 982 if (caster->contr->party == NULL)
1005 { 983 {
1006 spell->remove (); 984 spell->remove ();
1007 return success; 985 return success;
1008 } 986 }
987
1009 for_all_players (pl) 988 for_all_players (pl)
1010 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) 989 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); 990 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg);
1013 } 991
1014 spell->remove (); 992 spell->remove ();
1015 return success; 993 return success;
1016} 994}
1017 995
1018/* This is where the main dispatch when someone casts a spell. 996/* This is where the main dispatch when someone casts a spell.
1044 */ 1022 */
1045int 1023int
1046cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 1024cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
1047{ 1025{
1048 const char *godname; 1026 const char *godname;
1049 int success = 0, mflags, cast_level = 0; 1027 int success = 0, cast_level = 0;
1050 object *skill = NULL; 1028 object *skill = NULL;
1051 1029
1052 if (!spell_ob) 1030 if (!spell_ob)
1053 { 1031 {
1054 LOG (llevError, "cast_spell: null spell object passed\n"); 1032 LOG (llevError, "cast_spell: null spell object passed\n");
1091 { 1069 {
1092 skill = find_skill_by_name (op, spell_ob->skill); 1070 skill = find_skill_by_name (op, spell_ob->skill);
1093 1071
1094 if (!skill) 1072 if (!skill)
1095 { 1073 {
1096 new_draw_info_format (NDI_UNIQUE, 0, op, "You need the skill %s to cast %s.", &spell_ob->skill, &spell_ob->name); 1074 op->failmsg (format ("You need the skill %s to cast %s!", &spell_ob->skill, &spell_ob->name));
1097 return 0; 1075 return 0;
1098 } 1076 }
1099 1077
1100 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) 1078 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ))
1101 { 1079 {
1102 new_draw_info (NDI_UNIQUE, 0, op, "You lack enough skill to cast that spell."); 1080 op->failmsg ("You lack enough skill to cast that spell!");
1103 return 0; 1081 return 0;
1104 } 1082 }
1105 } 1083 }
1106 1084
1107 /* If the caster is the wiz, they don't ever fail, and don't have 1085 /* If the caster is the wiz, they don't ever fail, and don't have
1110 if (!QUERY_FLAG (op, FLAG_WIZ)) 1088 if (!QUERY_FLAG (op, FLAG_WIZ))
1111 { 1089 {
1112 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && 1090 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) &&
1113 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1091 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1114 { 1092 {
1115 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 1093 op->failmsg ("You don't have enough mana!");
1116 return 0; 1094 return 0;
1117 } 1095 }
1118 1096
1119 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && 1097 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) &&
1120 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) 1098 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace)
1121 { 1099 {
1122 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - 1100 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) 1101 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); 1102 op->statusmsg (format ("%s grants your prayer, though you are unworthy.", godname));
1126 }
1127 else 1103 else
1128 { 1104 {
1129 prayer_failure (op, op->stats.grace, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) - op->stats.grace); 1105 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); 1106 op->failmsg (format ("%s ignores your prayer.", godname));
1131 return 0; 1107 return 0;
1132 } 1108 }
1133 } 1109 }
1134 1110
1135 /* player/monster is trying to cast the spell. might fumble it */ 1111 /* player/monster is trying to cast the spell. might fumble it */
1136 if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < 1112 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])) 1113 (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis]))
1138 { 1114 {
1139 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); 1115 op->contr->play_sound (sound_find ("fumble_spell"));
1140 new_draw_info (NDI_UNIQUE, 0, op, "You fumble the prayer."); 1116 op->failmsg ("You fumble the prayer.");
1141 1117
1142 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); 1118 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1143 return 0; 1119 return 0;
1144 } 1120 }
1145 else if (spell_ob->stats.sp) 1121 else if (spell_ob->stats.sp)
1146 { 1122 {
1147 int failure = random_roll (0, 199, op, PREFER_HIGH) - op->contr->encumbrance + op->level - spell_ob->level + 35; 1123 int failure = random_roll (0, 199, op, PREFER_HIGH) - op->contr->encumbrance + op->level - spell_ob->level + 35;
1148 1124
1149 if (failure < 0) 1125 if (failure < 0)
1150 { 1126 {
1151 new_draw_info (NDI_UNIQUE, 0, op, "You bungle the spell because you have too much heavy equipment in use."); 1127 op->failmsg ("You bungle the spell because you have too much heavy equipment in use.");
1152 if (settings.spell_failure_effects == TRUE) 1128 if (settings.spell_failure_effects == TRUE)
1153 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill); 1129 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill);
1154 1130
1155 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW); 1131 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW);
1156 return 0; 1132 return 0;
1157 } 1133 }
1158 } 1134 }
1159 } 1135 }
1160 } 1136 }
1161 1137
1162 mflags = get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL); 1138 int mflags = op->ms ().flags ();
1163 1139
1164 /* See if we can cast a spell here. If the caster and op are 1140 /* 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 1141 * not alive, then this would mean that the mapmaker put the
1166 * objects on the space - presume that they know what they are 1142 * objects on the space - presume that they know what they are
1167 * doing. 1143 * doing.
1168 */ 1144 */
1169 1145
1170 if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)! 1146 if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)!
1171 { 1147 {
1172 new_draw_info (NDI_UNIQUE, 0, op, "This ground is sacred! The gods prevent any magical effects done by you here!."); 1148 op->failmsg ("This ground is sacred! The gods prevent any magical effects done by you here!");
1173 return 0; 1149 return 0;
1174 } 1150 }
1175 1151
1176 if ((spell_ob->type == SPELL) 1152 if ((spell_ob->type == SPELL)
1177 && (caster->type != POTION) 1153 && (caster->type != POTION)
1182 { 1158 {
1183 if (op->type != PLAYER) 1159 if (op->type != PLAYER)
1184 return 0; 1160 return 0;
1185 1161
1186 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) 1162 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); 1163 op->failmsg (format ("This ground is unholy! %s ignores you.", godname));
1188 else if (object *item = op->contr->ranged_ob) 1164 else if (object *item = op->contr->ranged_ob)
1189 { 1165 {
1190 if (item->type == SPELL) 1166 if (item->type == SPELL)
1191 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your spellcasting."); 1167 op->failmsg ("Something blocks your spellcasting.");
1192 else if (item->type == SCROLL) 1168 else if (item->type == SCROLL)
1193 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your scroll."); 1169 op->failmsg ("Something blocks the magic of your scroll.");
1194 else 1170 else
1195 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your item."); 1171 op->failmsg ("Something blocks the magic of your item.");
1196 } 1172 }
1197 else 1173 else
1198 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the spell!"); 1174 op->failmsg ("Something blocks the spell!");
1199 1175
1200 return 0; 1176 return 0;
1201 } 1177 }
1202 1178
1203 /* Take into account how long it takes to cast the spell. 1179 /* Take into account how long it takes to cast the spell.
1233 if (op != caster && !skill && caster->skill) 1209 if (op != caster && !skill && caster->skill)
1234 { 1210 {
1235 skill = find_skill_by_name (op, caster->skill); 1211 skill = find_skill_by_name (op, caster->skill);
1236 if (!skill) 1212 if (!skill)
1237 { 1213 {
1238 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the skill %s to use the %s", &caster->skill, query_name (caster)); 1214 op->failmsg (format ("You lack the skill %s to use the %s!", &caster->skill, query_name (caster)));
1239 return 0; 1215 return 0;
1240 } 1216 }
1241 1217
1242 op->change_skill (skill); /* needed for proper exp credit */ 1218 op->change_skill (skill); /* needed for proper exp credit */
1243 } 1219 }
1372#ifdef NO_POLYMORPH 1348#ifdef NO_POLYMORPH
1373 /* Not great, but at least provide feedback so if players do have 1349 /* 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 1350 * polymorph (ie, find it as a preset item or left over from before
1375 * it was disabled), they get some feedback. 1351 * it was disabled), they get some feedback.
1376 */ 1352 */
1377 new_draw_info (NDI_UNIQUE, 0, op, "The spell fizzles"); 1353 op->failmsg ("The spell fizzles!");
1378 success = 0; 1354 success = 0;
1379#else 1355#else
1380 success = cast_polymorph (op, caster, spell_ob, dir); 1356 success = cast_polymorph (op, caster, spell_ob, dir);
1381#endif 1357#endif
1382 break; 1358 break;
1402 break; 1378 break;
1403 1379
1404 case SP_MOVING_BALL: 1380 case SP_MOVING_BALL:
1405 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled) 1381 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled)
1406 { 1382 {
1407 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the proper attunement to cast %s", &spell_ob->name); 1383 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name));
1408 success = 0; 1384 success = 0;
1409 } 1385 }
1410 else 1386 else
1411 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1387 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob);
1412 break; 1388 break;
1462 1438
1463 default: 1439 default:
1464 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); 1440 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1465 } 1441 }
1466 1442
1467 /* FIXME - we need some better sound suppport */ 1443 op->play_sound (
1468 // yes, for example, augment map info with the spell effect 1444 success
1469 // so clients can calculate the sounds themselves 1445 ? spell_ob->sound
1470 //play_sound_map(op->map, op->x, op->y, SOUND_CAST_SPELL_0 + spell_ob->subtype); 1446 ? spell_ob->sound
1447 : sound_find ("spell_success")
1448 : sound_find ("fumble_spell")
1449 );
1471 1450
1472 return success; 1451 return success;
1473} 1452}
1474 1453
1475
1476/* This is called from time.c/process_object(). That function 1454/* This is called from time.c/process_object(). That function
1477 * calls this for any SPELL_EFFECT type objects. This function 1455 * calls this for any SPELL_EFFECT type objects. This function
1478 * then dispatches them to the appropriate specific routines. 1456 * then dispatches them to the appropriate specific routines.
1479 */ 1457 */
1480void 1458void
1481move_spell_effect (object *op) 1459move_spell_effect (object *op)
1482{ 1460{
1573 else if (victim->materialname) 1551 else if (victim->materialname)
1574 save_throw_object (victim, spell->attacktype, spell); 1552 save_throw_object (victim, spell->attacktype, spell);
1575 break; 1553 break;
1576 } 1554 }
1577} 1555}
1556

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines