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.27 by root, Mon Dec 25 11:25:50 2006 UTC vs.
Revision 1.33 by root, Mon Jan 15 01:25:41 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 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
24 25
25#include <global.h> 26#include <global.h>
26#include <spells.h> 27#include <spells.h>
27#include <object.h> 28#include <object.h>
28#include <errno.h> 29#include <errno.h>
29#ifndef __CEXTRACT__
30# include <sproto.h> 30#include <sproto.h>
31#endif
32#include <sounds.h> 31#include <sounds.h>
33 32
34extern char *spell_mapping[]; 33extern char *spell_mapping[];
35 34
36/* This returns a random spell from 'ob'. If skill is set, then 35/* This returns a random spell from 'ob'. If skill is set, then
151} 150}
152 151
153/* pretty basic function - basically just takes 152/* pretty basic function - basically just takes
154 * an object, sets the x,y, and calls insert_ob_in_map 153 * an object, sets the x,y, and calls insert_ob_in_map
155 */ 154 */
156
157void 155void
158spell_effect (object *spob, int x, int y, maptile *map, object *originator) 156spell_effect (object *spob, int x, int y, maptile *map, object *originator)
159{ 157{
160
161 if (spob->other_arch != NULL) 158 if (spob->other_arch)
162 { 159 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} 160}
171 161
172/* 162/*
173 * This function takes a caster and spell and presents the 163 * This function takes a caster and spell and presents the
174 * effective level the caster needs to be to cast the spell. 164 * effective level the caster needs to be to cast the spell.
175 * basically, it just adjusts the spell->level with attuned/repelled 165 * basically, it just adjusts the spell->level with attuned/repelled
176 * spellpaths. Was called path_level_mod 166 * spellpaths. Was called path_level_mod.
177 * 167 *
178 * caster is person casting hte spell. 168 * caster is person casting the spell.
179 * spell is the spell object. 169 * spell is the spell object.
180 * Returns modified level. 170 * Returns modified level.
181 */ 171 */
182int 172int
183min_casting_level (object *caster, object *spell) 173min_casting_level (object *caster, object *spell)
186 176
187 if (caster->path_denied & spell->path_attuned) 177 if (caster->path_denied & spell->path_attuned)
188 return 1; 178 return 1;
189 179
190 new_level = spell->level 180 new_level = spell->level
191 + ((caster->path_repelled & spell->path_attuned) ? +2 : 0) + ((caster->path_attuned & spell->path_attuned) ? -2 : 0); 181 + (caster->path_repelled & spell->path_attuned ? +2 : 0)
182 + (caster->path_attuned & spell->path_attuned ? -2 : 0);
192 183
193 return (new_level < 1) ? 1 : new_level; 184 return max (1, new_level);
194} 185}
195
196 186
197/* This function returns the effective level the spell 187/* This function returns the effective level the spell
198 * is being cast at. 188 * is being cast at.
199 * Note that I changed the repelled/attuned bonus to 2 from 5. 189 * Note that I changed the repelled/attuned bonus to 2 from 5.
200 * This is because the new code compares casting_level against 190 * This is because the new code compares casting_level against
471 { 461 {
472 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 462 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
473 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); 463 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet.");
474 dir = 0; 464 dir = 0;
475 } 465 }
476 new_op->x = op->x + freearr_x[dir]; 466
477 new_op->y = op->y + freearr_y[dir]; 467 op->map->insert (new_op,
478 if (dir == 0) 468 op->x + freearr_x[dir], op->y + freearr_y[dir],
479 insert_ob_in_map (new_op, op->map, op, INS_BELOW_ORIGINATOR); 469 op,
480 else 470 dir ? 0 : INS_BELOW_ORIGINATOR);
481 insert_ob_in_map (new_op, op->map, op, 0); 471
482 return dir; 472 return dir;
483} 473}
484 474
485/* Returns true if it is ok to put spell *op on the space/may provided. 475/* Returns true if it is ok to put spell *op on the space/may provided.
486 * immune_stop is basically the attacktype of the spell (why 476 * immune_stop is basically the attacktype of the spell (why
488 * has the AT_MAGIC bit set, and there is a counterwall 478 * has the AT_MAGIC bit set, and there is a counterwall
489 * on the space, the object doesn't get placed. if immune stop 479 * on the space, the object doesn't get placed. if immune stop
490 * does not have AT_MAGIC, then counterwalls do not effect the spell. 480 * does not have AT_MAGIC, then counterwalls do not effect the spell.
491 * 481 *
492 */ 482 */
493
494int 483int
495ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) 484ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop)
496{ 485{
497 object *tmp; 486 if (!xy_normalise (m, x, y))
498 int mflags;
499 maptile *mp;
500
501 mp = m;
502 mflags = get_map_flags (m, &mp, x, y, &x, &y);
503
504 if (mflags & P_OUT_OF_MAP)
505 return 0; 487 return 0;
506 488
507 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (mp, x, y))) 489 mapspace &ms = m->at (x, y);
490
491 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block))
508 return 0; 492 return 0;
509 493
510 for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above) 494 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
511 { 495 {
512 /* If there is a counterspell on the space, and this 496 /* If there is a counterspell on the space, and this
513 * object is using magic, don't progress. I believe we could 497 * object is using magic, don't progress. I believe we could
514 * leave this out and let in progress, and other areas of the code 498 * leave this out and let in progress, and other areas of the code
515 * will then remove it, but that would seem to to use more 499 * will then remove it, but that would seem to to use more
538 * playability reasons. 522 * playability reasons.
539 */ 523 */
540 if (tmp->arch == op->arch 524 if (tmp->arch == op->arch
541 && tmp->type == op->type 525 && tmp->type == op->type
542 && tmp->subtype == op->subtype 526 && tmp->subtype == op->subtype
527 && tmp->owner == op->owner
543 && tmp->owner == op->owner && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) 528 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
544 { 529 {
545 tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); 530 tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam);
546 tmp->range = MAX (tmp->range, op->range); 531 tmp->range = MAX (tmp->range, op->range);
547 tmp->duration = MAX (tmp->duration, op->duration); 532 tmp->duration = MAX (tmp->duration, op->duration);
548 return 0; 533 return 0;
550 535
551 /* Perhaps we should also put checks in for no magic and unholy 536 /* Perhaps we should also put checks in for no magic and unholy
552 * ground to prevent it from moving along? 537 * ground to prevent it from moving along?
553 */ 538 */
554 } 539 }
540
555 /* If it passes the above tests, it must be OK */ 541 /* If it passes the above tests, it must be OK */
556 return 1; 542 return 1;
557} 543}
558 544
559/* fire_arch_from_position: fires an archetype. 545/* fire_arch_from_position: fires an archetype.
619 return 0; 605 return 0;
620 } 606 }
621 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) 607 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
622 SET_ANIMATION (tmp, dir); 608 SET_ANIMATION (tmp, dir);
623 609
624 if ((tmp = insert_ob_in_map (tmp, m, op, 0)) == NULL) 610 if ((tmp = insert_ob_in_map (tmp, m, op, 0)))
625 return 1;
626
627 move_spell_effect (tmp); 611 move_spell_effect (tmp);
628 612
629 return 1; 613 return 1;
630} 614}
631
632
633 615
634/***************************************************************************** 616/*****************************************************************************
635 * 617 *
636 * Code related to rods - perhaps better located in another file? 618 * Code related to rods - perhaps better located in another file?
637 * 619 *
638 ****************************************************************************/ 620 ****************************************************************************/
639
640void 621void
641regenerate_rod (object *rod) 622regenerate_rod (object *rod)
642{ 623{
643 if (rod->stats.hp < rod->stats.maxhp) 624 if (rod->stats.hp < rod->stats.maxhp)
644 { 625 {
808 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 789 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
809 790
810 insert_ob_in_map (head, op->map, op, 0); 791 insert_ob_in_map (head, op->map, op, 0);
811 792
812 /* thought it'd be cool to insert a burnout, too. */ 793 /* thought it'd be cool to insert a burnout, too. */
813 tmp = get_archetype ("burnout"); 794 op->map->insert (get_archetype ("burnout"), op->x + freearr_x[dir], op->y + freearr_y[dir], op);
814 tmp->map = op->map;
815 tmp->x = op->x + freearr_x[dir];
816 tmp->y = op->y + freearr_y[dir];
817 insert_ob_in_map (tmp, op->map, op, 0);
818 } 795 }
819} 796}
820 797
821/* peterm: function which summons hostile monsters and 798/* peterm: function which summons hostile monsters and
822 * places them in nearby squares. 799 * places them in nearby squares.
1022 else 999 else
1023 { 1000 {
1024 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); 1001 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!");
1025 tmp = get_archetype (LOOSE_MANA); 1002 tmp = get_archetype (LOOSE_MANA);
1026 tmp->level = skill->level; 1003 tmp->level = skill->level;
1027 tmp->x = op->x;
1028 tmp->y = op->y;
1029 1004
1030 /* increase the area of destruction a little for more powerful spells */ 1005 /* increase the area of destruction a little for more powerful spells */
1031 tmp->range += isqrt (power); 1006 tmp->range += isqrt (power);
1032 1007
1033 if (power > 25) 1008 if (power > 25)
1034 tmp->stats.dam = 25 + isqrt (power); 1009 tmp->stats.dam = 25 + isqrt (power);
1035 else 1010 else
1036 tmp->stats.dam = power; /* nasty recoils! */ 1011 tmp->stats.dam = power; /* nasty recoils! */
1037 1012
1038 tmp->stats.maxhp = tmp->count; 1013 tmp->stats.maxhp = tmp->count;
1039 insert_ob_in_map (tmp, op->map, NULL, 0); 1014
1015 tmp->insert_at (op);
1040 } 1016 }
1041 } 1017 }
1042} 1018}
1043 1019
1044int 1020int
1169 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1145 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1170 { 1146 {
1171 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 1147 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
1172 return 0; 1148 return 0;
1173 } 1149 }
1150
1174 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && 1151 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) &&
1175 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) 1152 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace)
1176 { 1153 {
1177 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - 1154 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace -
1178 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) 1155 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines