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 |
… | |
… | |
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 | |
|
|
494 | int |
483 | int |
495 | 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) |
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 |
… | |
… | |
550 | |
534 | |
551 | /* Perhaps we should also put checks in for no magic and unholy |
535 | /* Perhaps we should also put checks in for no magic and unholy |
552 | * ground to prevent it from moving along? |
536 | * ground to prevent it from moving along? |
553 | */ |
537 | */ |
554 | } |
538 | } |
|
|
539 | |
555 | /* If it passes the above tests, it must be OK */ |
540 | /* If it passes the above tests, it must be OK */ |
556 | return 1; |
541 | return 1; |
557 | } |
542 | } |
558 | |
543 | |
559 | /* fire_arch_from_position: fires an archetype. |
544 | /* fire_arch_from_position: fires an archetype. |
… | |
… | |
619 | return 0; |
604 | return 0; |
620 | } |
605 | } |
621 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
606 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
622 | SET_ANIMATION (tmp, dir); |
607 | SET_ANIMATION (tmp, dir); |
623 | |
608 | |
624 | if ((tmp = insert_ob_in_map (tmp, m, op, 0)) == NULL) |
609 | if ((tmp = insert_ob_in_map (tmp, m, op, 0))) |
625 | return 1; |
|
|
626 | |
|
|
627 | move_spell_effect (tmp); |
610 | move_spell_effect (tmp); |
628 | |
611 | |
629 | return 1; |
612 | return 1; |
630 | } |
613 | } |
631 | |
|
|
632 | |
|
|
633 | |
614 | |
634 | /***************************************************************************** |
615 | /***************************************************************************** |
635 | * |
616 | * |
636 | * Code related to rods - perhaps better located in another file? |
617 | * Code related to rods - perhaps better located in another file? |
637 | * |
618 | * |
638 | ****************************************************************************/ |
619 | ****************************************************************************/ |
639 | |
|
|
640 | void |
620 | void |
641 | regenerate_rod (object *rod) |
621 | regenerate_rod (object *rod) |
642 | { |
622 | { |
643 | if (rod->stats.hp < rod->stats.maxhp) |
623 | if (rod->stats.hp < rod->stats.maxhp) |
644 | { |
624 | { |
… | |
… | |
808 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
788 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
809 | |
789 | |
810 | insert_ob_in_map (head, op->map, op, 0); |
790 | insert_ob_in_map (head, op->map, op, 0); |
811 | |
791 | |
812 | /* thought it'd be cool to insert a burnout, too. */ |
792 | /* thought it'd be cool to insert a burnout, too. */ |
813 | tmp = get_archetype ("burnout"); |
793 | 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 | } |
794 | } |
819 | } |
795 | } |
820 | |
796 | |
821 | /* peterm: function which summons hostile monsters and |
797 | /* peterm: function which summons hostile monsters and |
822 | * places them in nearby squares. |
798 | * places them in nearby squares. |
… | |
… | |
1022 | else |
998 | else |
1023 | { |
999 | { |
1024 | new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); |
1000 | new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); |
1025 | tmp = get_archetype (LOOSE_MANA); |
1001 | tmp = get_archetype (LOOSE_MANA); |
1026 | tmp->level = skill->level; |
1002 | tmp->level = skill->level; |
1027 | tmp->x = op->x; |
|
|
1028 | tmp->y = op->y; |
|
|
1029 | |
1003 | |
1030 | /* increase the area of destruction a little for more powerful spells */ |
1004 | /* increase the area of destruction a little for more powerful spells */ |
1031 | tmp->range += isqrt (power); |
1005 | tmp->range += isqrt (power); |
1032 | |
1006 | |
1033 | if (power > 25) |
1007 | if (power > 25) |
1034 | tmp->stats.dam = 25 + isqrt (power); |
1008 | tmp->stats.dam = 25 + isqrt (power); |
1035 | else |
1009 | else |
1036 | tmp->stats.dam = power; /* nasty recoils! */ |
1010 | tmp->stats.dam = power; /* nasty recoils! */ |
1037 | |
1011 | |
1038 | tmp->stats.maxhp = tmp->count; |
1012 | tmp->stats.maxhp = tmp->count; |
1039 | insert_ob_in_map (tmp, op->map, NULL, 0); |
1013 | |
|
|
1014 | tmp->insert_at (op); |
1040 | } |
1015 | } |
1041 | } |
1016 | } |
1042 | } |
1017 | } |
1043 | |
1018 | |
1044 | int |
1019 | int |
… | |
… | |
1061 | if (caster->contr->party == NULL) |
1036 | if (caster->contr->party == NULL) |
1062 | { |
1037 | { |
1063 | spell->remove (); |
1038 | spell->remove (); |
1064 | return success; |
1039 | return success; |
1065 | } |
1040 | } |
1066 | for (pl = first_player; pl != NULL; pl = pl->next) |
1041 | for_all_players (pl) |
1067 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1042 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1068 | { |
1043 | { |
1069 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1044 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1070 | } |
1045 | } |
1071 | spell->remove (); |
1046 | spell->remove (); |
… | |
… | |
1169 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1144 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1170 | { |
1145 | { |
1171 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
1146 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
1172 | return 0; |
1147 | return 0; |
1173 | } |
1148 | } |
|
|
1149 | |
1174 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1150 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1175 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) |
1151 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) |
1176 | { |
1152 | { |
1177 | if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - |
1153 | 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) |
1154 | 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) |