MCPcopy Create free account
hub / github.com/crawl/crawl / aim_player_ranged_attack

Function aim_player_ranged_attack

crawl-ref/source/throw.cc:658–702  ·  view source on GitHub ↗

Aim and then perform a standard ranged attack, either by autofight or the quiver interface.

Source from the content-addressed store, hash-verified

656
657// Aim and then perform a standard ranged attack, either by autofight or the quiver interface.
658void aim_player_ranged_attack(quiver::action &a)
659{
660 ASSERT(a.get_item() >= 0);
661 item_def* item = &you.inv[a.get_item()];
662 const bool throwing = item->base_type == OBJ_MISSILES;
663
664 if (you.confused())
665 {
666 do
667 {
668 a.target.target.x = you.pos().x + random2(13) - 6;
669 a.target.target.y = you.pos().y + random2(13) - 6;
670 } while (a.target.target == you.pos());
671
672 a.target.isValid = true;
673 a.target.cmd_result = CMD_FIRE;
674 }
675 else
676 {
677 // non-confused interactive or non-interactive firing
678 fire_target_behaviour beh(a);
679 direction_chooser_args args;
680 args.behaviour = &beh;
681 args.mode = TARG_HOSTILE;
682 args.self = confirm_prompt_type::cancel;
683 direction(a.target, args);
684 }
685 if (!a.target.isValid || a.target.isCancel)
686 return;
687
688 // Now that we have a target, set up the attacks and run tracers
689 // (which may also adjust targeting slightly).
690 vector<ranged_attack_beam> atks = _construct_player_ranged_beams(throwing ? item : nullptr);
691
692 for (ranged_attack_beam& atk : atks)
693 atk.beam.set_target(a.target);
694
695 if (_trace_player_ranged_attacks(atks))
696 return;
697
698 // Actually perform the attack and spend time.
699 you.time_taken = you.attack_delay(item).roll();
700 _fire_player_ranged_attacks(atks);
701 you.turn_is_over = true;
702}
703
704// Make the player immediately perform a ranged attack at a given target, optionally
705// with a specific projectile. Does not handle spending time.

Callers 2

triggerMethod · 0.85
triggerMethod · 0.85

Calls 11

random2Function · 0.85
directionFunction · 0.85
get_itemMethod · 0.45
confusedMethod · 0.45
posMethod · 0.45
set_targetMethod · 0.45
rollMethod · 0.45
attack_delayMethod · 0.45

Tested by

no test coverage detected