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.42 by root, Mon Apr 30 04:25:30 2007 UTC vs.
Revision 1.64 by root, Thu Mar 13 12:20:52 2008 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <spells.h> 25#include <spells.h>
27#include <object.h> 26#include <object.h>
96 95
97 if (init_spells_done) 96 if (init_spells_done)
98 return; 97 return;
99 LOG (llevDebug, "Checking spells...\n"); 98 LOG (llevDebug, "Checking spells...\n");
100 99
101 for (at = first_archetype; at; at = at->next) 100 for_all_archetypes (at)
102 { 101 {
103 if (at->clone.type == SPELL) 102 if (at->type == SPELL)
104 { 103 {
105 if (at->clone.skill) 104 if (at->skill)
106 { 105 {
107 for (i = 1; i < NUM_SKILLS; i++) 106 for (i = 1; i < NUM_SKILLS; i++)
108 if (!strcmp (skill_names[i], at->clone.skill)) 107 if (!strcmp (skill_names[i], at->skill))
109 break; 108 break;
110 if (i == NUM_SKILLS) 109 if (i == NUM_SKILLS)
111 { 110 {
112 LOG (llevError, "Spell %s has improper associated skill %s\n", at->name, at->clone.skill); 111 LOG (llevError, "Spell %s has improper associated skill %s\n", at->name, at->skill);
113 } 112 }
114 } 113 }
115 /* other_arch is already checked for in the loader */ 114 /* other_arch is already checked for in the loader */
116 } 115 }
117 } 116 }
132/* 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.
133 * 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
134 * minimal, but easy enough to keep around. 133 * minimal, but easy enough to keep around.
135 */ 134 */
136void 135void
137dump_spells (void) 136dump_spells ()
138{ 137{
139 archetype *at; 138 for_all_archetypes (at)
140
141 for (at = first_archetype; at; at = at->next)
142 {
143 if (at->clone.type == SPELL) 139 if (at->type == SPELL)
144 {
145 fprintf (stderr, "%s:%s:%s:%s:%d\n", &at->clone.name, 140 fprintf (stderr, "%s:%s:%s:%s:%d\n", &at->object::name,
146 &at->name, at->clone.other_arch ? &at->clone.other_arch->name : "<nil>", &at->clone.skill, at->clone.level); 141 &at->archname, at->other_arch ? &at->other_arch->archname : "<nil>", &at->skill, at->level);
147 }
148 }
149} 142}
150 143
151/* pretty basic function - basically just takes 144/* pretty basic function - basically just takes
152 * 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
153 */ 146 */
169 * Returns modified level. 162 * Returns modified level.
170 */ 163 */
171int 164int
172min_casting_level (object *caster, object *spell) 165min_casting_level (object *caster, object *spell)
173{ 166{
174 int new_level;
175
176 if (caster->path_denied & spell->path_attuned) 167 if (caster->path_denied & spell->path_attuned)
177 return 1; 168 return 1;
178 169
179 new_level = spell->level 170 int new_level = spell->level
180 + (caster->path_repelled & spell->path_attuned ? +2 : 0) 171 + (caster->path_repelled & spell->path_attuned ? +8 : 0)
181 + (caster->path_attuned & spell->path_attuned ? -2 : 0); 172 + (caster->path_attuned & spell->path_attuned ? -8 : 0);
182 173
183 return max (1, new_level); 174 return max (1, new_level);
184} 175}
185 176
186/* This function returns the effective level the spell 177/* This function returns the effective level the spell
211 202
212 level = MIN (level, sk_level + level / 10 + 1); 203 level = MIN (level, sk_level + level / 10 + 1);
213 } 204 }
214 205
215 /* Got valid caster level. Now adjust for attunement */ 206 /* Got valid caster level. Now adjust for attunement */
216 level += caster->path_repelled & spell->path_attuned ? -2 : 0; 207 level += caster->path_repelled & spell->path_attuned ? -8 : 0;
217 level += caster->path_attuned & spell->path_attuned ? +2 : 0; 208 level += caster->path_attuned & spell->path_attuned ? +8 : 0;
218 209
219 /* Always make this at least 1. If this is zero, we get divide by zero 210 /* Always make this at least 1. If this is zero, we get divide by zero
220 * errors in various places. 211 * errors in various places.
221 */ 212 */
222 return max (level, 1); 213 return max (level, 1);
270 sp = 1; 261 sp = 1;
271 grace = (int) (spell->stats.grace * PATH_SP_MULT (caster, spell)); 262 grace = (int) (spell->stats.grace * PATH_SP_MULT (caster, spell));
272 if (spell->stats.grace && !grace) 263 if (spell->stats.grace && !grace)
273 grace = 1; 264 grace = 1;
274 } 265 }
266
275 if (flags == SPELL_HIGHEST) 267 if (flags == SPELL_HIGHEST)
276 return MAX (sp, grace); 268 return MAX (sp, grace);
277 else if (flags == SPELL_GRACE) 269 else if (flags == SPELL_GRACE)
278 return grace; 270 return grace;
279 else if (flags == SPELL_MANA) 271 else if (flags == SPELL_MANA)
283 LOG (llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags); 275 LOG (llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
284 return 0; 276 return 0;
285 } 277 }
286} 278}
287 279
288
289/* SP_level_dam_adjust: Returns adjusted damage based on the caster. 280/* SP_level_dam_adjust: Returns adjusted damage based on the caster.
290 * spob is the spell we are adjusting. 281 * spob is the spell we are adjusting.
291 */ 282 */
292int 283int
293SP_level_dam_adjust (object *caster, object *spob) 284SP_level_dam_adjust (object *caster, object *spob)
294{ 285{
286 if (!spob->dam_modifier)
287 return 0;
288
295 int level = caster_level (caster, spob); 289 int level = caster_level (caster, spob);
296 int adj = level - min_casting_level (caster, spob); 290 return max (0, level - min_casting_level (caster, spob)) / spob->dam_modifier;
297
298 if (adj < 0)
299 adj = 0;
300 if (spob->dam_modifier)
301 adj /= spob->dam_modifier;
302 else
303 adj = 0;
304 return adj;
305} 291}
306 292
307/* Adjust the strength of the spell based on level. 293/* Adjust the strength of the spell based on level.
308 * This is basically the same as SP_level_dam_adjust above, 294 * This is basically the same as SP_level_dam_adjust above,
309 * but instead looks at the level_modifier value. 295 * but instead looks at the level_modifier value.
310 */ 296 */
311int 297int
312SP_level_duration_adjust (object *caster, object *spob) 298SP_level_duration_adjust (object *caster, object *spob)
313{ 299{
300 if (!spob->duration_modifier)
301 return 0;
302
314 int level = caster_level (caster, spob); 303 int level = caster_level (caster, spob);
315 int adj = level - min_casting_level (caster, spob); 304 return max (0, level - min_casting_level (caster, spob)) / spob->duration_modifier;
316
317 if (adj < 0)
318 adj = 0;
319 if (spob->duration_modifier)
320 adj /= spob->duration_modifier;
321 else
322 adj = 0;
323
324 return adj;
325} 305}
326 306
327/* Adjust the strength of the spell based on level. 307/* Adjust the strength of the spell based on level.
328 * This is basically the same as SP_level_dam_adjust above, 308 * This is basically the same as SP_level_dam_adjust above,
329 * but instead looks at the level_modifier value. 309 * but instead looks at the level_modifier value.
330 */ 310 */
331int 311int
332SP_level_range_adjust (object *caster, object *spob) 312SP_level_range_adjust (object *caster, object *spob)
333{ 313{
314 if (!spob->range_modifier)
315 return 0;
316
334 int level = caster_level (caster, spob); 317 int level = caster_level (caster, spob);
335 int adj = level - min_casting_level (caster, spob); 318 return (level - min_casting_level (caster, spob)) / spob->range_modifier;
336
337 if (adj < 0)
338 adj = 0;
339 if (spob->range_modifier)
340 adj /= spob->range_modifier;
341 else
342 adj = 0;
343
344 return adj;
345} 319}
346 320
347/* Checks to see if player knows the spell. If the name is the same 321/* Checks to see if player knows the spell. If the name is the same
348 * as an existing spell, we presume they know it. 322 * as an existing spell, we presume they know it.
349 * returns 1 if they know the spell, 0 if they don't. 323 * returns 1 if they know the spell, 0 if they don't.
458 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 432 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
459 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); 433 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet.");
460 dir = 0; 434 dir = 0;
461 } 435 }
462 436
437 SET_FLAG (new_op, FLAG_IDENTIFIED);
463 op->map->insert (new_op, 438 op->map->insert (new_op,
464 op->x + freearr_x[dir], op->y + freearr_y[dir], 439 op->x + freearr_x[dir], op->y + freearr_y[dir],
465 op, 440 op,
466 dir ? 0 : INS_BELOW_ORIGINATOR); 441 dir ? 0 : INS_BELOW_ORIGINATOR);
467 442
557 * dir: direction to fire in. 532 * dir: direction to fire in.
558 * spell: spell that is being fired. It uses other_arch for the archetype 533 * spell: spell that is being fired. It uses other_arch for the archetype
559 * to fire. 534 * to fire.
560 * returns 0 on failure, 1 on success. 535 * returns 0 on failure, 1 on success.
561 */ 536 */
562
563int 537int
564fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) 538fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
565{ 539{
566 object *tmp; 540 object *tmp;
567 int mflags; 541 int mflags;
627 ****************************************************************************/ 601 ****************************************************************************/
628void 602void
629regenerate_rod (object *rod) 603regenerate_rod (object *rod)
630{ 604{
631 if (rod->stats.hp < rod->stats.maxhp) 605 if (rod->stats.hp < rod->stats.maxhp)
632 { 606 rod->stats.hp = min (rod->stats.maxhp, rod->stats.hp + 1 + rod->stats.maxhp / 10);
633 rod->stats.hp += 1 + rod->stats.maxhp / 10;
634
635 if (rod->stats.hp > rod->stats.maxhp)
636 rod->stats.hp = rod->stats.maxhp;
637 }
638} 607}
639
640 608
641void 609void
642drain_rod_charge (object *rod) 610drain_rod_charge (object *rod)
643{ 611{
644 rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST); 612 rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST);
754 722
755 /* find a free square nearby 723 /* find a free square nearby
756 * first we check the closest square for free squares 724 * first we check the closest square for free squares
757 */ 725 */
758 726
759 dir = find_first_free_spot (&at->clone, op->map, op->x, op->y); 727 dir = find_first_free_spot (at, op->map, op->x, op->y);
760 if (dir != -1) 728 if (dir != -1)
761 { 729 {
762 /* This is basically grabbed for generate monster. Fixed 971225 to 730 /* This is basically grabbed for generate monster. Fixed 971225 to
763 * insert multipart monsters properly 731 * insert multipart monsters properly
764 */ 732 */
733 //TODO: use expand_tail + ...
765 while (at != NULL) 734 while (at != NULL)
766 { 735 {
767 tmp = arch_to_object (at); 736 tmp = arch_to_object (at);
768 tmp->x = op->x + freearr_x[dir] + at->clone.x; 737 tmp->x = op->x + freearr_x[dir] + at->x;
769 tmp->y = op->y + freearr_y[dir] + at->clone.y; 738 tmp->y = op->y + freearr_y[dir] + at->y;
770 tmp->map = op->map; 739 tmp->map = op->map;
771 if (head) 740 if (head)
772 { 741 {
773 tmp->head = head; 742 tmp->head = head;
774 prev->more = tmp; 743 prev->more = tmp;
775 } 744 }
745
776 if (!head) 746 if (!head)
777 head = tmp; 747 head = tmp;
748
778 prev = tmp; 749 prev = tmp;
750
779 at = at->more; 751 at = (archetype *)at->more;
780 } 752 }
781 753
782 if (head->randomitems) 754 if (head->randomitems)
783 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 755 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
784 756
997 if (!spell_ob->other_arch) 969 if (!spell_ob->other_arch)
998 { 970 {
999 LOG (llevError, "cast_party_spell: empty other arch\n"); 971 LOG (llevError, "cast_party_spell: empty other arch\n");
1000 return 0; 972 return 0;
1001 } 973 }
974
1002 spell = arch_to_object (spell_ob->other_arch); 975 spell = arch_to_object (spell_ob->other_arch);
1003 976
1004 /* Always cast spell on caster */ 977 /* Always cast spell on caster */
1005 success = cast_spell (op, caster, dir, spell, stringarg); 978 success = cast_spell (op, caster, dir, spell, stringarg);
1006 979
1007 if (caster->contr->party == NULL) 980 if (caster->contr->party == NULL)
1008 { 981 {
1009 spell->remove (); 982 spell->remove ();
1010 return success; 983 return success;
1011 } 984 }
985
1012 for_all_players (pl) 986 for_all_players (pl)
1013 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) 987 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster)))
1014 {
1015 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); 988 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg);
1016 } 989
1017 spell->remove (); 990 spell->remove ();
1018 return success; 991 return success;
1019} 992}
1020 993
1021/* This is where the main dispatch when someone casts a spell. 994/* This is where the main dispatch when someone casts a spell.
1047 */ 1020 */
1048int 1021int
1049cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 1022cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
1050{ 1023{
1051 const char *godname; 1024 const char *godname;
1052 int success = 0, mflags, cast_level = 0; 1025 int success = 0, cast_level = 0;
1053 object *skill = NULL; 1026 object *skill = NULL;
1054 1027
1055 if (!spell_ob) 1028 if (!spell_ob)
1056 { 1029 {
1057 LOG (llevError, "cast_spell: null spell object passed\n"); 1030 LOG (llevError, "cast_spell: null spell object passed\n");
1087 * at least process that code. 1060 * at least process that code.
1088 */ 1061 */
1089 if (op->type == PLAYER && op == caster) 1062 if (op->type == PLAYER && op == caster)
1090 { 1063 {
1091 cast_level = caster_level (caster, spell_ob); 1064 cast_level = caster_level (caster, spell_ob);
1065
1092 if (spell_ob->skill) 1066 if (spell_ob->skill)
1093 { 1067 {
1094 skill = find_skill_by_name (op, spell_ob->skill); 1068 skill = find_skill_by_name (op, spell_ob->skill);
1069
1095 if (!skill) 1070 if (!skill)
1096 { 1071 {
1097 new_draw_info_format (NDI_UNIQUE, 0, op, "You need the skill %s to cast %s.", &spell_ob->skill, &spell_ob->name); 1072 op->failmsg (format ("You need the skill %s to cast %s!", &spell_ob->skill, &spell_ob->name));
1098 return 0; 1073 return 0;
1099 } 1074 }
1075
1100 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) 1076 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ))
1101 { 1077 {
1102 new_draw_info (NDI_UNIQUE, 0, op, "You lack enough skill to cast that spell."); 1078 op->failmsg ("You lack enough skill to cast that spell!");
1103 return 0; 1079 return 0;
1104 } 1080 }
1105 } 1081 }
1082
1106 /* If the caster is the wiz, they don't ever fail, and don't have 1083 /* If the caster is the wiz, they don't ever fail, and don't have
1107 * to have sufficient grace/mana. 1084 * to have sufficient grace/mana.
1108 */ 1085 */
1109 if (!QUERY_FLAG (op, FLAG_WIZ)) 1086 if (!QUERY_FLAG (op, FLAG_WIZ))
1110 { 1087 {
1111 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && 1088 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) &&
1112 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1089 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1113 { 1090 {
1114 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 1091 op->failmsg ("You don't have enough mana!");
1115 return 0; 1092 return 0;
1116 } 1093 }
1117 1094
1118 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && 1095 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) &&
1119 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) 1096 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace)
1120 { 1097 {
1121 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - 1098 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace -
1122 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) 1099 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0)
1123 {
1124 new_draw_info_format (NDI_UNIQUE, 0, op, "%s grants your prayer, though you are unworthy.", godname); 1100 op->statusmsg (format ("%s grants your prayer, though you are unworthy.", godname));
1125 }
1126 else 1101 else
1127 { 1102 {
1128 prayer_failure (op, op->stats.grace, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) - op->stats.grace); 1103 prayer_failure (op, op->stats.grace, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) - op->stats.grace);
1129 new_draw_info_format (NDI_UNIQUE, 0, op, "%s ignores your prayer.", godname); 1104 op->failmsg (format ("%s ignores your prayer.", godname));
1130 return 0; 1105 return 0;
1131 } 1106 }
1132 } 1107 }
1133 1108
1134 /* player/monster is trying to cast the spell. might fumble it */ 1109 /* player/monster is trying to cast the spell. might fumble it */
1135 if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < 1110 if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) <
1136 (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) 1111 (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis]))
1137 { 1112 {
1138 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); 1113 op->contr->play_sound (sound_find ("fumble_spell"));
1139 new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); 1114 op->failmsg ("You fumble the prayer.");
1140
1141 if (settings.casting_time == TRUE)
1142 op->casting_time = -1;
1143 1115
1144 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); 1116 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1145 return 0; 1117 return 0;
1146 } 1118 }
1147 else if (spell_ob->stats.sp) 1119 else if (spell_ob->stats.sp)
1148 { 1120 {
1149 int failure = random_roll (0, 199, op, PREFER_HIGH) - op->contr->encumbrance + op->level - spell_ob->level + 35; 1121 int failure = random_roll (0, 199, op, PREFER_HIGH) - op->contr->encumbrance + op->level - spell_ob->level + 35;
1150 1122
1151 if (failure < 0) 1123 if (failure < 0)
1152 { 1124 {
1153 new_draw_info (NDI_UNIQUE, 0, op, "You bungle the spell because you have too much heavy equipment in use."); 1125 op->failmsg ("You bungle the spell because you have too much heavy equipment in use.");
1154 if (settings.spell_failure_effects == TRUE) 1126 if (settings.spell_failure_effects == TRUE)
1155 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill); 1127 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill);
1156 1128
1157 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW); 1129 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW);
1158 return 0; 1130 return 0;
1159 } 1131 }
1160 } 1132 }
1161 } 1133 }
1162 } 1134 }
1163 1135
1164 mflags = get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL); 1136 int mflags = op->ms ().flags ();
1165 1137
1166 /* See if we can cast a spell here. If the caster and op are 1138 /* See if we can cast a spell here. If the caster and op are
1167 * not alive, then this would mean that the mapmaker put the 1139 * not alive, then this would mean that the mapmaker put the
1168 * objects on the space - presume that they know what they are 1140 * objects on the space - presume that they know what they are
1169 * doing. 1141 * doing.
1170 */ 1142 */
1171 1143
1172 if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)! 1144 if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)!
1173 { 1145 {
1174 new_draw_info (NDI_UNIQUE, 0, op, "This ground is sacred! The gods prevent any magical effects done by you here!."); 1146 op->failmsg ("This ground is sacred! The gods prevent any magical effects done by you here!");
1175 return 0; 1147 return 0;
1176 } 1148 }
1177 1149
1178 if ((spell_ob->type == SPELL) 1150 if ((spell_ob->type == SPELL)
1179 && (caster->type != POTION) 1151 && (caster->type != POTION)
1184 { 1156 {
1185 if (op->type != PLAYER) 1157 if (op->type != PLAYER)
1186 return 0; 1158 return 0;
1187 1159
1188 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) 1160 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace)
1189 new_draw_info_format (NDI_UNIQUE, 0, op, "This ground is unholy! %s ignores you.", godname); 1161 op->failmsg (format ("This ground is unholy! %s ignores you.", godname));
1190 else 1162 else if (object *item = op->contr->ranged_ob)
1191 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the spell!");
1192
1193 return 0;
1194 }
1195
1196 if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL)
1197 {
1198 if (op->casting_time == -1)
1199 { /* begin the casting */
1200 op->casting_time = (sint16) (spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob));
1201 op->spell = spell_ob;
1202 /* put the stringarg into the object struct so that when the
1203 * spell is actually cast, it knows about the stringarg.
1204 * necessary for the invoke command spells.
1205 */
1206 if (stringarg)
1207 { 1163 {
1208 op->spellarg = strdup (stringarg); 1164 if (item->type == SPELL)
1209 } 1165 op->failmsg ("Something blocks your spellcasting.");
1166 else if (item->type == SCROLL)
1167 op->failmsg ("Something blocks the magic of your scroll.");
1210 else 1168 else
1211 op->spellarg = NULL; 1169 op->failmsg ("Something blocks the magic of your item.");
1212 return 0;
1213 }
1214 else if (op->casting_time != 0)
1215 {
1216 if (op->type == PLAYER)
1217 new_draw_info (NDI_UNIQUE, 0, op, "You are casting!");
1218 return 0;
1219 } 1170 }
1220 else 1171 else
1221 { /* casting_time == 0 */ 1172 op->failmsg ("Something blocks the spell!");
1222 op->casting_time = -1; 1173
1223 spell_ob = op->spell; 1174 return 0;
1224 stringarg = op->spellarg;
1225 }
1226 }
1227 else
1228 { 1175 }
1176
1229 /* Take into account how long it takes to cast the spell. 1177 /* Take into account how long it takes to cast the spell.
1230 * if the player is casting it, then we use the time in 1178 * if the player is casting it, then we use the time in
1231 * the spell object. If it is a spell object, have it 1179 * the spell object. If it is a spell object, have it
1232 * take two ticks. Things that cast spells on the players 1180 * take two ticks. Things that cast spells on the players
1233 * behalf (eg, altars, and whatever else) shouldn't cost 1181 * behalf (eg, altars, and whatever else) shouldn't cost
1234 * the player any time. 1182 * the player any time.
1235 * Ignore casting time for firewalls 1183 * Ignore casting time for firewalls
1184 */
1185 if (caster == op && caster->type != FIREWALL)
1186 {
1187 op->speed_left -= spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed);
1188 /* Other portions of the code may also decrement the speed of the player, so
1189 * put a lower limit so that the player isn't stuck here too long
1236 */ 1190 */
1237 if (caster == op && caster->type != FIREWALL)
1238 {
1239 op->speed_left -= spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed);
1240 /* Other portions of the code may also decrement the speed of the player, so
1241 * put a lower limit so that the player isn't stuck here too long
1242 */
1243 if ((spell_ob->casting_time > 0) && op->speed_left < -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed)) 1191 if ((spell_ob->casting_time > 0) && op->speed_left < -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed))
1244 op->speed_left = -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed); 1192 op->speed_left = -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed);
1245 } 1193 }
1246 else if (caster->type == WAND || caster->type == HORN || caster->type == ROD || caster->type == POTION || caster->type == SCROLL) 1194 else if (caster->type == WAND || caster->type == HORN || caster->type == ROD || caster->type == POTION || caster->type == SCROLL)
1247 {
1248 op->speed_left -= 2 * FABS (op->speed); 1195 op->speed_left -= 2 * FABS (op->speed);
1249 }
1250 }
1251 1196
1252 if (op->type == PLAYER && op == caster) 1197 if (op->type == PLAYER && op == caster)
1253 { 1198 {
1254 op->stats.grace -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE); 1199 op->stats.grace -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE);
1255 op->stats.sp -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA); 1200 op->stats.sp -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA);
1262 if (op != caster && !skill && caster->skill) 1207 if (op != caster && !skill && caster->skill)
1263 { 1208 {
1264 skill = find_skill_by_name (op, caster->skill); 1209 skill = find_skill_by_name (op, caster->skill);
1265 if (!skill) 1210 if (!skill)
1266 { 1211 {
1267 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the skill %s to use the %s", &caster->skill, query_name (caster)); 1212 op->failmsg (format ("You lack the skill %s to use the %s!", &caster->skill, query_name (caster)));
1268 return 0; 1213 return 0;
1269 } 1214 }
1215
1270 change_skill (op, skill, 0); /* needed for proper exp credit */ 1216 op->change_skill (skill); /* needed for proper exp credit */
1271 } 1217 }
1218
1219 if (INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (stringarg)))
1220 return RESULT_INT (0);
1272 1221
1273 switch (spell_ob->subtype) 1222 switch (spell_ob->subtype)
1274 { 1223 {
1275 /* The order of case statements is same as the order they show up 1224 /* The order of case statements is same as the order they show up
1276 * in in spells.h. 1225 * in in spells.h.
1277 */ 1226 */
1278 case SP_RAISE_DEAD: 1227 case SP_RAISE_DEAD:
1279 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg); 1228 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg);
1280 break; 1229 break;
1281 1230
1282 case SP_RUNE: 1231 case SP_RUNE:
1397#ifdef NO_POLYMORPH 1346#ifdef NO_POLYMORPH
1398 /* Not great, but at least provide feedback so if players do have 1347 /* Not great, but at least provide feedback so if players do have
1399 * polymorph (ie, find it as a preset item or left over from before 1348 * polymorph (ie, find it as a preset item or left over from before
1400 * it was disabled), they get some feedback. 1349 * it was disabled), they get some feedback.
1401 */ 1350 */
1402 new_draw_info (NDI_UNIQUE, 0, op, "The spell fizzles"); 1351 op->failmsg ("The spell fizzles!");
1403 success = 0; 1352 success = 0;
1404#else 1353#else
1405 success = cast_polymorph (op, caster, spell_ob, dir); 1354 success = cast_polymorph (op, caster, spell_ob, dir);
1406#endif 1355#endif
1407 break; 1356 break;
1427 break; 1376 break;
1428 1377
1429 case SP_MOVING_BALL: 1378 case SP_MOVING_BALL:
1430 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled) 1379 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled)
1431 { 1380 {
1432 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the proper attunement to cast %s", &spell_ob->name); 1381 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name));
1433 success = 0; 1382 success = 0;
1434 } 1383 }
1435 else 1384 else
1436 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1385 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob);
1437 break; 1386 break;
1479 1428
1480 case SP_AURA: 1429 case SP_AURA:
1481 success = create_aura (op, caster, spell_ob); 1430 success = create_aura (op, caster, spell_ob);
1482 break; 1431 break;
1483 1432
1484 case SP_TOWN_PORTAL:
1485 success = cast_create_town_portal (op, caster, spell_ob, dir);
1486 break;
1487
1488 case SP_PARTY_SPELL: 1433 case SP_PARTY_SPELL:
1489 success = cast_party_spell (op, caster, dir, spell_ob, stringarg); 1434 success = cast_party_spell (op, caster, dir, spell_ob, stringarg);
1490 break; 1435 break;
1491 1436
1492 default: 1437 default:
1493 if (!INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (stringarg)))
1494 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); 1438 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1495 }
1496
1497 /* FIXME - we need some better sound suppport */
1498 // yes, for example, augment map info with the spell effect
1499 // so clients can calculate the sounds themselves
1500 //play_sound_map(op->map, op->x, op->y, SOUND_CAST_SPELL_0 + spell_ob->subtype);
1501
1502 /* free the spell arg */
1503 if (settings.casting_time == TRUE && stringarg)
1504 { 1439 }
1505 free (stringarg); 1440
1506 stringarg = 0; 1441 op->play_sound (
1507 } 1442 success
1443 ? spell_ob->sound
1444 ? spell_ob->sound
1445 : sound_find ("spell_success")
1446 : sound_find ("fumble_spell")
1447 );
1508 1448
1509 return success; 1449 return success;
1510} 1450}
1511 1451
1512
1513/* This is called from time.c/process_object(). That function 1452/* This is called from time.c/process_object(). That function
1514 * calls this for any SPELL_EFFECT type objects. This function 1453 * calls this for any SPELL_EFFECT type objects. This function
1515 * then dispatches them to the appropriate specific routines. 1454 * then dispatches them to the appropriate specific routines.
1516 */ 1455 */
1517void 1456void
1518move_spell_effect (object *op) 1457move_spell_effect (object *op)
1519{ 1458{
1610 else if (victim->materialname) 1549 else if (victim->materialname)
1611 save_throw_object (victim, spell->attacktype, spell); 1550 save_throw_object (victim, spell->attacktype, spell);
1612 break; 1551 break;
1613 } 1552 }
1614} 1553}
1554

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines