1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_spell_attack_c = |
|
|
4 | * "$Id: spell_attack.C,v 1.10 2006/09/10 23:24:12 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | |
|
|
8 | /* |
1 | /* |
9 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
10 | |
3 | |
11 | Copyright (C) 2002-2003 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002-2003 Mark Wedel & Crossfire Development Team |
12 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
23 | |
16 | |
24 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
25 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
26 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
27 | |
20 | |
28 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
29 | */ |
22 | */ |
30 | |
23 | |
31 | /* This file contains all the spell attack code. Grouping this code |
24 | /* This file contains all the spell attack code. Grouping this code |
32 | * together should hopefully make it easier to find the relevent bits |
25 | * together should hopefully make it easier to find the relevent bits |
33 | * of code |
26 | * of code |
… | |
… | |
124 | void |
117 | void |
125 | forklightning (object *op, object *tmp) |
118 | forklightning (object *op, object *tmp) |
126 | { |
119 | { |
127 | int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */ |
120 | int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */ |
128 | int t_dir; /* stores temporary dir calculation */ |
121 | int t_dir; /* stores temporary dir calculation */ |
129 | mapstruct *m; |
122 | maptile *m; |
130 | sint16 sx, sy; |
123 | sint16 sx, sy; |
131 | object *new_bolt; |
124 | object *new_bolt; |
132 | |
125 | |
133 | /* pick a fork direction. tmp->stats.Con is the left bias |
126 | /* pick a fork direction. tmp->stats.Con is the left bias |
134 | * i.e., the chance in 100 of forking LEFT |
127 | * i.e., the chance in 100 of forking LEFT |
… | |
… | |
147 | |
140 | |
148 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, sx, sy))) |
141 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, sx, sy))) |
149 | return; |
142 | return; |
150 | |
143 | |
151 | /* OK, we made a fork */ |
144 | /* OK, we made a fork */ |
152 | new_bolt = get_object (); |
145 | new_bolt = object::create (); |
153 | copy_object (tmp, new_bolt); |
146 | tmp->copy_to (new_bolt); |
154 | |
147 | |
155 | /* reduce chances of subsequent forking */ |
148 | /* reduce chances of subsequent forking */ |
156 | new_bolt->stats.Dex -= 10; |
149 | new_bolt->stats.Dex -= 10; |
157 | tmp->stats.Dex -= 10; /* less forks from main bolt too */ |
150 | tmp->stats.Dex -= 10; /* less forks from main bolt too */ |
158 | new_bolt->stats.Con += 25 * new_dir; /* adjust the left bias */ |
151 | new_bolt->stats.Con += 25 * new_dir; /* adjust the left bias */ |
… | |
… | |
177 | move_bolt (object *op) |
170 | move_bolt (object *op) |
178 | { |
171 | { |
179 | object *tmp; |
172 | object *tmp; |
180 | int mflags; |
173 | int mflags; |
181 | sint16 x, y; |
174 | sint16 x, y; |
182 | mapstruct *m; |
175 | maptile *m; |
183 | |
176 | |
184 | if (--(op->duration) < 0) |
177 | if (--(op->duration) < 0) |
185 | { |
178 | { |
186 | remove_ob (op); |
179 | op->destroy (); |
187 | free_object (op); |
|
|
188 | return; |
180 | return; |
189 | } |
181 | } |
|
|
182 | |
190 | hit_map (op, 0, op->attacktype, 1); |
183 | hit_map (op, 0, op->attacktype, 1); |
191 | |
184 | |
192 | if (!op->direction) |
185 | if (!op->direction) |
193 | return; |
186 | return; |
194 | |
187 | |
… | |
… | |
256 | update_turn_face (op); /* A bolt *must* be IS_TURNABLE */ |
249 | update_turn_face (op); /* A bolt *must* be IS_TURNABLE */ |
257 | return; |
250 | return; |
258 | } |
251 | } |
259 | else |
252 | else |
260 | { /* Create a copy of this object and put it ahead */ |
253 | { /* Create a copy of this object and put it ahead */ |
261 | tmp = get_object (); |
254 | tmp = object::create (); |
262 | copy_object (op, tmp); |
255 | op->copy_to (tmp); |
263 | tmp->speed_left = -0.1; |
256 | tmp->speed_left = -0.1; |
264 | tmp->x += DIRX (tmp), tmp->y += DIRY (tmp); |
257 | tmp->x += DIRX (tmp), tmp->y += DIRY (tmp); |
265 | tmp = insert_ob_in_map (tmp, op->map, op, 0); |
258 | tmp = insert_ob_in_map (tmp, op->map, op, 0); |
266 | /* To make up for the decrease at the top of the function */ |
259 | /* To make up for the decrease at the top of the function */ |
267 | tmp->duration++; |
260 | tmp->duration++; |
… | |
… | |
326 | tmp->map = op->map; |
319 | tmp->map = op->map; |
327 | |
320 | |
328 | mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); |
321 | mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); |
329 | if (mflags & P_OUT_OF_MAP) |
322 | if (mflags & P_OUT_OF_MAP) |
330 | { |
323 | { |
331 | free_object (tmp); |
324 | tmp->destroy (); |
332 | return 0; |
325 | return 0; |
333 | } |
326 | } |
|
|
327 | |
334 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y))) |
328 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y))) |
335 | { |
329 | { |
336 | if (!QUERY_FLAG (tmp, FLAG_REFLECTING)) |
330 | if (!QUERY_FLAG (tmp, FLAG_REFLECTING)) |
337 | { |
331 | { |
338 | free_object (tmp); |
332 | tmp->destroy (); |
339 | return 0; |
333 | return 0; |
340 | } |
334 | } |
|
|
335 | |
341 | tmp->x = op->x; |
336 | tmp->x = op->x; |
342 | tmp->y = op->y; |
337 | tmp->y = op->y; |
343 | tmp->direction = absdir (tmp->direction + 4); |
338 | tmp->direction = absdir (tmp->direction + 4); |
344 | tmp->map = op->map; |
339 | tmp->map = op->map; |
345 | } |
340 | } |
|
|
341 | |
346 | if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL) |
342 | if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL) |
347 | move_bolt (tmp); |
343 | move_bolt (tmp); |
|
|
344 | |
348 | return 1; |
345 | return 1; |
349 | } |
346 | } |
350 | |
347 | |
351 | |
348 | |
352 | |
349 | |
… | |
… | |
362 | */ |
359 | */ |
363 | void |
360 | void |
364 | explosion (object *op) |
361 | explosion (object *op) |
365 | { |
362 | { |
366 | object *tmp; |
363 | object *tmp; |
367 | mapstruct *m = op->map; |
364 | maptile *m = op->map; |
368 | int i; |
365 | int i; |
369 | |
366 | |
370 | if (--(op->duration) < 0) |
367 | if (--(op->duration) < 0) |
371 | { |
368 | { |
372 | remove_ob (op); |
369 | op->destroy (); |
373 | free_object (op); |
|
|
374 | return; |
370 | return; |
375 | } |
371 | } |
|
|
372 | |
376 | hit_map (op, 0, op->attacktype, 0); |
373 | hit_map (op, 0, op->attacktype, 0); |
377 | |
374 | |
378 | if (op->range > 0) |
375 | if (op->range > 0) |
379 | { |
376 | { |
380 | for (i = 1; i < 9; i++) |
377 | for (i = 1; i < 9; i++) |
… | |
… | |
386 | /* ok_to_put_more already does things like checks for walls, |
383 | /* ok_to_put_more already does things like checks for walls, |
387 | * out of map, etc. |
384 | * out of map, etc. |
388 | */ |
385 | */ |
389 | if (ok_to_put_more (op->map, dx, dy, op, op->attacktype)) |
386 | if (ok_to_put_more (op->map, dx, dy, op, op->attacktype)) |
390 | { |
387 | { |
391 | tmp = get_object (); |
388 | tmp = object::create (); |
392 | copy_object (op, tmp); |
389 | op->copy_to (tmp); |
393 | tmp->state = 0; |
390 | tmp->state = 0; |
394 | tmp->speed_left = -0.21; |
391 | tmp->speed_left = -0.21; |
395 | tmp->range--; |
392 | tmp->range--; |
396 | tmp->value = 0; |
393 | tmp->value = 0; |
397 | tmp->x = dx; |
394 | tmp->x = dx; |
… | |
… | |
408 | * explode. |
405 | * explode. |
409 | */ |
406 | */ |
410 | void |
407 | void |
411 | explode_bullet (object *op) |
408 | explode_bullet (object *op) |
412 | { |
409 | { |
413 | tag_t op_tag = op->count; |
|
|
414 | object *tmp, *owner; |
410 | object *tmp, *owner; |
415 | |
411 | |
416 | if (op->other_arch == NULL) |
412 | if (op->other_arch == NULL) |
417 | { |
413 | { |
418 | LOG (llevError, "BUG: explode_bullet(): op without other_arch\n"); |
414 | LOG (llevError, "BUG: explode_bullet(): op without other_arch\n"); |
419 | remove_ob (op); |
415 | op->destroy (); |
420 | free_object (op); |
|
|
421 | return; |
416 | return; |
422 | } |
417 | } |
423 | |
418 | |
424 | if (op->env) |
419 | if (op->env) |
425 | { |
420 | { |
… | |
… | |
427 | |
422 | |
428 | env = object_get_env_recursive (op); |
423 | env = object_get_env_recursive (op); |
429 | if (env->map == NULL || out_of_map (env->map, env->x, env->y)) |
424 | if (env->map == NULL || out_of_map (env->map, env->x, env->y)) |
430 | { |
425 | { |
431 | LOG (llevError, "BUG: explode_bullet(): env out of map\n"); |
426 | LOG (llevError, "BUG: explode_bullet(): env out of map\n"); |
432 | remove_ob (op); |
427 | op->destroy (); |
433 | free_object (op); |
|
|
434 | return; |
428 | return; |
435 | } |
429 | } |
|
|
430 | |
436 | remove_ob (op); |
431 | op->remove (); |
437 | op->x = env->x; |
432 | op->x = env->x; |
438 | op->y = env->y; |
433 | op->y = env->y; |
439 | insert_ob_in_map (op, env->map, op, INS_NO_MERGE | INS_NO_WALK_ON); |
434 | insert_ob_in_map (op, env->map, op, INS_NO_MERGE | INS_NO_WALK_ON); |
440 | } |
435 | } |
441 | else if (out_of_map (op->map, op->x, op->y)) |
436 | else if (out_of_map (op->map, op->x, op->y)) |
442 | { |
437 | { |
443 | LOG (llevError, "BUG: explode_bullet(): op out of map\n"); |
438 | LOG (llevError, "BUG: explode_bullet(): op out of map\n"); |
444 | remove_ob (op); |
439 | op->destroy (); |
445 | free_object (op); |
|
|
446 | return; |
440 | return; |
447 | } |
441 | } |
448 | |
442 | |
449 | // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent explosions of any kind on safe maps |
443 | // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent explosions of any kind on safe maps |
450 | // NOTE: If this breaks something important: remove this. I can't think of anything |
444 | // NOTE: If this breaks something important: remove this. I can't think of anything |
451 | // bad at the moment that might happen from this. |
445 | // bad at the moment that might happen from this. |
452 | if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) |
446 | if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) |
453 | { |
447 | { |
454 | remove_ob (op); |
448 | op->destroy (); |
455 | free_object (op); |
|
|
456 | return; |
449 | return; |
457 | } |
450 | } |
458 | |
451 | |
459 | if (op->attacktype) |
452 | if (op->attacktype) |
460 | { |
453 | { |
461 | hit_map (op, 0, op->attacktype, 1); |
454 | hit_map (op, 0, op->attacktype, 1); |
462 | if (was_destroyed (op, op_tag)) |
455 | if (op->destroyed ()) |
463 | return; |
456 | return; |
464 | } |
457 | } |
465 | |
458 | |
466 | /* other_arch contains what this explodes into */ |
459 | /* other_arch contains what this explodes into */ |
467 | tmp = arch_to_object (op->other_arch); |
460 | tmp = arch_to_object (op->other_arch); |
… | |
… | |
471 | |
464 | |
472 | owner = get_owner (op); |
465 | owner = get_owner (op); |
473 | |
466 | |
474 | if ((tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) && owner && !tailor_god_spell (tmp, owner)) |
467 | if ((tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) && owner && !tailor_god_spell (tmp, owner)) |
475 | { |
468 | { |
476 | remove_ob (op); |
469 | op->destroy (); |
477 | free_object (op); |
|
|
478 | return; |
470 | return; |
479 | } |
471 | } |
480 | |
472 | |
481 | tmp->x = op->x; |
473 | tmp->x = op->x; |
482 | tmp->y = op->y; |
474 | tmp->y = op->y; |
… | |
… | |
510 | /* Prevent recursion */ |
502 | /* Prevent recursion */ |
511 | op->move_on = 0; |
503 | op->move_on = 0; |
512 | |
504 | |
513 | insert_ob_in_map (tmp, op->map, op, 0); |
505 | insert_ob_in_map (tmp, op->map, op, 0); |
514 | /* remove the firebullet */ |
506 | /* remove the firebullet */ |
515 | if (!was_destroyed (op, op_tag)) |
507 | if (!op->destroyed ()) |
516 | { |
508 | { |
517 | remove_ob (op); |
509 | op->destroy (); |
518 | free_object (op); |
|
|
519 | } |
510 | } |
520 | } |
511 | } |
521 | |
512 | |
522 | |
513 | |
523 | |
514 | |
… | |
… | |
526 | */ |
517 | */ |
527 | |
518 | |
528 | void |
519 | void |
529 | check_bullet (object *op) |
520 | check_bullet (object *op) |
530 | { |
521 | { |
531 | tag_t op_tag = op->count, tmp_tag; |
|
|
532 | object *tmp; |
522 | object *tmp; |
533 | int dam, mflags; |
523 | int dam, mflags; |
534 | mapstruct *m; |
524 | maptile *m; |
535 | sint16 sx, sy; |
525 | sint16 sx, sy; |
536 | |
526 | |
537 | mflags = get_map_flags (op->map, &m, op->x, op->y, &sx, &sy); |
527 | mflags = get_map_flags (op->map, &m, op->x, op->y, &sx, &sy); |
538 | |
528 | |
539 | if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy))) |
529 | if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy))) |
… | |
… | |
552 | |
542 | |
553 | for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
543 | for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
554 | { |
544 | { |
555 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
545 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
556 | { |
546 | { |
557 | tmp_tag = tmp->count; |
|
|
558 | dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1); |
547 | dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1); |
559 | if (was_destroyed (op, op_tag) || !was_destroyed (tmp, tmp_tag) || (op->stats.dam -= dam) < 0) |
548 | if (op->destroyed () || !tmp->destroyed () || (op->stats.dam -= dam) < 0) |
560 | { |
549 | { |
561 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
550 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
562 | { |
551 | { |
563 | remove_ob (op); |
552 | op->destroy (); |
564 | free_object (op); |
|
|
565 | return; |
553 | return; |
566 | } |
554 | } |
567 | } |
555 | } |
568 | } |
556 | } |
569 | } |
557 | } |
… | |
… | |
579 | void |
567 | void |
580 | move_bullet (object *op) |
568 | move_bullet (object *op) |
581 | { |
569 | { |
582 | sint16 new_x, new_y; |
570 | sint16 new_x, new_y; |
583 | int mflags; |
571 | int mflags; |
584 | mapstruct *m; |
572 | maptile *m; |
585 | |
573 | |
586 | #if 0 |
574 | #if 0 |
587 | /* We need a better general purpose way to do this */ |
575 | /* We need a better general purpose way to do this */ |
588 | |
576 | |
589 | /* peterm: added to make comet leave a trail of burnouts |
577 | /* peterm: added to make comet leave a trail of burnouts |
590 | it's an unadulterated hack, but the effect is cool. */ |
578 | it's an unadulterated hack, but the effect is cool. */ |
591 | if (op->stats.sp == SP_METEOR) |
579 | if (op->stats.sp == SP_METEOR) |
592 | { |
580 | { |
593 | replace_insert_ob_in_map ("fire_trail", op); |
581 | replace_insert_ob_in_map ("fire_trail", op); |
594 | if (was_destroyed (op, op_tag)) |
582 | if (op->destroyed ()) |
595 | return; |
583 | return; |
596 | } /* end addition. */ |
584 | } /* end addition. */ |
597 | #endif |
585 | #endif |
598 | |
586 | |
599 | /* Reached the end of its life - remove it */ |
587 | /* Reached the end of its life - remove it */ |
600 | if (--op->range <= 0) |
588 | if (--op->range <= 0) |
601 | { |
589 | { |
602 | if (op->other_arch) |
590 | if (op->other_arch) |
603 | { |
|
|
604 | explode_bullet (op); |
591 | explode_bullet (op); |
605 | } |
|
|
606 | else |
592 | else |
607 | { |
593 | op->destroy (); |
608 | remove_ob (op); |
594 | |
609 | free_object (op); |
|
|
610 | } |
|
|
611 | return; |
595 | return; |
612 | } |
596 | } |
613 | |
597 | |
614 | new_x = op->x + DIRX (op); |
598 | new_x = op->x + DIRX (op); |
615 | new_y = op->y + DIRY (op); |
599 | new_y = op->y + DIRY (op); |
616 | m = op->map; |
600 | m = op->map; |
617 | mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y); |
601 | mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y); |
618 | |
602 | |
619 | if (mflags & P_OUT_OF_MAP) |
603 | if (mflags & P_OUT_OF_MAP) |
620 | { |
604 | { |
621 | remove_ob (op); |
605 | op->destroy (); |
622 | free_object (op); |
|
|
623 | return; |
606 | return; |
624 | } |
607 | } |
625 | |
608 | |
626 | if (!op->direction || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) |
609 | if (!op->direction || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) |
627 | { |
610 | { |
628 | if (op->other_arch) |
611 | if (op->other_arch) |
629 | { |
|
|
630 | explode_bullet (op); |
612 | explode_bullet (op); |
631 | } |
|
|
632 | else |
613 | else |
633 | { |
614 | op->destroy (); |
634 | remove_ob (op); |
615 | |
635 | free_object (op); |
|
|
636 | } |
|
|
637 | return; |
616 | return; |
638 | } |
617 | } |
639 | |
618 | |
640 | remove_ob (op); |
619 | op->remove (); |
641 | op->x = new_x; |
620 | op->x = new_x; |
642 | op->y = new_y; |
621 | op->y = new_y; |
643 | if ((op = insert_ob_in_map (op, m, op, 0)) == NULL) |
622 | if ((op = insert_ob_in_map (op, m, op, 0)) == NULL) |
644 | return; |
623 | return; |
645 | |
624 | |
… | |
… | |
704 | tmp->map = op->map; |
683 | tmp->map = op->map; |
705 | |
684 | |
706 | mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); |
685 | mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); |
707 | if (mflags & P_OUT_OF_MAP) |
686 | if (mflags & P_OUT_OF_MAP) |
708 | { |
687 | { |
709 | free_object (tmp); |
688 | tmp->destroy (); |
710 | return 0; |
689 | return 0; |
711 | } |
690 | } |
|
|
691 | |
712 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y))) |
692 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y))) |
713 | { |
693 | { |
714 | if (!QUERY_FLAG (tmp, FLAG_REFLECTING)) |
694 | if (!QUERY_FLAG (tmp, FLAG_REFLECTING)) |
715 | { |
695 | { |
716 | free_object (tmp); |
696 | tmp->destroy (); |
717 | return 0; |
697 | return 0; |
718 | } |
698 | } |
|
|
699 | |
719 | tmp->x = op->x; |
700 | tmp->x = op->x; |
720 | tmp->y = op->y; |
701 | tmp->y = op->y; |
721 | tmp->direction = absdir (tmp->direction + 4); |
702 | tmp->direction = absdir (tmp->direction + 4); |
722 | tmp->map = op->map; |
703 | tmp->map = op->map; |
723 | } |
704 | } |
|
|
705 | |
724 | if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL) |
706 | if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL) |
725 | { |
|
|
726 | check_bullet (tmp); |
707 | check_bullet (tmp); |
727 | } |
708 | |
728 | return 1; |
709 | return 1; |
729 | } |
710 | } |
730 | |
711 | |
731 | |
712 | |
732 | |
713 | |
… | |
… | |
762 | |
743 | |
763 | void |
744 | void |
764 | move_cone (object *op) |
745 | move_cone (object *op) |
765 | { |
746 | { |
766 | int i; |
747 | int i; |
767 | tag_t tag; |
|
|
768 | |
748 | |
769 | /* if no map then hit_map will crash so just ignore object */ |
749 | /* if no map then hit_map will crash so just ignore object */ |
770 | if (!op->map) |
750 | if (!op->map) |
771 | { |
751 | { |
772 | LOG (llevError, "Tried to move_cone object %s without a map.\n", op->name ? &op->name : "unknown"); |
752 | LOG (llevError, "Tried to move_cone object %s without a map.\n", op->name ? &op->name : "unknown"); |
… | |
… | |
787 | * when their cone dies when they die. |
767 | * when their cone dies when they die. |
788 | */ |
768 | */ |
789 | /* If no owner left, the spell dies out. */ |
769 | /* If no owner left, the spell dies out. */ |
790 | if (get_owner (op) == NULL) |
770 | if (get_owner (op) == NULL) |
791 | { |
771 | { |
792 | remove_ob (op); |
772 | op->destroy (); |
793 | free_object (op); |
|
|
794 | return; |
773 | return; |
795 | } |
774 | } |
796 | #endif |
775 | #endif |
797 | |
776 | |
798 | tag = op->count; |
|
|
799 | hit_map (op, 0, op->attacktype, 0); |
777 | hit_map (op, 0, op->attacktype, 0); |
800 | |
778 | |
801 | /* Check to see if we should push anything. |
779 | /* Check to see if we should push anything. |
802 | * Spell objects with weight push whatever they encounter to some |
780 | * Spell objects with weight push whatever they encounter to some |
803 | * degree. |
781 | * degree. |
804 | */ |
782 | */ |
805 | if (op->weight) |
783 | if (op->weight) |
806 | check_spell_knockback (op); |
784 | check_spell_knockback (op); |
807 | |
785 | |
808 | if (was_destroyed (op, tag)) |
786 | if (op->destroyed ()) |
809 | return; |
787 | return; |
810 | |
788 | |
811 | if ((op->duration--) < 0) |
789 | if ((op->duration--) < 0) |
812 | { |
790 | { |
813 | remove_ob (op); |
791 | op->destroy (); |
814 | free_object (op); |
|
|
815 | return; |
792 | return; |
816 | } |
793 | } |
817 | /* Object has hit maximum range, so don't have it move |
794 | /* Object has hit maximum range, so don't have it move |
818 | * any further. When the duration above expires, |
795 | * any further. When the duration above expires, |
819 | * then the object will get removed. |
796 | * then the object will get removed. |
… | |
… | |
828 | { |
805 | { |
829 | sint16 x = op->x + freearr_x[absdir (op->stats.sp + i)], y = op->y + freearr_y[absdir (op->stats.sp + i)]; |
806 | sint16 x = op->x + freearr_x[absdir (op->stats.sp + i)], y = op->y + freearr_y[absdir (op->stats.sp + i)]; |
830 | |
807 | |
831 | if (ok_to_put_more (op->map, x, y, op, op->attacktype)) |
808 | if (ok_to_put_more (op->map, x, y, op, op->attacktype)) |
832 | { |
809 | { |
833 | object *tmp = get_object (); |
810 | object *tmp = object::create (); |
834 | |
811 | |
835 | copy_object (op, tmp); |
812 | op->copy_to (tmp); |
836 | tmp->x = x; |
813 | tmp->x = x; |
837 | tmp->y = y; |
814 | tmp->y = y; |
838 | |
815 | |
839 | tmp->duration = op->duration + 1; |
816 | tmp->duration = op->duration + 1; |
840 | |
817 | |
… | |
… | |
858 | int |
835 | int |
859 | cast_cone (object *op, object *caster, int dir, object *spell) |
836 | cast_cone (object *op, object *caster, int dir, object *spell) |
860 | { |
837 | { |
861 | object *tmp; |
838 | object *tmp; |
862 | int i, success = 0, range_min = -1, range_max = 1; |
839 | int i, success = 0, range_min = -1, range_max = 1; |
863 | mapstruct *m; |
840 | maptile *m; |
864 | sint16 sx, sy; |
841 | sint16 sx, sy; |
865 | MoveType movetype; |
842 | MoveType movetype; |
866 | |
843 | |
867 | if (!spell->other_arch) |
844 | if (!spell->other_arch) |
868 | return 0; |
845 | return 0; |
… | |
… | |
1023 | return; |
1000 | return; |
1024 | |
1001 | |
1025 | if (env->type == PLAYER) |
1002 | if (env->type == PLAYER) |
1026 | esrv_del_item (env->contr, op->count); |
1003 | esrv_del_item (env->contr, op->count); |
1027 | |
1004 | |
1028 | remove_ob (op); |
1005 | op->remove (); |
1029 | op->x = env->x; |
1006 | op->x = env->x; |
1030 | op->y = env->y; |
1007 | op->y = env->y; |
1031 | if ((op = insert_ob_in_map (op, env->map, op, 0)) == NULL) |
1008 | if ((op = insert_ob_in_map (op, env->map, op, 0)) == NULL) |
1032 | return; |
1009 | return; |
1033 | } |
1010 | } |
… | |
… | |
1035 | // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent bomb from exploding |
1012 | // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent bomb from exploding |
1036 | // on a safe map. I don't like this special casing, but it seems to be neccessary |
1013 | // on a safe map. I don't like this special casing, but it seems to be neccessary |
1037 | // as bombs can be carried. |
1014 | // as bombs can be carried. |
1038 | if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) |
1015 | if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) |
1039 | { |
1016 | { |
1040 | remove_ob (op); |
1017 | op->destroy (); |
1041 | free_object (op); |
|
|
1042 | return; |
1018 | return; |
1043 | } |
1019 | } |
1044 | |
1020 | |
1045 | /* This copies a lot of the code from the fire bullet, |
1021 | /* This copies a lot of the code from the fire bullet, |
1046 | * but using the cast_bullet isn't really feasible, |
1022 | * but using the cast_bullet isn't really feasible, |
1047 | * so just set up the appropriate values. |
1023 | * so just set up the appropriate values. |
1048 | */ |
1024 | */ |
1049 | at = find_archetype (SPLINT); |
1025 | at = archetype::find (SPLINT); |
1050 | if (at) |
1026 | if (at) |
1051 | { |
1027 | { |
1052 | for (i = 1; i < 9; i++) |
1028 | for (i = 1; i < 9; i++) |
1053 | { |
1029 | { |
1054 | if (out_of_map (op->map, op->x + freearr_x[i], op->y + freearr_x[i])) |
1030 | if (out_of_map (op->map, op->x + freearr_x[i], op->y + freearr_x[i])) |
… | |
… | |
1081 | { |
1057 | { |
1082 | |
1058 | |
1083 | object *tmp; |
1059 | object *tmp; |
1084 | int mflags; |
1060 | int mflags; |
1085 | sint16 dx = op->x + freearr_x[dir], dy = op->y + freearr_y[dir]; |
1061 | sint16 dx = op->x + freearr_x[dir], dy = op->y + freearr_y[dir]; |
1086 | mapstruct *m; |
1062 | maptile *m; |
1087 | |
1063 | |
1088 | mflags = get_map_flags (op->map, &m, dx, dy, &dx, &dy); |
1064 | mflags = get_map_flags (op->map, &m, dx, dy, &dx, &dy); |
1089 | if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK (m, dx, dy) & MOVE_WALK)) |
1065 | if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK (m, dx, dy) & MOVE_WALK)) |
1090 | { |
1066 | { |
1091 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
1067 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
… | |
… | |
1127 | get_pointed_target (object *op, int dir, int range, int type) |
1103 | get_pointed_target (object *op, int dir, int range, int type) |
1128 | { |
1104 | { |
1129 | object *target; |
1105 | object *target; |
1130 | sint16 x, y; |
1106 | sint16 x, y; |
1131 | int dist, mflags; |
1107 | int dist, mflags; |
1132 | mapstruct *mp; |
1108 | maptile *mp; |
1133 | |
1109 | |
1134 | if (dir == 0) |
1110 | if (dir == 0) |
1135 | return NULL; |
1111 | return NULL; |
1136 | |
1112 | |
1137 | for (dist = 1; dist < range; dist++) |
1113 | for (dist = 1; dist < range; dist++) |
… | |
… | |
1240 | } |
1216 | } |
1241 | else |
1217 | else |
1242 | { |
1218 | { |
1243 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s looks stronger!", query_name (target)); |
1219 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s looks stronger!", query_name (target)); |
1244 | target->stats.hp = target->stats.maxhp * 2; |
1220 | target->stats.hp = target->stats.maxhp * 2; |
1245 | free_object (effect); |
1221 | effect->destroy (); |
1246 | return 0; |
1222 | return 0; |
1247 | } |
1223 | } |
1248 | } |
1224 | } |
1249 | } |
1225 | } |
1250 | else |
1226 | else |
… | |
… | |
1277 | move_missile (object *op) |
1253 | move_missile (object *op) |
1278 | { |
1254 | { |
1279 | int i, mflags; |
1255 | int i, mflags; |
1280 | object *owner; |
1256 | object *owner; |
1281 | sint16 new_x, new_y; |
1257 | sint16 new_x, new_y; |
1282 | mapstruct *m; |
1258 | maptile *m; |
1283 | |
1259 | |
1284 | if (op->range-- <= 0) |
1260 | if (op->range-- <= 0) |
1285 | { |
1261 | { |
1286 | remove_ob (op); |
1262 | op->destroy (); |
1287 | free_object (op); |
|
|
1288 | return; |
1263 | return; |
1289 | } |
1264 | } |
1290 | |
1265 | |
1291 | owner = get_owner (op); |
1266 | owner = get_owner (op); |
1292 | #if 0 |
1267 | #if 0 |
1293 | /* It'd make things nastier if this wasn't here - spells cast by |
1268 | /* It'd make things nastier if this wasn't here - spells cast by |
1294 | * monster that are then killed would continue to survive |
1269 | * monster that are then killed would continue to survive |
1295 | */ |
1270 | */ |
1296 | if (owner == NULL) |
1271 | if (owner == NULL) |
1297 | { |
1272 | { |
1298 | remove_ob (op); |
1273 | op->destroy (); |
1299 | free_object (op); |
|
|
1300 | return; |
1274 | return; |
1301 | } |
1275 | } |
1302 | #endif |
1276 | #endif |
1303 | |
1277 | |
1304 | new_x = op->x + DIRX (op); |
1278 | new_x = op->x + DIRX (op); |
… | |
… | |
1306 | |
1280 | |
1307 | mflags = get_map_flags (op->map, &m, new_x, new_y, &new_x, &new_y); |
1281 | mflags = get_map_flags (op->map, &m, new_x, new_y, &new_x, &new_y); |
1308 | |
1282 | |
1309 | if (!(mflags & P_OUT_OF_MAP) && ((mflags & P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y)))) |
1283 | if (!(mflags & P_OUT_OF_MAP) && ((mflags & P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y)))) |
1310 | { |
1284 | { |
1311 | tag_t tag = op->count; |
|
|
1312 | |
|
|
1313 | hit_map (op, op->direction, AT_MAGIC, 1); |
1285 | hit_map (op, op->direction, AT_MAGIC, 1); |
1314 | /* Basically, missile only hits one thing then goes away. |
1286 | /* Basically, missile only hits one thing then goes away. |
1315 | * we need to remove it if someone hasn't already done so. |
1287 | * we need to remove it if someone hasn't already done so. |
1316 | */ |
1288 | */ |
1317 | if (!was_destroyed (op, tag)) |
1289 | if (!op->destroyed ()) |
1318 | { |
1290 | op->destroy (); |
1319 | remove_ob (op); |
1291 | |
1320 | free_object (op); |
|
|
1321 | } |
|
|
1322 | return; |
1292 | return; |
1323 | } |
1293 | } |
1324 | |
1294 | |
1325 | remove_ob (op); |
1295 | op->remove (); |
|
|
1296 | |
1326 | if (!op->direction || (mflags & P_OUT_OF_MAP)) |
1297 | if (!op->direction || (mflags & P_OUT_OF_MAP)) |
1327 | { |
1298 | { |
1328 | free_object (op); |
1299 | op->destroy (); |
1329 | return; |
1300 | return; |
1330 | } |
1301 | } |
|
|
1302 | |
1331 | op->x = new_x; |
1303 | op->x = new_x; |
1332 | op->y = new_y; |
1304 | op->y = new_y; |
1333 | op->map = m; |
1305 | op->map = m; |
1334 | i = spell_find_dir (op->map, op->x, op->y, get_owner (op)); |
1306 | i = spell_find_dir (op->map, op->x, op->y, get_owner (op)); |
1335 | if (i > 0 && i != op->direction) |
1307 | if (i > 0 && i != op->direction) |
1336 | { |
1308 | { |
1337 | op->direction = i; |
1309 | op->direction = i; |
1338 | SET_ANIMATION (op, op->direction); |
1310 | SET_ANIMATION (op, op->direction); |
1339 | } |
1311 | } |
|
|
1312 | |
1340 | insert_ob_in_map (op, op->map, op, 0); |
1313 | insert_ob_in_map (op, op->map, op, 0); |
1341 | } |
1314 | } |
1342 | |
1315 | |
1343 | /**************************************************************************** |
1316 | /**************************************************************************** |
1344 | * Destruction |
1317 | * Destruction |
… | |
… | |
1390 | int |
1363 | int |
1391 | cast_destruction (object *op, object *caster, object *spell_ob) |
1364 | cast_destruction (object *op, object *caster, object *spell_ob) |
1392 | { |
1365 | { |
1393 | int i, j, range, mflags, friendly = 0, dam, dur; |
1366 | int i, j, range, mflags, friendly = 0, dam, dur; |
1394 | sint16 sx, sy; |
1367 | sint16 sx, sy; |
1395 | mapstruct *m; |
1368 | maptile *m; |
1396 | object *tmp; |
1369 | object *tmp; |
1397 | const char *skill; |
1370 | const char *skill; |
1398 | |
1371 | |
1399 | range = spell_ob->range + SP_level_range_adjust (caster, spell_ob); |
1372 | range = spell_ob->range + SP_level_range_adjust (caster, spell_ob); |
1400 | dam = spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob); |
1373 | dam = spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob); |
… | |
… | |
1582 | mood_change (object *op, object *caster, object *spell) |
1555 | mood_change (object *op, object *caster, object *spell) |
1583 | { |
1556 | { |
1584 | object *tmp, *god, *head; |
1557 | object *tmp, *god, *head; |
1585 | int done_one, range, mflags, level, at, best_at; |
1558 | int done_one, range, mflags, level, at, best_at; |
1586 | sint16 x, y, nx, ny; |
1559 | sint16 x, y, nx, ny; |
1587 | mapstruct *m; |
1560 | maptile *m; |
1588 | const char *race; |
1561 | const char *race; |
1589 | |
1562 | |
1590 | /* We precompute some values here so that we don't have to keep |
1563 | /* We precompute some values here so that we don't have to keep |
1591 | * doing it over and over again. |
1564 | * doing it over and over again. |
1592 | */ |
1565 | */ |
… | |
… | |
1756 | move_ball_spell (object *op) |
1729 | move_ball_spell (object *op) |
1757 | { |
1730 | { |
1758 | int i, j, dam_save, dir, mflags; |
1731 | int i, j, dam_save, dir, mflags; |
1759 | sint16 nx, ny, hx, hy; |
1732 | sint16 nx, ny, hx, hy; |
1760 | object *owner; |
1733 | object *owner; |
1761 | mapstruct *m; |
1734 | maptile *m; |
1762 | |
1735 | |
1763 | owner = get_owner (op); |
1736 | owner = get_owner (op); |
1764 | |
1737 | |
1765 | /* the following logic makes sure that the ball doesn't move into a wall, |
1738 | /* the following logic makes sure that the ball doesn't move into a wall, |
1766 | * and makes sure that it will move along a wall to try and get at it's |
1739 | * and makes sure that it will move along a wall to try and get at it's |
… | |
… | |
1797 | nx = op->x; |
1770 | nx = op->x; |
1798 | ny = op->y; |
1771 | ny = op->y; |
1799 | m = op->map; |
1772 | m = op->map; |
1800 | } |
1773 | } |
1801 | |
1774 | |
1802 | remove_ob (op); |
1775 | op->remove (); |
1803 | op->y = ny; |
1776 | op->y = ny; |
1804 | op->x = nx; |
1777 | op->x = nx; |
1805 | insert_ob_in_map (op, m, op, 0); |
1778 | insert_ob_in_map (op, m, op, 0); |
1806 | |
1779 | |
1807 | dam_save = op->stats.dam; /* save the original dam: we do halfdam on |
1780 | dam_save = op->stats.dam; /* save the original dam: we do halfdam on |
… | |
… | |
1878 | #if 0 |
1851 | #if 0 |
1879 | static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 }; |
1852 | static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 }; |
1880 | static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 }; |
1853 | static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 }; |
1881 | sint16 target_x, target_y, origin_x, origin_y; |
1854 | sint16 target_x, target_y, origin_x, origin_y; |
1882 | int adjustdir; |
1855 | int adjustdir; |
1883 | mapstruct *m; |
1856 | maptile *m; |
1884 | #endif |
1857 | #endif |
1885 | int basedir; |
1858 | int basedir; |
1886 | object *owner; |
1859 | object *owner; |
1887 | |
1860 | |
1888 | owner = get_owner (op); |
1861 | owner = get_owner (op); |
1889 | if (op->duration == 0 || owner == NULL) |
1862 | if (op->duration == 0 || owner == NULL) |
1890 | { |
1863 | { |
1891 | remove_ob (op); |
1864 | op->destroy (); |
1892 | free_object (op); |
|
|
1893 | return; |
1865 | return; |
1894 | } |
1866 | } |
|
|
1867 | |
1895 | op->duration--; |
1868 | op->duration--; |
1896 | |
1869 | |
1897 | basedir = op->direction; |
1870 | basedir = op->direction; |
1898 | if (basedir == 0) |
1871 | if (basedir == 0) |
1899 | { |
1872 | { |
… | |
… | |
2031 | cast_light (object *op, object *caster, object *spell, int dir) |
2004 | cast_light (object *op, object *caster, object *spell, int dir) |
2032 | { |
2005 | { |
2033 | object *target = NULL, *tmp = NULL; |
2006 | object *target = NULL, *tmp = NULL; |
2034 | sint16 x, y; |
2007 | sint16 x, y; |
2035 | int dam, mflags; |
2008 | int dam, mflags; |
2036 | mapstruct *m; |
2009 | maptile *m; |
2037 | |
2010 | |
2038 | dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); |
2011 | dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); |
2039 | |
2012 | |
2040 | if (!dir) |
2013 | if (!dir) |
2041 | { |
2014 | { |
… | |
… | |
2109 | cast_cause_disease (object *op, object *caster, object *spell, int dir) |
2082 | cast_cause_disease (object *op, object *caster, object *spell, int dir) |
2110 | { |
2083 | { |
2111 | sint16 x, y; |
2084 | sint16 x, y; |
2112 | int i, mflags, range, dam_mod, dur_mod; |
2085 | int i, mflags, range, dam_mod, dur_mod; |
2113 | object *walk; |
2086 | object *walk; |
2114 | mapstruct *m; |
2087 | maptile *m; |
2115 | |
2088 | |
2116 | x = op->x; |
2089 | x = op->x; |
2117 | y = op->y; |
2090 | y = op->y; |
2118 | |
2091 | |
2119 | /* If casting from a scroll, no direction will be available, so refer to the |
2092 | /* If casting from a scroll, no direction will be available, so refer to the |
… | |
… | |
2211 | { |
2184 | { |
2212 | object *flash; /* visual effect for inflicting disease */ |
2185 | object *flash; /* visual effect for inflicting disease */ |
2213 | |
2186 | |
2214 | new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name); |
2187 | new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name); |
2215 | |
2188 | |
2216 | free_object (disease); /* don't need this one anymore */ |
2189 | disease->destroy (); /* don't need this one anymore */ |
2217 | flash = get_archetype (ARCH_DETECT_MAGIC); |
2190 | flash = get_archetype (ARCH_DETECT_MAGIC); |
2218 | flash->x = x; |
2191 | flash->x = x; |
2219 | flash->y = y; |
2192 | flash->y = y; |
2220 | flash->map = walk->map; |
2193 | flash->map = walk->map; |
2221 | insert_ob_in_map (flash, walk->map, op, 0); |
2194 | insert_ob_in_map (flash, walk->map, op, 0); |
2222 | return 1; |
2195 | return 1; |
2223 | } |
2196 | } |
2224 | free_object (disease); |
2197 | |
|
|
2198 | disease->destroy (); |
2225 | } |
2199 | } |
2226 | } /* if living creature */ |
2200 | } /* if living creature */ |
2227 | } /* for range of spaces */ |
2201 | } /* for range of spaces */ |
2228 | new_draw_info (NDI_UNIQUE, 0, op, "No one caught anything!"); |
2202 | new_draw_info (NDI_UNIQUE, 0, op, "No one caught anything!"); |
2229 | return 1; |
2203 | return 1; |