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-devel@real-time.com |
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> |
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 |
… | |
… | |
119 | } |
118 | } |
120 | |
119 | |
121 | i = 0; |
120 | i = 0; |
122 | while (spell_mapping[i]) |
121 | while (spell_mapping[i]) |
123 | { |
122 | { |
124 | if (!find_archetype (spell_mapping[i])) |
123 | if (!archetype::find (spell_mapping[i])) |
125 | { |
124 | { |
126 | LOG (llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i); |
125 | LOG (llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i); |
127 | } |
126 | } |
128 | i++; |
127 | i++; |
129 | } |
128 | } |
… | |
… | |
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, mapstruct *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) |
184 | { |
174 | { |
185 | int new_level; |
175 | int new_level; |
186 | |
176 | |
187 | if (caster->path_denied & spell->path_attuned) |
177 | if (caster->path_denied & spell->path_attuned) |
188 | { |
|
|
189 | /* This case is not a bug, just the fact that this function is |
|
|
190 | * usually called BEFORE checking for path_deny. -AV |
|
|
191 | */ |
|
|
192 | #if 0 |
|
|
193 | LOG (llevError, "BUG: path_level_mod (arch %s, name %s): casting denied " "spell\n", caster->arch->name, caster->name); |
|
|
194 | #endif |
|
|
195 | return 1; |
178 | return 1; |
196 | } |
179 | |
197 | new_level = spell->level |
180 | new_level = spell->level |
198 | + ((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) |
199 | return (new_level < 1) ? 1 : new_level; |
182 | + (caster->path_attuned & spell->path_attuned ? -2 : 0); |
200 | } |
|
|
201 | |
183 | |
|
|
184 | return max (1, new_level); |
|
|
185 | } |
202 | |
186 | |
203 | /* This function returns the effective level the spell |
187 | /* This function returns the effective level the spell |
204 | * is being cast at. |
188 | * is being cast at. |
205 | * 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. |
206 | * This is because the new code compares casting_level against |
190 | * This is because the new code compares casting_level against |
207 | * min_caster_level, so the difference is effectively 4 |
191 | * min_caster_level, so the difference is effectively 4 |
208 | */ |
192 | */ |
209 | |
|
|
210 | int |
193 | int |
211 | caster_level (object *caster, object *spell) |
194 | caster_level (object *caster, object *spell) |
212 | { |
195 | { |
213 | int level = caster->level; |
196 | int level = caster->level; |
214 | |
197 | |
215 | /* If this is a player, try to find the matching skill */ |
198 | /* If this is a player, try to find the matching skill */ |
216 | if (caster->type == PLAYER && spell->skill) |
199 | if (caster->type == PLAYER && spell->skill) |
217 | { |
|
|
218 | int i; |
|
|
219 | |
|
|
220 | for (i = 0; i < NUM_SKILLS; i++) |
200 | for (int i = 0; i < NUM_SKILLS; i++) |
221 | if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) |
201 | if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) |
222 | { |
202 | { |
223 | level = caster->contr->last_skill_ob[i]->level; |
203 | level = caster->contr->last_skill_ob[i]->level; |
224 | break; |
204 | break; |
225 | } |
205 | } |
226 | } |
|
|
227 | |
206 | |
228 | /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ |
207 | /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ |
229 | if (caster->type == ROD && caster->env && caster->env->type == PLAYER) |
208 | if (caster->type == ROD && caster->env && caster->env->type == PLAYER) |
230 | { |
209 | { |
231 | object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); |
210 | object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); |
… | |
… | |
233 | |
212 | |
234 | level = MIN (level, sk_level + level / 10 + 1); |
213 | level = MIN (level, sk_level + level / 10 + 1); |
235 | } |
214 | } |
236 | |
215 | |
237 | /* Got valid caster level. Now adjust for attunement */ |
216 | /* Got valid caster level. Now adjust for attunement */ |
238 | 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; |
239 | |
219 | |
240 | /* 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 |
241 | * errors in various places. |
221 | * errors in various places. |
242 | */ |
222 | */ |
243 | if (level < 1) |
|
|
244 | level = 1; |
|
|
245 | return level; |
223 | return max (level, 1); |
246 | } |
224 | } |
247 | |
225 | |
248 | /* The following function scales the spellpoint cost of |
226 | /* The following function scales the spellpoint cost of |
249 | * a spell by it's increased effectiveness. Some of the |
227 | * a spell by it's increased effectiveness. Some of the |
250 | * lower level spells become incredibly vicious at high |
228 | * lower level spells become incredibly vicious at high |
… | |
… | |
444 | * reflect_spell fails.) |
422 | * reflect_spell fails.) |
445 | * Caller should be sure it passes us valid map coordinates |
423 | * Caller should be sure it passes us valid map coordinates |
446 | * eg, updated for tiled maps. |
424 | * eg, updated for tiled maps. |
447 | */ |
425 | */ |
448 | int |
426 | int |
449 | reflwall (mapstruct *m, int x, int y, object *sp_op) |
427 | reflwall (maptile *m, int x, int y, object *sp_op) |
450 | { |
428 | { |
451 | object *op; |
429 | object *op; |
452 | |
430 | |
453 | if (OUT_OF_REAL_MAP (m, x, y)) |
431 | if (OUT_OF_REAL_MAP (m, x, y)) |
454 | return 0; |
432 | return 0; |
455 | for (op = get_map_ob (m, x, y); op != NULL; op = op->above) |
433 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
456 | if (QUERY_FLAG (op, FLAG_REFL_SPELL) && (!QUERY_FLAG (op, FLAG_ALIVE) || |
434 | if (QUERY_FLAG (op, FLAG_REFL_SPELL) |
457 | sp_op->type == LIGHTNING || (rndm (0, 99)) < 90 - (sp_op->level / 10))) |
435 | && (!QUERY_FLAG (op, FLAG_ALIVE) |
|
|
436 | || (rndm (0, 99)) < 90 - (sp_op->level / 10))) |
458 | return 1; |
437 | return 1; |
459 | |
438 | |
460 | return 0; |
439 | return 0; |
461 | } |
440 | } |
462 | |
441 | |
… | |
… | |
468 | * in. |
447 | * in. |
469 | */ |
448 | */ |
470 | int |
449 | int |
471 | cast_create_obj (object *op, object *caster, object *new_op, int dir) |
450 | cast_create_obj (object *op, object *caster, object *new_op, int dir) |
472 | { |
451 | { |
473 | mapstruct *m; |
452 | maptile *m; |
474 | sint16 sx, sy; |
453 | sint16 sx, sy; |
475 | |
454 | |
476 | if (dir && |
455 | if (dir && |
477 | ((get_map_flags (op->map, &m, op->x + freearr_x[dir], op->y + freearr_y[dir], &sx, &sy) & P_OUT_OF_MAP) || |
456 | ((get_map_flags (op->map, &m, op->x + freearr_x[dir], op->y + freearr_y[dir], &sx, &sy) & P_OUT_OF_MAP) || |
478 | OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))) |
457 | OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))) |
479 | { |
458 | { |
480 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
459 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
481 | new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); |
460 | new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); |
482 | dir = 0; |
461 | dir = 0; |
483 | } |
462 | } |
484 | new_op->x = op->x + freearr_x[dir]; |
463 | |
485 | new_op->y = op->y + freearr_y[dir]; |
464 | op->map->insert (new_op, |
486 | if (dir == 0) |
465 | op->x + freearr_x[dir], op->y + freearr_y[dir], |
487 | insert_ob_in_map (new_op, op->map, op, INS_BELOW_ORIGINATOR); |
466 | op, |
488 | else |
467 | dir ? 0 : INS_BELOW_ORIGINATOR); |
489 | insert_ob_in_map (new_op, op->map, op, 0); |
468 | |
490 | return dir; |
469 | return dir; |
491 | } |
470 | } |
492 | |
471 | |
493 | /* Returns true if it is ok to put spell *op on the space/may provided. |
472 | /* Returns true if it is ok to put spell *op on the space/may provided. |
494 | * immune_stop is basically the attacktype of the spell (why |
473 | * immune_stop is basically the attacktype of the spell (why |
… | |
… | |
496 | * has the AT_MAGIC bit set, and there is a counterwall |
475 | * has the AT_MAGIC bit set, and there is a counterwall |
497 | * 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 |
498 | * 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. |
499 | * |
478 | * |
500 | */ |
479 | */ |
501 | |
|
|
502 | int |
480 | int |
503 | ok_to_put_more (mapstruct *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) |
504 | { |
482 | { |
505 | object *tmp; |
483 | if (!xy_normalise (m, x, y)) |
506 | int mflags; |
|
|
507 | mapstruct *mp; |
|
|
508 | |
|
|
509 | mp = m; |
|
|
510 | mflags = get_map_flags (m, &mp, x, y, &x, &y); |
|
|
511 | |
|
|
512 | if (mflags & P_OUT_OF_MAP) |
|
|
513 | return 0; |
484 | return 0; |
514 | |
485 | |
515 | 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)) |
516 | return 0; |
489 | return 0; |
517 | |
490 | |
518 | for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) |
491 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
519 | { |
492 | { |
520 | /* If there is a counterspell on the space, and this |
493 | /* If there is a counterspell on the space, and this |
521 | * object is using magic, don't progress. I believe we could |
494 | * object is using magic, don't progress. I believe we could |
522 | * 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 |
523 | * 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 |
524 | * 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 |
525 | * 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 |
526 | * 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 |
527 | * spell to actually hit the counterwall and be sucked up. |
500 | * spell to actually hit the counterwall and be sucked up. |
528 | */ |
501 | */ |
529 | if ((tmp->attacktype & AT_COUNTERSPELL) && |
502 | if ((tmp->attacktype & AT_COUNTERSPELL) |
530 | (tmp->type != PLAYER) && !QUERY_FLAG (tmp, FLAG_MONSTER) && |
503 | && !QUERY_FLAG (tmp, FLAG_MONSTER) |
531 | (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)) |
532 | return 0; |
516 | return 0; |
533 | |
517 | |
534 | /* This is to prevent 'out of control' spells. Basically, this |
518 | /* This is to prevent 'out of control' spells. Basically, this |
535 | * limits one spell effect per space per spell. This is definately |
519 | * limits one spell effect per space per spell. This is definately |
536 | * needed for performance reasons, and just for playability I believe. |
520 | * needed for performance reasons, and just for playability I believe. |
… | |
… | |
546 | * playability reasons. |
530 | * playability reasons. |
547 | */ |
531 | */ |
548 | if (tmp->arch == op->arch |
532 | if (tmp->arch == op->arch |
549 | && tmp->type == op->type |
533 | && tmp->type == op->type |
550 | && tmp->subtype == op->subtype |
534 | && tmp->subtype == op->subtype |
|
|
535 | && tmp->owner == op->owner |
551 | && 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))) |
552 | { |
537 | { |
553 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
538 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
554 | tmp->range = MAX (tmp->range, op->range); |
539 | tmp->range = MAX (tmp->range, op->range); |
555 | tmp->duration = MAX (tmp->duration, op->duration); |
540 | tmp->duration = MAX (tmp->duration, op->duration); |
556 | return 0; |
541 | return 0; |
… | |
… | |
558 | |
543 | |
559 | /* 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 |
560 | * ground to prevent it from moving along? |
545 | * ground to prevent it from moving along? |
561 | */ |
546 | */ |
562 | } |
547 | } |
|
|
548 | |
563 | /* If it passes the above tests, it must be OK */ |
549 | /* If it passes the above tests, it must be OK */ |
564 | return 1; |
550 | return 1; |
565 | } |
551 | } |
566 | |
552 | |
567 | /* fire_arch_from_position: fires an archetype. |
553 | /* fire_arch_from_position: fires an archetype. |
… | |
… | |
578 | int |
564 | int |
579 | fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) |
565 | fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) |
580 | { |
566 | { |
581 | object *tmp; |
567 | object *tmp; |
582 | int mflags; |
568 | int mflags; |
583 | mapstruct *m; |
569 | maptile *m; |
584 | |
570 | |
585 | if (spell->other_arch == NULL) |
571 | if (spell->other_arch == NULL) |
586 | return 0; |
572 | return 0; |
587 | |
573 | |
588 | m = op->map; |
574 | m = op->map; |
… | |
… | |
598 | return 0; |
584 | return 0; |
599 | |
585 | |
600 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) |
586 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) |
601 | { |
587 | { |
602 | new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); |
588 | new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); |
603 | free_object (tmp); |
589 | tmp->destroy (); |
604 | return 0; |
590 | return 0; |
605 | } |
591 | } |
606 | |
|
|
607 | |
|
|
608 | |
592 | |
609 | tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); |
593 | tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); |
610 | tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); |
594 | tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); |
611 | /* code in time.c uses food for some things, duration for others */ |
595 | /* code in time.c uses food for some things, duration for others */ |
612 | tmp->stats.food = tmp->duration; |
596 | tmp->stats.food = tmp->duration; |
613 | tmp->range = spell->range + SP_level_range_adjust (caster, spell); |
597 | tmp->range = spell->range + SP_level_range_adjust (caster, spell); |
614 | tmp->attacktype = spell->attacktype; |
598 | tmp->attacktype = spell->attacktype; |
615 | tmp->x = x; |
599 | tmp->x = x; |
616 | tmp->y = y; |
600 | tmp->y = y; |
617 | tmp->direction = dir; |
601 | tmp->direction = dir; |
618 | if (get_owner (op) != NULL) |
602 | if (op->owner != NULL) |
619 | copy_owner (tmp, op); |
603 | tmp->set_owner (op); |
620 | else |
604 | else |
621 | set_owner (tmp, op); |
605 | tmp->set_owner (op); |
622 | tmp->level = caster_level (caster, spell); |
606 | tmp->level = caster_level (caster, spell); |
623 | set_spell_skill (op, caster, spell, tmp); |
607 | set_spell_skill (op, caster, spell, tmp); |
624 | |
608 | |
625 | /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ |
609 | /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ |
626 | if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) |
610 | if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) |
… | |
… | |
629 | return 0; |
613 | return 0; |
630 | } |
614 | } |
631 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
615 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
632 | SET_ANIMATION (tmp, dir); |
616 | SET_ANIMATION (tmp, dir); |
633 | |
617 | |
634 | if ((tmp = insert_ob_in_map (tmp, m, op, 0)) == NULL) |
618 | if ((tmp = insert_ob_in_map (tmp, m, op, 0))) |
635 | return 1; |
|
|
636 | |
|
|
637 | move_spell_effect (tmp); |
619 | move_spell_effect (tmp); |
638 | |
620 | |
639 | return 1; |
621 | return 1; |
640 | } |
622 | } |
641 | |
|
|
642 | |
|
|
643 | |
623 | |
644 | /***************************************************************************** |
624 | /***************************************************************************** |
645 | * |
625 | * |
646 | * Code related to rods - perhaps better located in another file? |
626 | * Code related to rods - perhaps better located in another file? |
647 | * |
627 | * |
648 | ****************************************************************************/ |
628 | ****************************************************************************/ |
649 | |
|
|
650 | void |
629 | void |
651 | regenerate_rod (object *rod) |
630 | regenerate_rod (object *rod) |
652 | { |
631 | { |
653 | if (rod->stats.hp < rod->stats.maxhp) |
632 | if (rod->stats.hp < rod->stats.maxhp) |
654 | { |
633 | { |
… | |
… | |
663 | void |
642 | void |
664 | drain_rod_charge (object *rod) |
643 | drain_rod_charge (object *rod) |
665 | { |
644 | { |
666 | 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); |
667 | } |
646 | } |
668 | |
|
|
669 | |
|
|
670 | |
|
|
671 | |
647 | |
672 | /* this function is commonly used to find a friendly target for |
648 | /* this function is commonly used to find a friendly target for |
673 | * spells such as heal or protection or armour |
649 | * spells such as heal or protection or armour |
674 | * 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), |
675 | * 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 |
676 | * NULL if no good object. |
652 | * NULL if no good object. |
677 | */ |
653 | */ |
678 | |
|
|
679 | object * |
654 | object * |
680 | find_target_for_friendly_spell (object *op, int dir) |
655 | find_target_for_friendly_spell (object *op, int dir) |
681 | { |
656 | { |
682 | object *tmp; |
657 | object *tmp; |
683 | mapstruct *m; |
|
|
684 | sint16 x, y; |
|
|
685 | int mflags; |
|
|
686 | |
658 | |
687 | /* 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, |
688 | * we then make the owner of this object the target. |
660 | * we then make the owner of this object the target. |
689 | * The owner could very well be no where near op. |
661 | * The owner could very well be no where near op. |
690 | */ |
662 | */ |
691 | if (op->type != PLAYER && op->type != RUNE) |
663 | if (op->type != PLAYER && op->type != RUNE) |
692 | { |
664 | { |
693 | tmp = get_owner (op); |
665 | tmp = op->owner; |
694 | /* If the owner does not exist, or is not a monster, than apply the spell |
666 | /* If the owner does not exist, or is not a monster, than apply the spell |
695 | * to the caster. |
667 | * to the caster. |
696 | */ |
668 | */ |
697 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
669 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
698 | tmp = op; |
670 | tmp = op; |
699 | } |
671 | } |
700 | else |
672 | else |
701 | { |
673 | { |
702 | m = op->map; |
674 | maptile *m = op->map; |
703 | x = op->x + freearr_x[dir]; |
675 | sint16 x = op->x + freearr_x[dir]; |
704 | y = op->y + freearr_y[dir]; |
676 | sint16 y = op->y + freearr_y[dir]; |
705 | |
|
|
706 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
|
|
707 | |
|
|
708 | if (mflags & P_OUT_OF_MAP) |
|
|
709 | tmp = NULL; |
|
|
710 | else |
|
|
711 | { |
677 | |
712 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
678 | tmp = xy_normalise (m, x, y) |
713 | if (tmp->type == PLAYER) |
679 | ? m->at (x, y).player () |
714 | break; |
680 | : 0; |
715 | } |
|
|
716 | } |
681 | } |
|
|
682 | |
717 | /* 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 */ |
718 | if (tmp == NULL) |
684 | if (!tmp) |
719 | for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
685 | tmp = op->ms ().player (); |
720 | { |
|
|
721 | if (tmp->type == PLAYER) |
|
|
722 | break; |
|
|
723 | } |
|
|
724 | |
686 | |
725 | return tmp; |
687 | return tmp; |
726 | } |
688 | } |
727 | |
689 | |
728 | |
690 | |
… | |
… | |
738 | * any, otherwise -1. |
700 | * any, otherwise -1. |
739 | * note that exclude can be NULL, in which case all bets are off. |
701 | * note that exclude can be NULL, in which case all bets are off. |
740 | */ |
702 | */ |
741 | |
703 | |
742 | int |
704 | int |
743 | spell_find_dir (mapstruct *m, int x, int y, object *exclude) |
705 | spell_find_dir (maptile *m, int x, int y, object *exclude) |
744 | { |
706 | { |
745 | int i, max = SIZEOFFREE; |
707 | int i, max = SIZEOFFREE; |
746 | sint16 nx, ny; |
708 | sint16 nx, ny; |
747 | int owner_type = 0, mflags; |
709 | int owner_type = 0, mflags; |
748 | object *tmp; |
710 | object *tmp; |
749 | mapstruct *mp; |
711 | maptile *mp; |
750 | |
712 | |
751 | if (exclude && exclude->head) |
713 | if (exclude && exclude->head) |
752 | exclude = exclude->head; |
714 | exclude = exclude->head; |
753 | if (exclude && exclude->type) |
715 | if (exclude && exclude->type) |
754 | owner_type = exclude->type; |
716 | owner_type = exclude->type; |
… | |
… | |
760 | mp = m; |
722 | mp = m; |
761 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
723 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
762 | if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) |
724 | if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) |
763 | continue; |
725 | continue; |
764 | |
726 | |
765 | tmp = get_map_ob (mp, nx, ny); |
727 | tmp = GET_MAP_OB (mp, nx, ny); |
766 | |
728 | |
767 | while (tmp != NULL && (((owner_type == PLAYER && |
729 | while (tmp != NULL && (((owner_type == PLAYER && |
768 | !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || |
730 | !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || |
769 | (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude)))) |
731 | (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude)))) |
770 | tmp = tmp->above; |
732 | tmp = tmp->above; |
… | |
… | |
789 | archetype *at; |
751 | archetype *at; |
790 | int dir; |
752 | int dir; |
791 | |
753 | |
792 | /* Handle cases where we are passed a bogus mosntername */ |
754 | /* Handle cases where we are passed a bogus mosntername */ |
793 | |
755 | |
794 | if ((at = find_archetype (monstername)) == NULL) |
756 | if ((at = archetype::find (monstername)) == NULL) |
795 | return; |
757 | return; |
796 | |
758 | |
797 | /* find a free square nearby |
759 | /* find a free square nearby |
798 | * first we check the closest square for free squares |
760 | * first we check the closest square for free squares |
799 | */ |
761 | */ |
… | |
… | |
825 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
787 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
826 | |
788 | |
827 | insert_ob_in_map (head, op->map, op, 0); |
789 | insert_ob_in_map (head, op->map, op, 0); |
828 | |
790 | |
829 | /* thought it'd be cool to insert a burnout, too. */ |
791 | /* thought it'd be cool to insert a burnout, too. */ |
830 | tmp = get_archetype ("burnout"); |
792 | op->map->insert (get_archetype ("burnout"), op->x + freearr_x[dir], op->y + freearr_y[dir], op); |
831 | tmp->map = op->map; |
|
|
832 | tmp->x = op->x + freearr_x[dir]; |
|
|
833 | tmp->y = op->y + freearr_y[dir]; |
|
|
834 | insert_ob_in_map (tmp, op->map, op, 0); |
|
|
835 | } |
793 | } |
836 | } |
794 | } |
837 | |
795 | |
838 | /* peterm: function which summons hostile monsters and |
796 | /* peterm: function which summons hostile monsters and |
839 | * places them in nearby squares. |
797 | * places them in nearby squares. |
… | |
… | |
966 | if (failure <= -20 && failure > -40) /* wonder */ |
924 | if (failure <= -20 && failure > -40) /* wonder */ |
967 | { |
925 | { |
968 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname); |
926 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname); |
969 | tmp = get_archetype (SPELL_WONDER); |
927 | tmp = get_archetype (SPELL_WONDER); |
970 | cast_cone (op, op, 0, tmp); |
928 | cast_cone (op, op, 0, tmp); |
971 | free_object (tmp); |
929 | tmp->destroy (); |
972 | } |
930 | } |
973 | |
931 | |
974 | else if (failure <= -40 && failure > -60) /* confusion */ |
932 | else if (failure <= -40 && failure > -60) /* confusion */ |
975 | { |
933 | { |
976 | new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!"); |
934 | new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!"); |
… | |
… | |
1010 | if (failure <= -20 && failure > -40) /* wonder */ |
968 | if (failure <= -20 && failure > -40) /* wonder */ |
1011 | { |
969 | { |
1012 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect."); |
970 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect."); |
1013 | tmp = get_archetype (SPELL_WONDER); |
971 | tmp = get_archetype (SPELL_WONDER); |
1014 | cast_cone (op, op, 0, tmp); |
972 | cast_cone (op, op, 0, tmp); |
1015 | free_object (tmp); |
973 | tmp->destroy (); |
1016 | } |
974 | } |
1017 | |
975 | |
1018 | else if (failure <= -40 && failure > -60) /* confusion */ |
976 | else if (failure <= -40 && failure > -60) /* confusion */ |
1019 | { |
977 | { |
1020 | new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!"); |
978 | new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!"); |
… | |
… | |
1039 | else |
997 | else |
1040 | { |
998 | { |
1041 | new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); |
999 | new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); |
1042 | tmp = get_archetype (LOOSE_MANA); |
1000 | tmp = get_archetype (LOOSE_MANA); |
1043 | tmp->level = skill->level; |
1001 | tmp->level = skill->level; |
1044 | tmp->x = op->x; |
|
|
1045 | tmp->y = op->y; |
|
|
1046 | |
1002 | |
1047 | /* increase the area of destruction a little for more powerful spells */ |
1003 | /* increase the area of destruction a little for more powerful spells */ |
1048 | tmp->range += isqrt (power); |
1004 | tmp->range += isqrt (power); |
1049 | |
1005 | |
1050 | if (power > 25) |
1006 | if (power > 25) |
1051 | tmp->stats.dam = 25 + isqrt (power); |
1007 | tmp->stats.dam = 25 + isqrt (power); |
1052 | else |
1008 | else |
1053 | tmp->stats.dam = power; /* nasty recoils! */ |
1009 | tmp->stats.dam = power; /* nasty recoils! */ |
1054 | |
1010 | |
1055 | tmp->stats.maxhp = tmp->count; |
1011 | tmp->stats.maxhp = tmp->count; |
1056 | insert_ob_in_map (tmp, op->map, NULL, 0); |
1012 | |
|
|
1013 | tmp->insert_at (op); |
1057 | } |
1014 | } |
1058 | } |
1015 | } |
1059 | } |
1016 | } |
1060 | |
1017 | |
1061 | int |
1018 | int |
1062 | 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) |
1063 | { |
1020 | { |
1064 | int success; |
1021 | int success; |
1065 | player *pl; |
|
|
1066 | object *spell; |
1022 | object *spell; |
1067 | |
1023 | |
1068 | if (!spell_ob->other_arch) |
1024 | if (!spell_ob->other_arch) |
1069 | { |
1025 | { |
1070 | LOG (llevError, "cast_party_spell: empty other arch\n"); |
1026 | LOG (llevError, "cast_party_spell: empty other arch\n"); |
… | |
… | |
1075 | /* Always cast spell on caster */ |
1031 | /* Always cast spell on caster */ |
1076 | success = cast_spell (op, caster, dir, spell, stringarg); |
1032 | success = cast_spell (op, caster, dir, spell, stringarg); |
1077 | |
1033 | |
1078 | if (caster->contr->party == NULL) |
1034 | if (caster->contr->party == NULL) |
1079 | { |
1035 | { |
1080 | remove_ob (spell); |
1036 | spell->remove (); |
1081 | return success; |
1037 | return success; |
1082 | } |
1038 | } |
1083 | for (pl = first_player; pl != NULL; pl = pl->next) |
1039 | for_all_players (pl) |
1084 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1040 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1085 | { |
1041 | { |
1086 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1042 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1087 | } |
1043 | } |
1088 | remove_ob (spell); |
1044 | spell->remove (); |
1089 | return success; |
1045 | return success; |
1090 | } |
1046 | } |
1091 | |
1047 | |
1092 | /* This is where the main dispatch when someone casts a spell. |
1048 | /* This is where the main dispatch when someone casts a spell. |
1093 | * |
1049 | * |
… | |
… | |
1143 | } |
1099 | } |
1144 | |
1100 | |
1145 | /* if caster is a spell casting object, this normally shouldn't be |
1101 | /* if caster is a spell casting object, this normally shouldn't be |
1146 | * an issue, because they don't have any spellpaths set up. |
1102 | * an issue, because they don't have any spellpaths set up. |
1147 | */ |
1103 | */ |
1148 | if (caster->path_denied & spell_ob->path_attuned) |
1104 | if (caster->path_denied & spell_ob->path_attuned && !QUERY_FLAG (caster, FLAG_WIZCAST)) |
1149 | { |
1105 | { |
1150 | new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); |
1106 | new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); |
1151 | return 0; |
1107 | return 0; |
1152 | } |
1108 | } |
1153 | |
1109 | |
… | |
… | |
1186 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1142 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1187 | { |
1143 | { |
1188 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
1144 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
1189 | return 0; |
1145 | return 0; |
1190 | } |
1146 | } |
|
|
1147 | |
1191 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1148 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1192 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) |
1149 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) |
1193 | { |
1150 | { |
1194 | if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - |
1151 | if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - |
1195 | 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) |
1152 | 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) |
… | |
… | |
1208 | 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) < |
1209 | (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])) |
1210 | { |
1167 | { |
1211 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1168 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1212 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); |
1169 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); |
|
|
1170 | |
1213 | if (settings.casting_time == TRUE) |
1171 | if (settings.casting_time == TRUE) |
1214 | { |
|
|
1215 | op->casting_time = -1; |
1172 | op->casting_time = -1; |
1216 | } |
1173 | |
1217 | 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); |
1218 | return 0; |
1175 | return 0; |
1219 | } |
1176 | } |
1220 | else if (spell_ob->stats.sp) |
1177 | else if (spell_ob->stats.sp) |
1221 | { |
1178 | { |
… | |
… | |
1288 | * spell is actually cast, it knows about the stringarg. |
1245 | * spell is actually cast, it knows about the stringarg. |
1289 | * necessary for the invoke command spells. |
1246 | * necessary for the invoke command spells. |
1290 | */ |
1247 | */ |
1291 | if (stringarg) |
1248 | if (stringarg) |
1292 | { |
1249 | { |
1293 | op->spellarg = strdup_local (stringarg); |
1250 | op->spellarg = strdup (stringarg); |
1294 | } |
1251 | } |
1295 | else |
1252 | else |
1296 | op->spellarg = NULL; |
1253 | op->spellarg = NULL; |
1297 | return 0; |
1254 | return 0; |
1298 | } |
1255 | } |
… | |
… | |
1688 | break; |
1645 | break; |
1689 | |
1646 | |
1690 | case SP_MAGIC_MISSILE: |
1647 | case SP_MAGIC_MISSILE: |
1691 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1648 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1692 | { |
1649 | { |
1693 | tag_t spell_tag = spell->count; |
|
|
1694 | |
|
|
1695 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1650 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1696 | if (!was_destroyed (spell, spell_tag)) |
1651 | |
1697 | { |
1652 | if (!spell->destroyed ()) |
1698 | remove_ob (spell); |
1653 | spell->destroy (); |
1699 | free_object (spell); |
|
|
1700 | } |
|
|
1701 | } |
1654 | } |
1702 | break; |
1655 | break; |
1703 | |
1656 | |
1704 | case SP_MOVING_BALL: |
1657 | case SP_MOVING_BALL: |
1705 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1658 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1706 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1659 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1707 | else if (victim->material || victim->materialname) |
1660 | else if (victim->materialname) |
1708 | save_throw_object (victim, spell->attacktype, spell); |
1661 | save_throw_object (victim, spell->attacktype, spell); |
1709 | break; |
1662 | break; |
1710 | } |
1663 | } |
1711 | } |
1664 | } |