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 | |
34 | extern char *spell_mapping[]; |
33 | extern 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 | |
|
|
157 | void |
155 | void |
158 | spell_effect (object *spob, int x, int y, maptile *map, object *originator) |
156 | spell_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 | */ |
182 | int |
172 | int |
183 | min_casting_level (object *caster, object *spell) |
173 | min_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 |
… | |
… | |
444 | if (OUT_OF_REAL_MAP (m, x, y)) |
434 | if (OUT_OF_REAL_MAP (m, x, y)) |
445 | return 0; |
435 | return 0; |
446 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
436 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
447 | if (QUERY_FLAG (op, FLAG_REFL_SPELL) |
437 | if (QUERY_FLAG (op, FLAG_REFL_SPELL) |
448 | && (!QUERY_FLAG (op, FLAG_ALIVE) |
438 | && (!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))) |
439 | || (rndm (0, 99)) < 90 - (sp_op->level / 10))) |
452 | return 1; |
440 | return 1; |
453 | |
441 | |
454 | return 0; |
442 | return 0; |
455 | } |
443 | } |
… | |
… | |
473 | { |
461 | { |
474 | 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."); |
475 | 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."); |
476 | dir = 0; |
464 | dir = 0; |
477 | } |
465 | } |
478 | new_op->x = op->x + freearr_x[dir]; |
466 | |
479 | new_op->y = op->y + freearr_y[dir]; |
467 | op->map->insert (new_op, |
480 | if (dir == 0) |
468 | op->x + freearr_x[dir], op->y + freearr_y[dir], |
481 | insert_ob_in_map (new_op, op->map, op, INS_BELOW_ORIGINATOR); |
469 | op, |
482 | else |
470 | dir ? 0 : INS_BELOW_ORIGINATOR); |
483 | insert_ob_in_map (new_op, op->map, op, 0); |
471 | |
484 | return dir; |
472 | return dir; |
485 | } |
473 | } |
486 | |
474 | |
487 | /* 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. |
488 | * immune_stop is basically the attacktype of the spell (why |
476 | * immune_stop is basically the attacktype of the spell (why |
… | |
… | |
490 | * has the AT_MAGIC bit set, and there is a counterwall |
478 | * has the AT_MAGIC bit set, and there is a counterwall |
491 | * 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 |
492 | * 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. |
493 | * |
481 | * |
494 | */ |
482 | */ |
495 | |
|
|
496 | int |
483 | int |
497 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
484 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
498 | { |
485 | { |
499 | object *tmp; |
486 | if (!xy_normalise (m, x, y)) |
500 | int mflags; |
|
|
501 | maptile *mp; |
|
|
502 | |
|
|
503 | mp = m; |
|
|
504 | mflags = get_map_flags (m, &mp, x, y, &x, &y); |
|
|
505 | |
|
|
506 | if (mflags & P_OUT_OF_MAP) |
|
|
507 | return 0; |
487 | return 0; |
508 | |
488 | |
509 | 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)) |
510 | return 0; |
492 | return 0; |
511 | |
493 | |
512 | for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above) |
494 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
513 | { |
495 | { |
514 | /* If there is a counterspell on the space, and this |
496 | /* If there is a counterspell on the space, and this |
515 | * object is using magic, don't progress. I believe we could |
497 | * object is using magic, don't progress. I believe we could |
516 | * 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 |
517 | * 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 |
… | |
… | |
540 | * playability reasons. |
522 | * playability reasons. |
541 | */ |
523 | */ |
542 | if (tmp->arch == op->arch |
524 | if (tmp->arch == op->arch |
543 | && tmp->type == op->type |
525 | && tmp->type == op->type |
544 | && tmp->subtype == op->subtype |
526 | && tmp->subtype == op->subtype |
|
|
527 | && tmp->owner == op->owner |
545 | && 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))) |
546 | { |
529 | { |
547 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
530 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
548 | tmp->range = MAX (tmp->range, op->range); |
531 | tmp->range = MAX (tmp->range, op->range); |
549 | tmp->duration = MAX (tmp->duration, op->duration); |
532 | tmp->duration = MAX (tmp->duration, op->duration); |
550 | return 0; |
533 | return 0; |
… | |
… | |
552 | |
535 | |
553 | /* 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 |
554 | * ground to prevent it from moving along? |
537 | * ground to prevent it from moving along? |
555 | */ |
538 | */ |
556 | } |
539 | } |
|
|
540 | |
557 | /* If it passes the above tests, it must be OK */ |
541 | /* If it passes the above tests, it must be OK */ |
558 | return 1; |
542 | return 1; |
559 | } |
543 | } |
560 | |
544 | |
561 | /* fire_arch_from_position: fires an archetype. |
545 | /* fire_arch_from_position: fires an archetype. |
… | |
… | |
621 | return 0; |
605 | return 0; |
622 | } |
606 | } |
623 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
607 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
624 | SET_ANIMATION (tmp, dir); |
608 | SET_ANIMATION (tmp, dir); |
625 | |
609 | |
626 | if ((tmp = insert_ob_in_map (tmp, m, op, 0)) == NULL) |
610 | if ((tmp = insert_ob_in_map (tmp, m, op, 0))) |
627 | return 1; |
|
|
628 | |
|
|
629 | move_spell_effect (tmp); |
611 | move_spell_effect (tmp); |
630 | |
612 | |
631 | return 1; |
613 | return 1; |
632 | } |
614 | } |
633 | |
|
|
634 | |
|
|
635 | |
615 | |
636 | /***************************************************************************** |
616 | /***************************************************************************** |
637 | * |
617 | * |
638 | * Code related to rods - perhaps better located in another file? |
618 | * Code related to rods - perhaps better located in another file? |
639 | * |
619 | * |
640 | ****************************************************************************/ |
620 | ****************************************************************************/ |
641 | |
|
|
642 | void |
621 | void |
643 | regenerate_rod (object *rod) |
622 | regenerate_rod (object *rod) |
644 | { |
623 | { |
645 | if (rod->stats.hp < rod->stats.maxhp) |
624 | if (rod->stats.hp < rod->stats.maxhp) |
646 | { |
625 | { |
… | |
… | |
696 | y = op->y + freearr_y[dir]; |
675 | y = op->y + freearr_y[dir]; |
697 | |
676 | |
698 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
677 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
699 | |
678 | |
700 | if (mflags & P_OUT_OF_MAP) |
679 | if (mflags & P_OUT_OF_MAP) |
701 | tmp = NULL; |
680 | tmp = 0; |
702 | else |
681 | else |
703 | { |
682 | 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 | } |
683 | } |
|
|
684 | |
709 | /* didn't find a player there, look in current square for a player */ |
685 | /* didn't find a player there, look in current square for a player */ |
710 | if (tmp == NULL) |
686 | if (!tmp) |
711 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
687 | tmp = op->ms ().player (); |
712 | { |
|
|
713 | if (tmp->type == PLAYER) |
|
|
714 | break; |
|
|
715 | } |
|
|
716 | |
688 | |
717 | return tmp; |
689 | return tmp; |
718 | } |
690 | } |
719 | |
691 | |
720 | |
692 | |
… | |
… | |
817 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
789 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
818 | |
790 | |
819 | insert_ob_in_map (head, op->map, op, 0); |
791 | insert_ob_in_map (head, op->map, op, 0); |
820 | |
792 | |
821 | /* thought it'd be cool to insert a burnout, too. */ |
793 | /* thought it'd be cool to insert a burnout, too. */ |
822 | tmp = get_archetype ("burnout"); |
794 | 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 | } |
795 | } |
828 | } |
796 | } |
829 | |
797 | |
830 | /* peterm: function which summons hostile monsters and |
798 | /* peterm: function which summons hostile monsters and |
831 | * places them in nearby squares. |
799 | * places them in nearby squares. |
… | |
… | |
1031 | else |
999 | else |
1032 | { |
1000 | { |
1033 | 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!"); |
1034 | tmp = get_archetype (LOOSE_MANA); |
1002 | tmp = get_archetype (LOOSE_MANA); |
1035 | tmp->level = skill->level; |
1003 | tmp->level = skill->level; |
1036 | tmp->x = op->x; |
|
|
1037 | tmp->y = op->y; |
|
|
1038 | |
1004 | |
1039 | /* increase the area of destruction a little for more powerful spells */ |
1005 | /* increase the area of destruction a little for more powerful spells */ |
1040 | tmp->range += isqrt (power); |
1006 | tmp->range += isqrt (power); |
1041 | |
1007 | |
1042 | if (power > 25) |
1008 | if (power > 25) |
1043 | tmp->stats.dam = 25 + isqrt (power); |
1009 | tmp->stats.dam = 25 + isqrt (power); |
1044 | else |
1010 | else |
1045 | tmp->stats.dam = power; /* nasty recoils! */ |
1011 | tmp->stats.dam = power; /* nasty recoils! */ |
1046 | |
1012 | |
1047 | tmp->stats.maxhp = tmp->count; |
1013 | tmp->stats.maxhp = tmp->count; |
1048 | insert_ob_in_map (tmp, op->map, NULL, 0); |
1014 | |
|
|
1015 | tmp->insert_at (op); |
1049 | } |
1016 | } |
1050 | } |
1017 | } |
1051 | } |
1018 | } |
1052 | |
1019 | |
1053 | int |
1020 | int |
… | |
… | |
1070 | if (caster->contr->party == NULL) |
1037 | if (caster->contr->party == NULL) |
1071 | { |
1038 | { |
1072 | spell->remove (); |
1039 | spell->remove (); |
1073 | return success; |
1040 | return success; |
1074 | } |
1041 | } |
1075 | for (pl = first_player; pl != NULL; pl = pl->next) |
1042 | for_all_players (pl) |
1076 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1043 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1077 | { |
1044 | { |
1078 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1045 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1079 | } |
1046 | } |
1080 | spell->remove (); |
1047 | spell->remove (); |
… | |
… | |
1178 | 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) |
1179 | { |
1146 | { |
1180 | 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."); |
1181 | return 0; |
1148 | return 0; |
1182 | } |
1149 | } |
|
|
1150 | |
1183 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1151 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1184 | 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) |
1185 | { |
1153 | { |
1186 | 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 - |
1187 | 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) |