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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | 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 |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
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> |
… | |
… | |
187 | * is being cast at. |
188 | * is being cast at. |
188 | * 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. |
189 | * This is because the new code compares casting_level against |
190 | * This is because the new code compares casting_level against |
190 | * min_caster_level, so the difference is effectively 4 |
191 | * min_caster_level, so the difference is effectively 4 |
191 | */ |
192 | */ |
192 | |
|
|
193 | int |
193 | int |
194 | caster_level (object *caster, object *spell) |
194 | caster_level (object *caster, object *spell) |
195 | { |
195 | { |
196 | int level = caster->level; |
196 | int level = caster->level; |
197 | |
197 | |
… | |
… | |
212 | |
212 | |
213 | level = MIN (level, sk_level + level / 10 + 1); |
213 | level = MIN (level, sk_level + level / 10 + 1); |
214 | } |
214 | } |
215 | |
215 | |
216 | /* Got valid caster level. Now adjust for attunement */ |
216 | /* Got valid caster level. Now adjust for attunement */ |
217 | level += ((caster->path_repelled & spell->path_attuned) ? -2 : 0) + ((caster->path_attuned & spell->path_attuned) ? 2 : 0); |
217 | level += caster->path_repelled & spell->path_attuned ? -2 : 0; |
|
|
218 | level += caster->path_attuned & spell->path_attuned ? +2 : 0; |
218 | |
219 | |
219 | /* Always make this at least 1. If this is zero, we get divide by zero |
220 | /* Always make this at least 1. If this is zero, we get divide by zero |
220 | * errors in various places. |
221 | * errors in various places. |
221 | */ |
222 | */ |
222 | if (level < 1) |
|
|
223 | level = 1; |
|
|
224 | |
|
|
225 | return level; |
223 | return max (level, 1); |
226 | } |
224 | } |
227 | |
225 | |
228 | /* The following function scales the spellpoint cost of |
226 | /* The following function scales the spellpoint cost of |
229 | * a spell by it's increased effectiveness. Some of the |
227 | * a spell by it's increased effectiveness. Some of the |
230 | * lower level spells become incredibly vicious at high |
228 | * lower level spells become incredibly vicious at high |
… | |
… | |
477 | * has the AT_MAGIC bit set, and there is a counterwall |
475 | * has the AT_MAGIC bit set, and there is a counterwall |
478 | * on the space, the object doesn't get placed. if immune stop |
476 | * on the space, the object doesn't get placed. if immune stop |
479 | * does not have AT_MAGIC, then counterwalls do not effect the spell. |
477 | * does not have AT_MAGIC, then counterwalls do not effect the spell. |
480 | * |
478 | * |
481 | */ |
479 | */ |
482 | |
|
|
483 | int |
480 | int |
484 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
481 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
485 | { |
482 | { |
486 | object *tmp; |
483 | if (!xy_normalise (m, x, y)) |
487 | int mflags; |
|
|
488 | maptile *mp; |
|
|
489 | |
|
|
490 | mp = m; |
|
|
491 | mflags = get_map_flags (m, &mp, x, y, &x, &y); |
|
|
492 | |
|
|
493 | if (mflags & P_OUT_OF_MAP) |
|
|
494 | return 0; |
484 | return 0; |
495 | |
485 | |
496 | if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (mp, x, y))) |
486 | mapspace &ms = m->at (x, y); |
|
|
487 | |
|
|
488 | if (OB_TYPE_MOVE_BLOCK (op, ms.move_block)) |
497 | return 0; |
489 | return 0; |
498 | |
490 | |
499 | for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above) |
491 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
500 | { |
492 | { |
501 | /* If there is a counterspell on the space, and this |
493 | /* If there is a counterspell on the space, and this |
502 | * object is using magic, don't progress. I believe we could |
494 | * object is using magic, don't progress. I believe we could |
503 | * leave this out and let in progress, and other areas of the code |
495 | * leave this out and let in progress, and other areas of the code |
504 | * will then remove it, but that would seem to to use more |
496 | * will then remove it, but that would seem to to use more |
505 | * resources, and may not work as well if a player is standing |
497 | * resources, and may not work as well if a player is standing |
506 | * on top of a counterwall spell (may hit the player before being |
498 | * on top of a counterwall spell (may hit the player before being |
507 | * removed.) On the other hand, it may be more dramatic for the |
499 | * removed.) On the other hand, it may be more dramatic for the |
508 | * spell to actually hit the counterwall and be sucked up. |
500 | * spell to actually hit the counterwall and be sucked up. |
509 | */ |
501 | */ |
510 | if ((tmp->attacktype & AT_COUNTERSPELL) && |
502 | if ((tmp->attacktype & AT_COUNTERSPELL) |
511 | (tmp->type != PLAYER) && !QUERY_FLAG (tmp, FLAG_MONSTER) && |
503 | && !QUERY_FLAG (tmp, FLAG_MONSTER) |
512 | (tmp->type != WEAPON) && (tmp->type != BOW) && (tmp->type != ARROW) && (tmp->type != GOLEM) && (immune_stop & AT_MAGIC)) |
504 | && (tmp->type != PLAYER) |
|
|
505 | && (tmp->type != WEAPON) |
|
|
506 | && (tmp->type != BOW) |
|
|
507 | && (tmp->type != ARROW) |
|
|
508 | && (tmp->type != GOLEM) |
|
|
509 | && !QUERY_FLAG (tmp, FLAG_IS_FLOOR) // XXX: |
|
|
510 | // we special case floor here because there |
|
|
511 | // are sometimes spell effect floors |
|
|
512 | // which are used to inflict damage |
|
|
513 | // (and those shouldn't go away from |
|
|
514 | // sanctuary) see also: permanent lava |
|
|
515 | && (immune_stop & AT_MAGIC)) |
513 | return 0; |
516 | return 0; |
514 | |
517 | |
515 | /* This is to prevent 'out of control' spells. Basically, this |
518 | /* This is to prevent 'out of control' spells. Basically, this |
516 | * limits one spell effect per space per spell. This is definately |
519 | * limits one spell effect per space per spell. This is definately |
517 | * needed for performance reasons, and just for playability I believe. |
520 | * needed for performance reasons, and just for playability I believe. |
… | |
… | |
527 | * playability reasons. |
530 | * playability reasons. |
528 | */ |
531 | */ |
529 | if (tmp->arch == op->arch |
532 | if (tmp->arch == op->arch |
530 | && tmp->type == op->type |
533 | && tmp->type == op->type |
531 | && tmp->subtype == op->subtype |
534 | && tmp->subtype == op->subtype |
|
|
535 | && tmp->owner == op->owner |
532 | && tmp->owner == op->owner && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) |
536 | && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) |
533 | { |
537 | { |
534 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
538 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
535 | tmp->range = MAX (tmp->range, op->range); |
539 | tmp->range = MAX (tmp->range, op->range); |
536 | tmp->duration = MAX (tmp->duration, op->duration); |
540 | tmp->duration = MAX (tmp->duration, op->duration); |
537 | return 0; |
541 | return 0; |
… | |
… | |
539 | |
543 | |
540 | /* Perhaps we should also put checks in for no magic and unholy |
544 | /* Perhaps we should also put checks in for no magic and unholy |
541 | * ground to prevent it from moving along? |
545 | * ground to prevent it from moving along? |
542 | */ |
546 | */ |
543 | } |
547 | } |
|
|
548 | |
544 | /* If it passes the above tests, it must be OK */ |
549 | /* If it passes the above tests, it must be OK */ |
545 | return 1; |
550 | return 1; |
546 | } |
551 | } |
547 | |
552 | |
548 | /* fire_arch_from_position: fires an archetype. |
553 | /* fire_arch_from_position: fires an archetype. |
… | |
… | |
638 | drain_rod_charge (object *rod) |
643 | drain_rod_charge (object *rod) |
639 | { |
644 | { |
640 | rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST); |
645 | rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST); |
641 | } |
646 | } |
642 | |
647 | |
643 | |
|
|
644 | |
|
|
645 | |
|
|
646 | /* this function is commonly used to find a friendly target for |
648 | /* this function is commonly used to find a friendly target for |
647 | * spells such as heal or protection or armour |
649 | * spells such as heal or protection or armour |
648 | * op is what is looking for the target (which can be a player), |
650 | * op is what is looking for the target (which can be a player), |
649 | * dir is the direction we are looking in. Return object found, or |
651 | * dir is the direction we are looking in. Return object found, or |
650 | * NULL if no good object. |
652 | * NULL if no good object. |
651 | */ |
653 | */ |
652 | |
|
|
653 | object * |
654 | object * |
654 | find_target_for_friendly_spell (object *op, int dir) |
655 | find_target_for_friendly_spell (object *op, int dir) |
655 | { |
656 | { |
656 | object *tmp; |
657 | object *tmp; |
657 | maptile *m; |
|
|
658 | sint16 x, y; |
|
|
659 | int mflags; |
|
|
660 | |
658 | |
661 | /* I don't really get this block - if op isn't a player or rune, |
659 | /* I don't really get this block - if op isn't a player or rune, |
662 | * we then make the owner of this object the target. |
660 | * we then make the owner of this object the target. |
663 | * The owner could very well be no where near op. |
661 | * The owner could very well be no where near op. |
664 | */ |
662 | */ |
… | |
… | |
671 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
669 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
672 | tmp = op; |
670 | tmp = op; |
673 | } |
671 | } |
674 | else |
672 | else |
675 | { |
673 | { |
676 | m = op->map; |
674 | maptile *m = op->map; |
677 | x = op->x + freearr_x[dir]; |
675 | sint16 x = op->x + freearr_x[dir]; |
678 | y = op->y + freearr_y[dir]; |
676 | sint16 y = op->y + freearr_y[dir]; |
679 | |
|
|
680 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
|
|
681 | |
|
|
682 | if (mflags & P_OUT_OF_MAP) |
|
|
683 | tmp = 0; |
|
|
684 | else |
677 | |
|
|
678 | tmp = xy_normalise (m, x, y) |
685 | tmp = m->at (x, y).player (); |
679 | ? m->at (x, y).player () |
|
|
680 | : 0; |
686 | } |
681 | } |
687 | |
682 | |
688 | /* didn't find a player there, look in current square for a player */ |
683 | /* didn't find a player there, look in current square for a player */ |
689 | if (!tmp) |
684 | if (!tmp) |
690 | tmp = op->ms ().player (); |
685 | tmp = op->ms ().player (); |
… | |
… | |
1022 | |
1017 | |
1023 | int |
1018 | int |
1024 | cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) |
1019 | cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) |
1025 | { |
1020 | { |
1026 | int success; |
1021 | int success; |
1027 | player *pl; |
|
|
1028 | object *spell; |
1022 | object *spell; |
1029 | |
1023 | |
1030 | if (!spell_ob->other_arch) |
1024 | if (!spell_ob->other_arch) |
1031 | { |
1025 | { |
1032 | LOG (llevError, "cast_party_spell: empty other arch\n"); |
1026 | LOG (llevError, "cast_party_spell: empty other arch\n"); |
… | |
… | |
1171 | if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < |
1165 | if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < |
1172 | (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) |
1166 | (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) |
1173 | { |
1167 | { |
1174 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1168 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1175 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); |
1169 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); |
|
|
1170 | |
1176 | if (settings.casting_time == TRUE) |
1171 | if (settings.casting_time == TRUE) |
1177 | { |
|
|
1178 | op->casting_time = -1; |
1172 | op->casting_time = -1; |
1179 | } |
1173 | |
1180 | op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); |
1174 | op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); |
1181 | return 0; |
1175 | return 0; |
1182 | } |
1176 | } |
1183 | else if (spell_ob->stats.sp) |
1177 | else if (spell_ob->stats.sp) |
1184 | { |
1178 | { |
… | |
… | |
1661 | break; |
1655 | break; |
1662 | |
1656 | |
1663 | case SP_MOVING_BALL: |
1657 | case SP_MOVING_BALL: |
1664 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1658 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1665 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1659 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1666 | else if (victim->material || victim->materialname) |
1660 | else if (victim->materialname) |
1667 | save_throw_object (victim, spell->attacktype, spell); |
1661 | save_throw_object (victim, spell->attacktype, spell); |
1668 | break; |
1662 | break; |
1669 | } |
1663 | } |
1670 | } |
1664 | } |