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) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | |
7 | * |
8 | 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 |
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 2 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, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
21 | * |
22 | 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> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | |
25 | |
26 | #include <global.h> |
26 | #include <global.h> |
27 | #include <spells.h> |
27 | #include <spells.h> |
28 | #include <object.h> |
28 | #include <object.h> |
… | |
… | |
188 | * is being cast at. |
188 | * is being cast at. |
189 | * 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. |
190 | * This is because the new code compares casting_level against |
190 | * This is because the new code compares casting_level against |
191 | * min_caster_level, so the difference is effectively 4 |
191 | * min_caster_level, so the difference is effectively 4 |
192 | */ |
192 | */ |
193 | |
|
|
194 | int |
193 | int |
195 | caster_level (object *caster, object *spell) |
194 | caster_level (object *caster, object *spell) |
196 | { |
195 | { |
197 | int level = caster->level; |
196 | int level = caster->level; |
198 | |
197 | |
… | |
… | |
213 | |
212 | |
214 | level = MIN (level, sk_level + level / 10 + 1); |
213 | level = MIN (level, sk_level + level / 10 + 1); |
215 | } |
214 | } |
216 | |
215 | |
217 | /* Got valid caster level. Now adjust for attunement */ |
216 | /* Got valid caster level. Now adjust for attunement */ |
218 | 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; |
219 | |
219 | |
220 | /* 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 |
221 | * errors in various places. |
221 | * errors in various places. |
222 | */ |
222 | */ |
223 | if (level < 1) |
|
|
224 | level = 1; |
|
|
225 | |
|
|
226 | return level; |
223 | return max (level, 1); |
227 | } |
224 | } |
228 | |
225 | |
229 | /* The following function scales the spellpoint cost of |
226 | /* The following function scales the spellpoint cost of |
230 | * a spell by it's increased effectiveness. Some of the |
227 | * a spell by it's increased effectiveness. Some of the |
231 | * lower level spells become incredibly vicious at high |
228 | * lower level spells become incredibly vicious at high |
… | |
… | |
478 | * has the AT_MAGIC bit set, and there is a counterwall |
475 | * has the AT_MAGIC bit set, and there is a counterwall |
479 | * 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 |
480 | * 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. |
481 | * |
478 | * |
482 | */ |
479 | */ |
483 | |
|
|
484 | int |
480 | int |
485 | 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) |
486 | { |
482 | { |
487 | object *tmp; |
483 | if (!xy_normalise (m, x, y)) |
488 | int mflags; |
|
|
489 | maptile *mp; |
|
|
490 | |
|
|
491 | mp = m; |
|
|
492 | mflags = get_map_flags (m, &mp, x, y, &x, &y); |
|
|
493 | |
|
|
494 | if (mflags & P_OUT_OF_MAP) |
|
|
495 | return 0; |
484 | return 0; |
496 | |
485 | |
497 | 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)) |
498 | return 0; |
489 | return 0; |
499 | |
490 | |
500 | for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above) |
491 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
501 | { |
492 | { |
502 | /* If there is a counterspell on the space, and this |
493 | /* If there is a counterspell on the space, and this |
503 | * object is using magic, don't progress. I believe we could |
494 | * object is using magic, don't progress. I believe we could |
504 | * 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 |
505 | * 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 |
506 | * 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 |
507 | * 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 |
508 | * 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 |
509 | * spell to actually hit the counterwall and be sucked up. |
500 | * spell to actually hit the counterwall and be sucked up. |
510 | */ |
501 | */ |
511 | if ((tmp->attacktype & AT_COUNTERSPELL) && |
502 | if ((tmp->attacktype & AT_COUNTERSPELL) |
512 | (tmp->type != PLAYER) && !QUERY_FLAG (tmp, FLAG_MONSTER) && |
503 | && !QUERY_FLAG (tmp, FLAG_MONSTER) |
513 | (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)) |
514 | return 0; |
516 | return 0; |
515 | |
517 | |
516 | /* This is to prevent 'out of control' spells. Basically, this |
518 | /* This is to prevent 'out of control' spells. Basically, this |
517 | * limits one spell effect per space per spell. This is definately |
519 | * limits one spell effect per space per spell. This is definately |
518 | * needed for performance reasons, and just for playability I believe. |
520 | * needed for performance reasons, and just for playability I believe. |
… | |
… | |
528 | * playability reasons. |
530 | * playability reasons. |
529 | */ |
531 | */ |
530 | if (tmp->arch == op->arch |
532 | if (tmp->arch == op->arch |
531 | && tmp->type == op->type |
533 | && tmp->type == op->type |
532 | && tmp->subtype == op->subtype |
534 | && tmp->subtype == op->subtype |
|
|
535 | && tmp->owner == op->owner |
533 | && 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))) |
534 | { |
537 | { |
535 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
538 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
536 | tmp->range = MAX (tmp->range, op->range); |
539 | tmp->range = MAX (tmp->range, op->range); |
537 | tmp->duration = MAX (tmp->duration, op->duration); |
540 | tmp->duration = MAX (tmp->duration, op->duration); |
538 | return 0; |
541 | return 0; |
… | |
… | |
540 | |
543 | |
541 | /* 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 |
542 | * ground to prevent it from moving along? |
545 | * ground to prevent it from moving along? |
543 | */ |
546 | */ |
544 | } |
547 | } |
|
|
548 | |
545 | /* If it passes the above tests, it must be OK */ |
549 | /* If it passes the above tests, it must be OK */ |
546 | return 1; |
550 | return 1; |
547 | } |
551 | } |
548 | |
552 | |
549 | /* fire_arch_from_position: fires an archetype. |
553 | /* fire_arch_from_position: fires an archetype. |
… | |
… | |
639 | drain_rod_charge (object *rod) |
643 | drain_rod_charge (object *rod) |
640 | { |
644 | { |
641 | 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); |
642 | } |
646 | } |
643 | |
647 | |
644 | |
|
|
645 | |
|
|
646 | |
|
|
647 | /* this function is commonly used to find a friendly target for |
648 | /* this function is commonly used to find a friendly target for |
648 | * spells such as heal or protection or armour |
649 | * spells such as heal or protection or armour |
649 | * 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), |
650 | * 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 |
651 | * NULL if no good object. |
652 | * NULL if no good object. |
652 | */ |
653 | */ |
653 | |
|
|
654 | object * |
654 | object * |
655 | find_target_for_friendly_spell (object *op, int dir) |
655 | find_target_for_friendly_spell (object *op, int dir) |
656 | { |
656 | { |
657 | object *tmp; |
657 | object *tmp; |
658 | maptile *m; |
|
|
659 | sint16 x, y; |
|
|
660 | int mflags; |
|
|
661 | |
658 | |
662 | /* 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, |
663 | * we then make the owner of this object the target. |
660 | * we then make the owner of this object the target. |
664 | * The owner could very well be no where near op. |
661 | * The owner could very well be no where near op. |
665 | */ |
662 | */ |
… | |
… | |
672 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
669 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
673 | tmp = op; |
670 | tmp = op; |
674 | } |
671 | } |
675 | else |
672 | else |
676 | { |
673 | { |
677 | m = op->map; |
674 | maptile *m = op->map; |
678 | x = op->x + freearr_x[dir]; |
675 | sint16 x = op->x + freearr_x[dir]; |
679 | y = op->y + freearr_y[dir]; |
676 | sint16 y = op->y + freearr_y[dir]; |
680 | |
|
|
681 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
|
|
682 | |
|
|
683 | if (mflags & P_OUT_OF_MAP) |
|
|
684 | tmp = 0; |
|
|
685 | else |
677 | |
|
|
678 | tmp = xy_normalise (m, x, y) |
686 | tmp = m->at (x, y).player (); |
679 | ? m->at (x, y).player () |
|
|
680 | : 0; |
687 | } |
681 | } |
688 | |
682 | |
689 | /* 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 */ |
690 | if (!tmp) |
684 | if (!tmp) |
691 | tmp = op->ms ().player (); |
685 | tmp = op->ms ().player (); |
… | |
… | |
1023 | |
1017 | |
1024 | int |
1018 | int |
1025 | 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) |
1026 | { |
1020 | { |
1027 | int success; |
1021 | int success; |
1028 | player *pl; |
|
|
1029 | object *spell; |
1022 | object *spell; |
1030 | |
1023 | |
1031 | if (!spell_ob->other_arch) |
1024 | if (!spell_ob->other_arch) |
1032 | { |
1025 | { |
1033 | LOG (llevError, "cast_party_spell: empty other arch\n"); |
1026 | LOG (llevError, "cast_party_spell: empty other arch\n"); |
… | |
… | |
1172 | 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) < |
1173 | (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])) |
1174 | { |
1167 | { |
1175 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1168 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1176 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); |
1169 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); |
|
|
1170 | |
1177 | if (settings.casting_time == TRUE) |
1171 | if (settings.casting_time == TRUE) |
1178 | { |
|
|
1179 | op->casting_time = -1; |
1172 | op->casting_time = -1; |
1180 | } |
1173 | |
1181 | 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); |
1182 | return 0; |
1175 | return 0; |
1183 | } |
1176 | } |
1184 | else if (spell_ob->stats.sp) |
1177 | else if (spell_ob->stats.sp) |
1185 | { |
1178 | { |
… | |
… | |
1662 | break; |
1655 | break; |
1663 | |
1656 | |
1664 | case SP_MOVING_BALL: |
1657 | case SP_MOVING_BALL: |
1665 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1658 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1666 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1659 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1667 | else if (victim->material || victim->materialname) |
1660 | else if (victim->materialname) |
1668 | save_throw_object (victim, spell->attacktype, spell); |
1661 | save_throw_object (victim, spell->attacktype, spell); |
1669 | break; |
1662 | break; |
1670 | } |
1663 | } |
1671 | } |
1664 | } |