| 809 | } |
| 810 | |
| 811 | bool mons_throw(monster* mons, ranged_attack_beam& ratk, bool teleport, bool was_redirected) |
| 812 | { |
| 813 | const item_def &weapon = *ratk.atk.weapon; |
| 814 | bolt& beam = ratk.beam; |
| 815 | |
| 816 | // Energy is already deducted for the spell cast, if using portal projectile |
| 817 | // FIXME: should it use this delay and not the spell delay? |
| 818 | if (!teleport) |
| 819 | { |
| 820 | const int energy = mons->action_energy(EUT_MISSILE); |
| 821 | const int delay = mons->attack_delay(&weapon).roll(); |
| 822 | ASSERT(energy > 0); |
| 823 | ASSERT(delay > 0); |
| 824 | mons->speed_increment -= div_rand_round(energy * delay, 10); |
| 825 | } |
| 826 | |
| 827 | // Avoid overshooting unless we're *trying* to hit allies. |
| 828 | // (Piercing beam tracers should already handle this). |
| 829 | if (!was_redirected) |
| 830 | beam.stop_at_allies |= !beam.pierce; |
| 831 | beam.aimed_at_spot |= _returning(weapon); |
| 832 | |
| 833 | const bool thrown = is_throwable(mons, weapon); |
| 834 | if (mons->observable()) |
| 835 | { |
| 836 | mpr(make_stringf("%s%s %s %s.", |
| 837 | mons->name(DESC_THE).c_str(), |
| 838 | teleport ? " magically" : "", |
| 839 | thrown ? "throws" : "shoots", |
| 840 | article_a(ratk.atk.projectile_name()).c_str()).c_str()); |
| 841 | } |
| 842 | |
| 843 | _throw_noise(mons, weapon); |
| 844 | |
| 845 | const bool uses_ammo = weapon.is_type(OBJ_MISSILES, MI_THROWING_NET); |
| 846 | beam.drop_item = uses_ammo; |
| 847 | |
| 848 | // Redraw the screen before firing, in case the monster just |
| 849 | // came into view and the screen hasn't been updated yet. |
| 850 | viewwindow(); |
| 851 | update_screen(); |
| 852 | const coord_def target = beam.target; |
| 853 | if (teleport) |
| 854 | { |
| 855 | beam.use_target_as_pos = true; |
| 856 | unwind_var<ranged_attack*> old_atk(beam.ranged_atk, &ratk.atk); |
| 857 | beam.affect_cell(); |
| 858 | beam.affect_endpoint(); |
| 859 | } |
| 860 | else |
| 861 | ratk.fire(); |
| 862 | |
| 863 | if (_returning(weapon)) |
| 864 | { |
| 865 | // Fire beam in reverse. |
| 866 | beam.setup_retrace(); |
| 867 | viewwindow(); |
| 868 | update_screen(); |
no test coverage detected