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.11 by root, Sun Sep 10 15:59:58 2006 UTC vs.
Revision 1.24 by root, Wed Dec 20 09:14:22 2006 UTC

1
2/*
3 * static char *rcsid_spell_util_c =
4 * "$Id: spell_util.C,v 1.11 2006/09/10 15:59:58 root Exp $";
5 */
6
7
8/* 1/*
9 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
10 3
11 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
12 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
23 16
24 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 20
28 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
29*/ 22*/
30 23
31 24
32#include <global.h> 25#include <global.h>
33#include <spells.h> 26#include <spells.h>
126 } 119 }
127 120
128 i = 0; 121 i = 0;
129 while (spell_mapping[i]) 122 while (spell_mapping[i])
130 { 123 {
131 if (!find_archetype (spell_mapping[i])) 124 if (!archetype::find (spell_mapping[i]))
132 { 125 {
133 LOG (llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i); 126 LOG (llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i);
134 } 127 }
135 i++; 128 i++;
136 } 129 }
160/* pretty basic function - basically just takes 153/* pretty basic function - basically just takes
161 * an object, sets the x,y, and calls insert_ob_in_map 154 * an object, sets the x,y, and calls insert_ob_in_map
162 */ 155 */
163 156
164void 157void
165spell_effect (object *spob, int x, int y, mapstruct *map, object *originator) 158spell_effect (object *spob, int x, int y, maptile *map, object *originator)
166{ 159{
167 160
168 if (spob->other_arch != NULL) 161 if (spob->other_arch != NULL)
169 { 162 {
170 object *effect = arch_to_object (spob->other_arch); 163 object *effect = arch_to_object (spob->other_arch);
190min_casting_level (object *caster, object *spell) 183min_casting_level (object *caster, object *spell)
191{ 184{
192 int new_level; 185 int new_level;
193 186
194 if (caster->path_denied & spell->path_attuned) 187 if (caster->path_denied & spell->path_attuned)
195 {
196 /* This case is not a bug, just the fact that this function is
197 * usually called BEFORE checking for path_deny. -AV
198 */
199#if 0
200 LOG (llevError, "BUG: path_level_mod (arch %s, name %s): casting denied " "spell\n", caster->arch->name, caster->name);
201#endif
202 return 1; 188 return 1;
203 } 189
204 new_level = spell->level 190 new_level = spell->level
205 + ((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
206 return (new_level < 1) ? 1 : new_level; 193 return (new_level < 1) ? 1 : new_level;
207} 194}
208 195
209 196
210/* This function returns the effective level the spell 197/* This function returns the effective level the spell
219{ 206{
220 int level = caster->level; 207 int level = caster->level;
221 208
222 /* If this is a player, try to find the matching skill */ 209 /* If this is a player, try to find the matching skill */
223 if (caster->type == PLAYER && spell->skill) 210 if (caster->type == PLAYER && spell->skill)
224 {
225 int i;
226
227 for (i = 0; i < NUM_SKILLS; i++) 211 for (int i = 0; i < NUM_SKILLS; i++)
228 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)
229 { 213 {
230 level = caster->contr->last_skill_ob[i]->level; 214 level = caster->contr->last_skill_ob[i]->level;
231 break; 215 break;
232 } 216 }
233 }
234 217
235 /* 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. */
236 if (caster->type == ROD && caster->env && caster->env->type == PLAYER) 219 if (caster->type == ROD && caster->env && caster->env->type == PLAYER)
237 { 220 {
238 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);
247 /* 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
248 * errors in various places. 231 * errors in various places.
249 */ 232 */
250 if (level < 1) 233 if (level < 1)
251 level = 1; 234 level = 1;
235
252 return level; 236 return level;
253} 237}
254 238
255/* The following function scales the spellpoint cost of 239/* The following function scales the spellpoint cost of
256 * a spell by it's increased effectiveness. Some of the 240 * a spell by it's increased effectiveness. Some of the
451 * reflect_spell fails.) 435 * reflect_spell fails.)
452 * Caller should be sure it passes us valid map coordinates 436 * Caller should be sure it passes us valid map coordinates
453 * eg, updated for tiled maps. 437 * eg, updated for tiled maps.
454 */ 438 */
455int 439int
456reflwall (mapstruct *m, int x, int y, object *sp_op) 440reflwall (maptile *m, int x, int y, object *sp_op)
457{ 441{
458 object *op; 442 object *op;
459 443
460 if (OUT_OF_REAL_MAP (m, x, y)) 444 if (OUT_OF_REAL_MAP (m, x, y))
461 return 0; 445 return 0;
462 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)
463 if (QUERY_FLAG (op, FLAG_REFL_SPELL) && (!QUERY_FLAG (op, FLAG_ALIVE) || 447 if (QUERY_FLAG (op, FLAG_REFL_SPELL)
464 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)))
465 return 1; 452 return 1;
466 453
467 return 0; 454 return 0;
468} 455}
469 456
475 * in. 462 * in.
476 */ 463 */
477int 464int
478cast_create_obj (object *op, object *caster, object *new_op, int dir) 465cast_create_obj (object *op, object *caster, object *new_op, int dir)
479{ 466{
480 mapstruct *m; 467 maptile *m;
481 sint16 sx, sy; 468 sint16 sx, sy;
482 469
483 if (dir && 470 if (dir &&
484 ((get_map_flags (op->map, &m, op->x + freearr_x[dir], op->y + freearr_y[dir], &sx, &sy) & P_OUT_OF_MAP) || 471 ((get_map_flags (op->map, &m, op->x + freearr_x[dir], op->y + freearr_y[dir], &sx, &sy) & P_OUT_OF_MAP) ||
485 OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))) 472 OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy))))
505 * does not have AT_MAGIC, then counterwalls do not effect the spell. 492 * does not have AT_MAGIC, then counterwalls do not effect the spell.
506 * 493 *
507 */ 494 */
508 495
509int 496int
510ok_to_put_more (mapstruct *m, sint16 x, sint16 y, object *op, int immune_stop) 497ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop)
511{ 498{
512 object *tmp; 499 object *tmp;
513 int mflags; 500 int mflags;
514 mapstruct *mp; 501 maptile *mp;
515 502
516 mp = m; 503 mp = m;
517 mflags = get_map_flags (m, &mp, x, y, &x, &y); 504 mflags = get_map_flags (m, &mp, x, y, &x, &y);
518 505
519 if (mflags & P_OUT_OF_MAP) 506 if (mflags & P_OUT_OF_MAP)
520 return 0; 507 return 0;
521 508
522 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)))
523 return 0; 510 return 0;
524 511
525 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)
526 { 513 {
527 /* If there is a counterspell on the space, and this 514 /* If there is a counterspell on the space, and this
528 * object is using magic, don't progress. I believe we could 515 * object is using magic, don't progress. I believe we could
529 * 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
530 * 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
585int 572int
586fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) 573fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
587{ 574{
588 object *tmp; 575 object *tmp;
589 int mflags; 576 int mflags;
590 mapstruct *m; 577 maptile *m;
591 578
592 if (spell->other_arch == NULL) 579 if (spell->other_arch == NULL)
593 return 0; 580 return 0;
594 581
595 m = op->map; 582 m = op->map;
605 return 0; 592 return 0;
606 593
607 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)))
608 { 595 {
609 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");
610 free_object (tmp); 597 tmp->destroy ();
611 return 0; 598 return 0;
612 } 599 }
613
614
615 600
616 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);
617 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); 602 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell);
618 /* 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 */
619 tmp->stats.food = tmp->duration; 604 tmp->stats.food = tmp->duration;
620 tmp->range = spell->range + SP_level_range_adjust (caster, spell); 605 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
621 tmp->attacktype = spell->attacktype; 606 tmp->attacktype = spell->attacktype;
622 tmp->x = x; 607 tmp->x = x;
623 tmp->y = y; 608 tmp->y = y;
624 tmp->direction = dir; 609 tmp->direction = dir;
625 if (get_owner (op) != NULL) 610 if (op->owner != NULL)
626 copy_owner (tmp, op); 611 tmp->set_owner (op);
627 else 612 else
628 set_owner (tmp, op); 613 tmp->set_owner (op);
629 tmp->level = caster_level (caster, spell); 614 tmp->level = caster_level (caster, spell);
630 set_spell_skill (op, caster, spell, tmp); 615 set_spell_skill (op, caster, spell, tmp);
631 616
632 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ 617 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */
633 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 618 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
685 670
686object * 671object *
687find_target_for_friendly_spell (object *op, int dir) 672find_target_for_friendly_spell (object *op, int dir)
688{ 673{
689 object *tmp; 674 object *tmp;
690 mapstruct *m; 675 maptile *m;
691 sint16 x, y; 676 sint16 x, y;
692 int mflags; 677 int mflags;
693 678
694 /* I don't really get this block - if op isn't a player or rune, 679 /* I don't really get this block - if op isn't a player or rune,
695 * we then make the owner of this object the target. 680 * we then make the owner of this object the target.
696 * The owner could very well be no where near op. 681 * The owner could very well be no where near op.
697 */ 682 */
698 if (op->type != PLAYER && op->type != RUNE) 683 if (op->type != PLAYER && op->type != RUNE)
699 { 684 {
700 tmp = get_owner (op); 685 tmp = op->owner;
701 /* 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
702 * to the caster. 687 * to the caster.
703 */ 688 */
704 if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) 689 if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER))
705 tmp = op; 690 tmp = op;
714 699
715 if (mflags & P_OUT_OF_MAP) 700 if (mflags & P_OUT_OF_MAP)
716 tmp = NULL; 701 tmp = NULL;
717 else 702 else
718 { 703 {
719 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)
720 if (tmp->type == PLAYER) 705 if (tmp->type == PLAYER)
721 break; 706 break;
722 } 707 }
723 } 708 }
724 /* 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 */
725 if (tmp == NULL) 710 if (tmp == NULL)
726 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)
727 { 712 {
728 if (tmp->type == PLAYER) 713 if (tmp->type == PLAYER)
729 break; 714 break;
730 } 715 }
731 716
745 * any, otherwise -1. 730 * any, otherwise -1.
746 * note that exclude can be NULL, in which case all bets are off. 731 * note that exclude can be NULL, in which case all bets are off.
747 */ 732 */
748 733
749int 734int
750spell_find_dir (mapstruct *m, int x, int y, object *exclude) 735spell_find_dir (maptile *m, int x, int y, object *exclude)
751{ 736{
752 int i, max = SIZEOFFREE; 737 int i, max = SIZEOFFREE;
753 sint16 nx, ny; 738 sint16 nx, ny;
754 int owner_type = 0, mflags; 739 int owner_type = 0, mflags;
755 object *tmp; 740 object *tmp;
756 mapstruct *mp; 741 maptile *mp;
757 742
758 if (exclude && exclude->head) 743 if (exclude && exclude->head)
759 exclude = exclude->head; 744 exclude = exclude->head;
760 if (exclude && exclude->type) 745 if (exclude && exclude->type)
761 owner_type = exclude->type; 746 owner_type = exclude->type;
767 mp = m; 752 mp = m;
768 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); 753 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny);
769 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) 754 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW))
770 continue; 755 continue;
771 756
772 tmp = get_map_ob (mp, nx, ny); 757 tmp = GET_MAP_OB (mp, nx, ny);
773 758
774 while (tmp != NULL && (((owner_type == PLAYER && 759 while (tmp != NULL && (((owner_type == PLAYER &&
775 !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || 760 !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) ||
776 (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))))
777 tmp = tmp->above; 762 tmp = tmp->above;
796 archetype *at; 781 archetype *at;
797 int dir; 782 int dir;
798 783
799 /* Handle cases where we are passed a bogus mosntername */ 784 /* Handle cases where we are passed a bogus mosntername */
800 785
801 if ((at = find_archetype (monstername)) == NULL) 786 if ((at = archetype::find (monstername)) == NULL)
802 return; 787 return;
803 788
804 /* find a free square nearby 789 /* find a free square nearby
805 * first we check the closest square for free squares 790 * first we check the closest square for free squares
806 */ 791 */
973 if (failure <= -20 && failure > -40) /* wonder */ 958 if (failure <= -20 && failure > -40) /* wonder */
974 { 959 {
975 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);
976 tmp = get_archetype (SPELL_WONDER); 961 tmp = get_archetype (SPELL_WONDER);
977 cast_cone (op, op, 0, tmp); 962 cast_cone (op, op, 0, tmp);
978 free_object (tmp); 963 tmp->destroy ();
979 } 964 }
980 965
981 else if (failure <= -40 && failure > -60) /* confusion */ 966 else if (failure <= -40 && failure > -60) /* confusion */
982 { 967 {
983 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!");
1017 if (failure <= -20 && failure > -40) /* wonder */ 1002 if (failure <= -20 && failure > -40) /* wonder */
1018 { 1003 {
1019 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.");
1020 tmp = get_archetype (SPELL_WONDER); 1005 tmp = get_archetype (SPELL_WONDER);
1021 cast_cone (op, op, 0, tmp); 1006 cast_cone (op, op, 0, tmp);
1022 free_object (tmp); 1007 tmp->destroy ();
1023 } 1008 }
1024 1009
1025 else if (failure <= -40 && failure > -60) /* confusion */ 1010 else if (failure <= -40 && failure > -60) /* confusion */
1026 { 1011 {
1027 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!");
1082 /* Always cast spell on caster */ 1067 /* Always cast spell on caster */
1083 success = cast_spell (op, caster, dir, spell, stringarg); 1068 success = cast_spell (op, caster, dir, spell, stringarg);
1084 1069
1085 if (caster->contr->party == NULL) 1070 if (caster->contr->party == NULL)
1086 { 1071 {
1087 remove_ob (spell); 1072 spell->remove ();
1088 return success; 1073 return success;
1089 } 1074 }
1090 for (pl = first_player; pl != NULL; pl = pl->next) 1075 for (pl = first_player; pl != NULL; pl = pl->next)
1091 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)))
1092 { 1077 {
1093 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); 1078 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg);
1094 } 1079 }
1095 remove_ob (spell); 1080 spell->remove ();
1096 return success; 1081 return success;
1097} 1082}
1098 1083
1099/* This is where the main dispatch when someone casts a spell. 1084/* This is where the main dispatch when someone casts a spell.
1100 * 1085 *
1125 */ 1110 */
1126 1111
1127int 1112int
1128cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 1113cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
1129{ 1114{
1130
1131 const char *godname; 1115 const char *godname;
1132 int success = 0, mflags, cast_level = 0, old_shoottype; 1116 int success = 0, mflags, cast_level = 0, old_shoottype;
1133 object *skill = NULL; 1117 object *skill = NULL;
1134 1118
1135 old_shoottype = op->contr ? op->contr->shoottype : 0; 1119 old_shoottype = op->contr ? op->contr->shoottype : 0;
1137 if (!spell_ob) 1121 if (!spell_ob)
1138 { 1122 {
1139 LOG (llevError, "cast_spell: null spell object passed\n"); 1123 LOG (llevError, "cast_spell: null spell object passed\n");
1140 return 0; 1124 return 0;
1141 } 1125 }
1126
1142 if (!strcmp ((godname = determine_god (op)), "none")) 1127 if (!strcmp ((godname = determine_god (op)), "none"))
1143 godname = "A random spirit"; 1128 godname = "A random spirit";
1144 1129
1145 /* the caller should set caster to op if appropriate */ 1130 /* the caller should set caster to op if appropriate */
1146 if (!caster) 1131 if (!caster)
1150 } 1135 }
1151 1136
1152 /* 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
1153 * an issue, because they don't have any spellpaths set up. 1138 * an issue, because they don't have any spellpaths set up.
1154 */ 1139 */
1155 if (caster->path_denied & spell_ob->path_attuned) 1140 if (caster->path_denied & spell_ob->path_attuned && !QUERY_FLAG (caster, FLAG_WIZCAST))
1156 { 1141 {
1157 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.");
1158 return 0; 1143 return 0;
1159 } 1144 }
1160 1145
1268 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) 1253 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace)
1269 new_draw_info_format (NDI_UNIQUE, 0, op, "This ground is unholy! %s ignores you.", godname); 1254 new_draw_info_format (NDI_UNIQUE, 0, op, "This ground is unholy! %s ignores you.", godname);
1270 else 1255 else
1271 switch (op->contr->shoottype) 1256 switch (op->contr->shoottype)
1272 { 1257 {
1273 case range_magic: 1258 case range_magic:
1274 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your spellcasting."); 1259 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your spellcasting.");
1275 break; 1260 break;
1276 case range_misc: 1261 case range_misc:
1277 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your item."); 1262 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your item.");
1278 break; 1263 break;
1279 case range_golem: 1264 case range_golem:
1280 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your scroll."); 1265 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your scroll.");
1281 break; 1266 break;
1282 default: 1267 default:
1283 break; 1268 break;
1284 } 1269 }
1285 return 0; 1270 return 0;
1286 } 1271 }
1287 1272
1288 if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL) 1273 if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL)
1295 * spell is actually cast, it knows about the stringarg. 1280 * spell is actually cast, it knows about the stringarg.
1296 * necessary for the invoke command spells. 1281 * necessary for the invoke command spells.
1297 */ 1282 */
1298 if (stringarg) 1283 if (stringarg)
1299 { 1284 {
1300 op->spellarg = strdup_local (stringarg); 1285 op->spellarg = strdup (stringarg);
1301 } 1286 }
1302 else 1287 else
1303 op->spellarg = NULL; 1288 op->spellarg = NULL;
1304 return 0; 1289 return 0;
1305 } 1290 }
1362 change_skill (op, skill, 0); /* needed for proper exp credit */ 1347 change_skill (op, skill, 0); /* needed for proper exp credit */
1363 } 1348 }
1364 1349
1365 switch (spell_ob->subtype) 1350 switch (spell_ob->subtype)
1366 { 1351 {
1367 /* The order of case statements is same as the order they show up 1352 /* The order of case statements is same as the order they show up
1368 * in in spells.h. 1353 * in in spells.h.
1369 */ 1354 */
1370 case SP_RAISE_DEAD: 1355 case SP_RAISE_DEAD:
1371 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg); 1356 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg);
1372 break; 1357 break;
1373 1358
1374 case SP_RUNE: 1359 case SP_RUNE:
1375 success = write_rune (op, caster, spell_ob, dir, stringarg); 1360 success = write_rune (op, caster, spell_ob, dir, stringarg);
1376 break; 1361 break;
1377 1362
1378 case SP_MAKE_MARK: 1363 case SP_MAKE_MARK:
1379 success = write_mark (op, spell_ob, stringarg); 1364 success = write_mark (op, spell_ob, stringarg);
1380 break; 1365 break;
1381 1366
1382 case SP_BOLT: 1367 case SP_BOLT:
1383 success = fire_bolt (op, caster, dir, spell_ob, skill); 1368 success = fire_bolt (op, caster, dir, spell_ob, skill);
1384 break; 1369 break;
1385 1370
1386 case SP_BULLET: 1371 case SP_BULLET:
1387 success = fire_bullet (op, caster, dir, spell_ob); 1372 success = fire_bullet (op, caster, dir, spell_ob);
1388 break; 1373 break;
1389 1374
1390 case SP_CONE: 1375 case SP_CONE:
1391 success = cast_cone (op, caster, dir, spell_ob); 1376 success = cast_cone (op, caster, dir, spell_ob);
1392 break; 1377 break;
1393 1378
1394 case SP_BOMB: 1379 case SP_BOMB:
1395 success = create_bomb (op, caster, dir, spell_ob); 1380 success = create_bomb (op, caster, dir, spell_ob);
1396 break; 1381 break;
1397 1382
1398 case SP_WONDER: 1383 case SP_WONDER:
1399 success = cast_wonder (op, caster, dir, spell_ob); 1384 success = cast_wonder (op, caster, dir, spell_ob);
1400 break; 1385 break;
1401 1386
1402 case SP_SMITE: 1387 case SP_SMITE:
1403 success = cast_smite_spell (op, caster, dir, spell_ob); 1388 success = cast_smite_spell (op, caster, dir, spell_ob);
1404 break; 1389 break;
1405 1390
1406 case SP_MAGIC_MISSILE: 1391 case SP_MAGIC_MISSILE:
1392 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob);
1393 break;
1394
1395 case SP_SUMMON_GOLEM:
1396 success = summon_golem (op, caster, dir, spell_ob);
1397 old_shoottype = range_golem;
1398 break;
1399
1400 case SP_DIMENSION_DOOR:
1401 /* dimension door needs the actual caster, because that is what is
1402 * moved.
1403 */
1404 success = dimension_door (op, caster, spell_ob, dir);
1405 break;
1406
1407 case SP_MAGIC_MAPPING:
1408 if (op->type == PLAYER)
1409 {
1410 spell_effect (spell_ob, op->x, op->y, op->map, op);
1411 draw_magic_map (op);
1412 success = 1;
1413 }
1414 else
1415 success = 0;
1416 break;
1417
1418 case SP_MAGIC_WALL:
1419 success = magic_wall (op, caster, dir, spell_ob);
1420 break;
1421
1422 case SP_DESTRUCTION:
1423 success = cast_destruction (op, caster, spell_ob);
1424 break;
1425
1426 case SP_PERCEIVE_SELF:
1427 success = perceive_self (op);
1428 break;
1429
1430 case SP_WORD_OF_RECALL:
1431 success = cast_word_of_recall (op, caster, spell_ob);
1432 break;
1433
1434 case SP_INVISIBLE:
1435 success = cast_invisible (op, caster, spell_ob);
1436 break;
1437
1438 case SP_PROBE:
1439 success = probe (op, caster, spell_ob, dir);
1440 break;
1441
1442 case SP_HEALING:
1443 success = cast_heal (op, caster, spell_ob, dir);
1444 break;
1445
1446 case SP_CREATE_FOOD:
1447 success = cast_create_food (op, caster, spell_ob, dir, stringarg);
1448 break;
1449
1450 case SP_EARTH_TO_DUST:
1451 success = cast_earth_to_dust (op, caster, spell_ob);
1452 break;
1453
1454 case SP_CHANGE_ABILITY:
1455 success = cast_change_ability (op, caster, spell_ob, dir, 0);
1456 break;
1457
1458 case SP_BLESS:
1459 success = cast_bless (op, caster, spell_ob, dir);
1460 break;
1461
1462 case SP_CURSE:
1463 success = cast_curse (op, caster, spell_ob, dir);
1464 break;
1465
1466 case SP_SUMMON_MONSTER:
1467 success = summon_object (op, caster, spell_ob, dir, stringarg);
1468 break;
1469
1470 case SP_CHARGING:
1471 success = recharge (op, caster, spell_ob);
1472 break;
1473
1474 case SP_POLYMORPH:
1475#ifdef NO_POLYMORPH
1476 /* Not great, but at least provide feedback so if players do have
1477 * polymorph (ie, find it as a preset item or left over from before
1478 * it was disabled), they get some feedback.
1479 */
1480 new_draw_info (NDI_UNIQUE, 0, op, "The spell fizzles");
1481 success = 0;
1482#else
1483 success = cast_polymorph (op, caster, spell_ob, dir);
1484#endif
1485 break;
1486
1487 case SP_ALCHEMY:
1488 success = alchemy (op, caster, spell_ob);
1489 break;
1490
1491 case SP_REMOVE_CURSE:
1492 success = remove_curse (op, caster, spell_ob);
1493 break;
1494
1495 case SP_IDENTIFY:
1496 success = cast_identify (op, caster, spell_ob);
1497 break;
1498
1499 case SP_DETECTION:
1500 success = cast_detection (op, caster, spell_ob, skill);
1501 break;
1502
1503 case SP_MOOD_CHANGE:
1504 success = mood_change (op, caster, spell_ob);
1505 break;
1506
1507 case SP_MOVING_BALL:
1508 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled)
1509 {
1510 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the proper attunement to cast %s", &spell_ob->name);
1511 success = 0;
1512 }
1513 else
1407 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1514 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob);
1408 break; 1515 break;
1409 1516
1410 case SP_SUMMON_GOLEM:
1411 success = summon_golem (op, caster, dir, spell_ob);
1412 old_shoottype = range_golem;
1413 break;
1414
1415 case SP_DIMENSION_DOOR:
1416 /* dimension door needs the actual caster, because that is what is
1417 * moved.
1418 */
1419 success = dimension_door (op, caster, spell_ob, dir);
1420 break;
1421
1422 case SP_MAGIC_MAPPING:
1423 if (op->type == PLAYER)
1424 {
1425 spell_effect (spell_ob, op->x, op->y, op->map, op);
1426 draw_magic_map (op);
1427 success = 1;
1428 }
1429 else
1430 success = 0;
1431 break;
1432
1433 case SP_MAGIC_WALL:
1434 success = magic_wall (op, caster, dir, spell_ob);
1435 break;
1436
1437 case SP_DESTRUCTION:
1438 success = cast_destruction (op, caster, spell_ob);
1439 break;
1440
1441 case SP_PERCEIVE_SELF:
1442 success = perceive_self (op);
1443 break;
1444
1445 case SP_WORD_OF_RECALL:
1446 success = cast_word_of_recall (op, caster, spell_ob);
1447 break;
1448
1449 case SP_INVISIBLE:
1450 success = cast_invisible (op, caster, spell_ob);
1451 break;
1452
1453 case SP_PROBE:
1454 success = probe (op, caster, spell_ob, dir);
1455 break;
1456
1457 case SP_HEALING:
1458 success = cast_heal (op, caster, spell_ob, dir);
1459 break;
1460
1461 case SP_CREATE_FOOD:
1462 success = cast_create_food (op, caster, spell_ob, dir, stringarg);
1463 break;
1464
1465 case SP_EARTH_TO_DUST:
1466 success = cast_earth_to_dust (op, caster, spell_ob);
1467 break;
1468
1469 case SP_CHANGE_ABILITY:
1470 success = cast_change_ability (op, caster, spell_ob, dir, 0);
1471 break;
1472
1473 case SP_BLESS:
1474 success = cast_bless (op, caster, spell_ob, dir);
1475 break;
1476
1477 case SP_CURSE:
1478 success = cast_curse (op, caster, spell_ob, dir);
1479 break;
1480
1481 case SP_SUMMON_MONSTER:
1482 success = summon_object (op, caster, spell_ob, dir, stringarg);
1483 break;
1484
1485 case SP_CHARGING:
1486 success = recharge (op, caster, spell_ob);
1487 break;
1488
1489 case SP_POLYMORPH:
1490#ifdef NO_POLYMORPH
1491 /* Not great, but at least provide feedback so if players do have
1492 * polymorph (ie, find it as a preset item or left over from before
1493 * it was disabled), they get some feedback.
1494 */
1495 new_draw_info (NDI_UNIQUE, 0, op, "The spell fizzles");
1496 success = 0;
1497#else
1498 success = cast_polymorph (op, caster, spell_ob, dir);
1499#endif
1500 break;
1501
1502 case SP_ALCHEMY:
1503 success = alchemy (op, caster, spell_ob);
1504 break;
1505
1506 case SP_REMOVE_CURSE:
1507 success = remove_curse (op, caster, spell_ob);
1508 break;
1509
1510 case SP_IDENTIFY:
1511 success = cast_identify (op, caster, spell_ob);
1512 break;
1513
1514 case SP_DETECTION:
1515 success = cast_detection (op, caster, spell_ob, skill);
1516 break;
1517
1518 case SP_MOOD_CHANGE:
1519 success = mood_change (op, caster, spell_ob);
1520 break;
1521
1522 case SP_MOVING_BALL:
1523 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled)
1524 {
1525 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the proper attunement to cast %s", &spell_ob->name);
1526 success = 0;
1527 }
1528 else
1529 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob);
1530 break;
1531
1532 case SP_SWARM: 1517 case SP_SWARM:
1533 success = fire_swarm (op, caster, spell_ob, dir); 1518 success = fire_swarm (op, caster, spell_ob, dir);
1534 break; 1519 break;
1535 1520
1536 case SP_CHANGE_MANA: 1521 case SP_CHANGE_MANA:
1537 success = cast_transfer (op, caster, spell_ob, dir); 1522 success = cast_transfer (op, caster, spell_ob, dir);
1538 break; 1523 break;
1539 1524
1540 case SP_DISPEL_RUNE: 1525 case SP_DISPEL_RUNE:
1541 /* in rune.c */ 1526 /* in rune.c */
1542 success = dispel_rune (op, caster, spell_ob, skill, dir); 1527 success = dispel_rune (op, caster, spell_ob, skill, dir);
1543 break; 1528 break;
1544 1529
1545 case SP_CREATE_MISSILE: 1530 case SP_CREATE_MISSILE:
1546 success = cast_create_missile (op, caster, spell_ob, dir, stringarg); 1531 success = cast_create_missile (op, caster, spell_ob, dir, stringarg);
1547 break; 1532 break;
1548 1533
1549 case SP_CONSECRATE: 1534 case SP_CONSECRATE:
1550 success = cast_consecrate (op, caster, spell_ob); 1535 success = cast_consecrate (op, caster, spell_ob);
1551 break; 1536 break;
1552 1537
1553 case SP_ANIMATE_WEAPON: 1538 case SP_ANIMATE_WEAPON:
1554 success = animate_weapon (op, caster, spell_ob, dir); 1539 success = animate_weapon (op, caster, spell_ob, dir);
1555 old_shoottype = range_golem; 1540 old_shoottype = range_golem;
1556 break; 1541 break;
1557 1542
1558 case SP_LIGHT: 1543 case SP_LIGHT:
1559 success = cast_light (op, caster, spell_ob, dir); 1544 success = cast_light (op, caster, spell_ob, dir);
1560 break; 1545 break;
1561 1546
1562 case SP_CHANGE_MAP_LIGHT: 1547 case SP_CHANGE_MAP_LIGHT:
1563 success = cast_change_map_lightlevel (op, caster, spell_ob); 1548 success = cast_change_map_lightlevel (op, caster, spell_ob);
1564 break; 1549 break;
1565 1550
1566 case SP_FAERY_FIRE: 1551 case SP_FAERY_FIRE:
1567 success = cast_destruction (op, caster, spell_ob); 1552 success = cast_destruction (op, caster, spell_ob);
1568 break; 1553 break;
1569 1554
1570 case SP_CAUSE_DISEASE: 1555 case SP_CAUSE_DISEASE:
1571 success = cast_cause_disease (op, caster, spell_ob, dir); 1556 success = cast_cause_disease (op, caster, spell_ob, dir);
1572 break; 1557 break;
1573 1558
1574 case SP_AURA: 1559 case SP_AURA:
1575 success = create_aura (op, caster, spell_ob); 1560 success = create_aura (op, caster, spell_ob);
1576 break; 1561 break;
1577 1562
1578 case SP_TOWN_PORTAL: 1563 case SP_TOWN_PORTAL:
1579 success = cast_create_town_portal (op, caster, spell_ob, dir); 1564 success = cast_create_town_portal (op, caster, spell_ob, dir);
1580 break; 1565 break;
1581 1566
1582 case SP_PARTY_SPELL: 1567 case SP_PARTY_SPELL:
1583 success = cast_party_spell (op, caster, dir, spell_ob, stringarg); 1568 success = cast_party_spell (op, caster, dir, spell_ob, stringarg);
1584 break; 1569 break;
1585 1570
1586 default: 1571 default:
1587 if (!INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (stringarg))) 1572 if (!INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (stringarg)))
1588 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); 1573 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1589
1590
1591 } 1574 }
1592 1575
1593 /* FIXME - we need some better sound suppport */ 1576 /* FIXME - we need some better sound suppport */
1594 // yes, for example, augment map info with the spell effect 1577 // yes, for example, augment map info with the spell effect
1595 // so clients can calculate the sounds themselves 1578 // so clients can calculate the sounds themselves
1617 * then dispatches them to the appropriate specific routines. 1600 * then dispatches them to the appropriate specific routines.
1618 */ 1601 */
1619void 1602void
1620move_spell_effect (object *op) 1603move_spell_effect (object *op)
1621{ 1604{
1622
1623 switch (op->subtype) 1605 switch (op->subtype)
1624 { 1606 {
1625 case SP_BOLT: 1607 case SP_BOLT:
1626 move_bolt (op); 1608 move_bolt (op);
1627 break; 1609 break;
1628 1610
1629 case SP_BULLET: 1611 case SP_BULLET:
1630 move_bullet (op); 1612 move_bullet (op);
1631 break; 1613 break;
1632 1614
1633 case SP_EXPLOSION: 1615 case SP_EXPLOSION:
1634 explosion (op); 1616 explosion (op);
1635 break; 1617 break;
1636 1618
1637 case SP_CONE: 1619 case SP_CONE:
1638 move_cone (op); 1620 move_cone (op);
1639 break; 1621 break;
1640 1622
1641 case SP_BOMB: 1623 case SP_BOMB:
1642 animate_bomb (op); 1624 animate_bomb (op);
1643 break; 1625 break;
1644 1626
1645 case SP_MAGIC_MISSILE: 1627 case SP_MAGIC_MISSILE:
1646 move_missile (op); 1628 move_missile (op);
1647 break; 1629 break;
1648 1630
1649 case SP_WORD_OF_RECALL: 1631 case SP_WORD_OF_RECALL:
1650 execute_word_of_recall (op); 1632 execute_word_of_recall (op);
1651 break; 1633 break;
1652 1634
1653 case SP_MOVING_BALL: 1635 case SP_MOVING_BALL:
1654 move_ball_spell (op); 1636 move_ball_spell (op);
1655 break; 1637 break;
1656 1638
1657 case SP_SWARM: 1639 case SP_SWARM:
1658 move_swarm_spell (op); 1640 move_swarm_spell (op);
1659 break; 1641 break;
1660 1642
1661 case SP_AURA: 1643 case SP_AURA:
1662 move_aura (op); 1644 move_aura (op);
1663 break; 1645 break;
1664
1665 } 1646 }
1666} 1647}
1667 1648
1668/* this checks to see if something special should happen if 1649/* this checks to see if something special should happen if
1669 * something runs into the object. 1650 * something runs into the object.
1670 */ 1651 */
1671void 1652void
1672check_spell_effect (object *op) 1653check_spell_effect (object *op)
1673{ 1654{
1674
1675 switch (op->subtype) 1655 switch (op->subtype)
1676 { 1656 {
1677 case SP_BOLT: 1657 case SP_BOLT:
1678 move_bolt (op); 1658 move_bolt (op);
1679 return; 1659 return;
1680 1660
1681 case SP_BULLET: 1661 case SP_BULLET:
1682 check_bullet (op); 1662 check_bullet (op);
1683 return; 1663 return;
1684 } 1664 }
1685
1686} 1665}
1687 1666
1688/* This is called by move_apply. Basically, if someone 1667/* This is called by move_apply. Basically, if someone
1689 * moves onto a spell effect and the walk_on or fly_on flags 1668 * moves onto a spell effect and the walk_on or fly_on flags
1690 * are set, this is called. This should only be called for 1669 * are set, this is called. This should only be called for
1693void 1672void
1694apply_spell_effect (object *spell, object *victim) 1673apply_spell_effect (object *spell, object *victim)
1695{ 1674{
1696 switch (spell->subtype) 1675 switch (spell->subtype)
1697 { 1676 {
1698 case SP_CONE: 1677 case SP_CONE:
1699 if (QUERY_FLAG (victim, FLAG_ALIVE) && spell->speed && spell->attacktype) 1678 if (QUERY_FLAG (victim, FLAG_ALIVE) && spell->speed && spell->attacktype)
1700 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 0); 1679 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 0);
1701 break; 1680 break;
1702 1681
1703 case SP_MAGIC_MISSILE: 1682 case SP_MAGIC_MISSILE:
1704 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1683 if (QUERY_FLAG (victim, FLAG_ALIVE))
1705 { 1684 {
1706 tag_t spell_tag = spell->count;
1707
1708 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1709 if (!was_destroyed (spell, spell_tag))
1710 {
1711 remove_ob (spell);
1712 free_object (spell);
1713 }
1714 }
1715 break;
1716
1717 case SP_MOVING_BALL:
1718 if (QUERY_FLAG (victim, FLAG_ALIVE))
1719 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1685 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1686
1687 if (!spell->destroyed ())
1688 spell->destroy ();
1689 }
1690 break;
1691
1692 case SP_MOVING_BALL:
1693 if (QUERY_FLAG (victim, FLAG_ALIVE))
1694 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1720 else if (victim->material || victim->materialname) 1695 else if (victim->material || victim->materialname)
1721 save_throw_object (victim, spell->attacktype, spell); 1696 save_throw_object (victim, spell->attacktype, spell);
1722 break; 1697 break;
1723 } 1698 }
1724} 1699}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines