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.24 by root, Wed Dec 20 09:14:22 2006 UTC vs.
Revision 1.30 by root, Sun Dec 31 19:02:24 2006 UTC

24 24
25#include <global.h> 25#include <global.h>
26#include <spells.h> 26#include <spells.h>
27#include <object.h> 27#include <object.h>
28#include <errno.h> 28#include <errno.h>
29#ifndef __CEXTRACT__
30# include <sproto.h> 29#include <sproto.h>
31#endif
32#include <sounds.h> 30#include <sounds.h>
33 31
34extern char *spell_mapping[]; 32extern char *spell_mapping[];
35 33
36/* This returns a random spell from 'ob'. If skill is set, then 34/* This returns a random spell from 'ob'. If skill is set, then
151} 149}
152 150
153/* pretty basic function - basically just takes 151/* pretty basic function - basically just takes
154 * an object, sets the x,y, and calls insert_ob_in_map 152 * an object, sets the x,y, and calls insert_ob_in_map
155 */ 153 */
156
157void 154void
158spell_effect (object *spob, int x, int y, maptile *map, object *originator) 155spell_effect (object *spob, int x, int y, maptile *map, object *originator)
159{ 156{
160
161 if (spob->other_arch != NULL) 157 if (spob->other_arch)
162 { 158 map->insert (arch_to_object (spob->other_arch), x, y, originator);
163 object *effect = arch_to_object (spob->other_arch);
164
165 effect->x = x;
166 effect->y = y;
167
168 insert_ob_in_map (effect, map, originator, 0);
169 }
170} 159}
171 160
172/* 161/*
173 * This function takes a caster and spell and presents the 162 * This function takes a caster and spell and presents the
174 * effective level the caster needs to be to cast the spell. 163 * effective level the caster needs to be to cast the spell.
175 * basically, it just adjusts the spell->level with attuned/repelled 164 * basically, it just adjusts the spell->level with attuned/repelled
176 * spellpaths. Was called path_level_mod 165 * spellpaths. Was called path_level_mod.
177 * 166 *
178 * caster is person casting hte spell. 167 * caster is person casting the spell.
179 * spell is the spell object. 168 * spell is the spell object.
180 * Returns modified level. 169 * Returns modified level.
181 */ 170 */
182int 171int
183min_casting_level (object *caster, object *spell) 172min_casting_level (object *caster, object *spell)
186 175
187 if (caster->path_denied & spell->path_attuned) 176 if (caster->path_denied & spell->path_attuned)
188 return 1; 177 return 1;
189 178
190 new_level = spell->level 179 new_level = spell->level
191 + ((caster->path_repelled & spell->path_attuned) ? +2 : 0) + ((caster->path_attuned & spell->path_attuned) ? -2 : 0); 180 + (caster->path_repelled & spell->path_attuned ? +2 : 0)
181 + (caster->path_attuned & spell->path_attuned ? -2 : 0);
192 182
193 return (new_level < 1) ? 1 : new_level; 183 return max (1, new_level);
194} 184}
195
196 185
197/* This function returns the effective level the spell 186/* This function returns the effective level the spell
198 * is being cast at. 187 * is being cast at.
199 * Note that I changed the repelled/attuned bonus to 2 from 5. 188 * Note that I changed the repelled/attuned bonus to 2 from 5.
200 * This is because the new code compares casting_level against 189 * This is because the new code compares casting_level against
444 if (OUT_OF_REAL_MAP (m, x, y)) 433 if (OUT_OF_REAL_MAP (m, x, y))
445 return 0; 434 return 0;
446 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) 435 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above)
447 if (QUERY_FLAG (op, FLAG_REFL_SPELL) 436 if (QUERY_FLAG (op, FLAG_REFL_SPELL)
448 && (!QUERY_FLAG (op, FLAG_ALIVE) 437 && (!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))) 438 || (rndm (0, 99)) < 90 - (sp_op->level / 10)))
452 return 1; 439 return 1;
453 440
454 return 0; 441 return 0;
455} 442}
473 { 460 {
474 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 461 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
475 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); 462 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet.");
476 dir = 0; 463 dir = 0;
477 } 464 }
478 new_op->x = op->x + freearr_x[dir]; 465
479 new_op->y = op->y + freearr_y[dir]; 466 op->map->insert (new_op,
480 if (dir == 0) 467 op->x + freearr_x[dir], op->y + freearr_y[dir],
481 insert_ob_in_map (new_op, op->map, op, INS_BELOW_ORIGINATOR); 468 op,
482 else 469 dir ? 0 : INS_BELOW_ORIGINATOR);
483 insert_ob_in_map (new_op, op->map, op, 0); 470
484 return dir; 471 return dir;
485} 472}
486 473
487/* Returns true if it is ok to put spell *op on the space/may provided. 474/* Returns true if it is ok to put spell *op on the space/may provided.
488 * immune_stop is basically the attacktype of the spell (why 475 * immune_stop is basically the attacktype of the spell (why
621 return 0; 608 return 0;
622 } 609 }
623 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) 610 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
624 SET_ANIMATION (tmp, dir); 611 SET_ANIMATION (tmp, dir);
625 612
626 if ((tmp = insert_ob_in_map (tmp, m, op, 0)) == NULL) 613 if ((tmp = insert_ob_in_map (tmp, m, op, 0)))
627 return 1;
628
629 move_spell_effect (tmp); 614 move_spell_effect (tmp);
630 615
631 return 1; 616 return 1;
632} 617}
633
634
635 618
636/***************************************************************************** 619/*****************************************************************************
637 * 620 *
638 * Code related to rods - perhaps better located in another file? 621 * Code related to rods - perhaps better located in another file?
639 * 622 *
640 ****************************************************************************/ 623 ****************************************************************************/
641
642void 624void
643regenerate_rod (object *rod) 625regenerate_rod (object *rod)
644{ 626{
645 if (rod->stats.hp < rod->stats.maxhp) 627 if (rod->stats.hp < rod->stats.maxhp)
646 { 628 {
696 y = op->y + freearr_y[dir]; 678 y = op->y + freearr_y[dir];
697 679
698 mflags = get_map_flags (m, &m, x, y, &x, &y); 680 mflags = get_map_flags (m, &m, x, y, &x, &y);
699 681
700 if (mflags & P_OUT_OF_MAP) 682 if (mflags & P_OUT_OF_MAP)
701 tmp = NULL; 683 tmp = 0;
702 else 684 else
703 { 685 tmp = m->at (x, y).player ();
704 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
705 if (tmp->type == PLAYER)
706 break;
707 }
708 } 686 }
687
709 /* didn't find a player there, look in current square for a player */ 688 /* didn't find a player there, look in current square for a player */
710 if (tmp == NULL) 689 if (!tmp)
711 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 690 tmp = op->ms ().player ();
712 {
713 if (tmp->type == PLAYER)
714 break;
715 }
716 691
717 return tmp; 692 return tmp;
718} 693}
719 694
720 695
817 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 792 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
818 793
819 insert_ob_in_map (head, op->map, op, 0); 794 insert_ob_in_map (head, op->map, op, 0);
820 795
821 /* thought it'd be cool to insert a burnout, too. */ 796 /* thought it'd be cool to insert a burnout, too. */
822 tmp = get_archetype ("burnout"); 797 op->map->insert (get_archetype ("burnout"), op->x + freearr_x[dir], op->y + freearr_y[dir], op);
823 tmp->map = op->map;
824 tmp->x = op->x + freearr_x[dir];
825 tmp->y = op->y + freearr_y[dir];
826 insert_ob_in_map (tmp, op->map, op, 0);
827 } 798 }
828} 799}
829 800
830/* peterm: function which summons hostile monsters and 801/* peterm: function which summons hostile monsters and
831 * places them in nearby squares. 802 * places them in nearby squares.
1031 else 1002 else
1032 { 1003 {
1033 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); 1004 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!");
1034 tmp = get_archetype (LOOSE_MANA); 1005 tmp = get_archetype (LOOSE_MANA);
1035 tmp->level = skill->level; 1006 tmp->level = skill->level;
1036 tmp->x = op->x;
1037 tmp->y = op->y;
1038 1007
1039 /* increase the area of destruction a little for more powerful spells */ 1008 /* increase the area of destruction a little for more powerful spells */
1040 tmp->range += isqrt (power); 1009 tmp->range += isqrt (power);
1041 1010
1042 if (power > 25) 1011 if (power > 25)
1043 tmp->stats.dam = 25 + isqrt (power); 1012 tmp->stats.dam = 25 + isqrt (power);
1044 else 1013 else
1045 tmp->stats.dam = power; /* nasty recoils! */ 1014 tmp->stats.dam = power; /* nasty recoils! */
1046 1015
1047 tmp->stats.maxhp = tmp->count; 1016 tmp->stats.maxhp = tmp->count;
1048 insert_ob_in_map (tmp, op->map, NULL, 0); 1017
1018 tmp->insert_at (op);
1049 } 1019 }
1050 } 1020 }
1051} 1021}
1052 1022
1053int 1023int
1070 if (caster->contr->party == NULL) 1040 if (caster->contr->party == NULL)
1071 { 1041 {
1072 spell->remove (); 1042 spell->remove ();
1073 return success; 1043 return success;
1074 } 1044 }
1075 for (pl = first_player; pl != NULL; pl = pl->next) 1045 for_all_players (pl)
1076 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) 1046 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster)))
1077 { 1047 {
1078 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); 1048 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg);
1079 } 1049 }
1080 spell->remove (); 1050 spell->remove ();
1178 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1148 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1179 { 1149 {
1180 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 1150 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
1181 return 0; 1151 return 0;
1182 } 1152 }
1153
1183 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && 1154 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) &&
1184 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) 1155 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace)
1185 { 1156 {
1186 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - 1157 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace -
1187 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) 1158 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines