*/
void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPELL_IDX snipe_type)
{
- DIRECTION dir;
- int i;
POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
- int tdam_base, tdis, thits, tmul;
- int bonus, chance;
- int cur_dis, visible;
- PERCENTAGE j;
-
ItemEntity forge;
ItemEntity *q_ptr;
ItemEntity *o_ptr;
AttributeFlags attribute_flags{};
attribute_flags.set(AttributeType::PLAYER_SHOOT);
- bool hit_body = false;
-
- GAME_TEXT o_name[MAX_NLEN];
-
- /* STICK TO */
- bool stick_to = false;
+ auto hit_body = false;
+ auto stick_to = false;
/* Access the item (if in the pack) */
if (item >= 0) {
snipe_type = SP_NONE;
}
+ GAME_TEXT o_name[MAX_NLEN];
describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
/* Use the proper number of shots */
- thits = player_ptr->num_fire;
+ auto thits = player_ptr->num_fire;
/* Use a base distance */
- tdis = 10;
+ auto tdis = 10;
/* Base damage from thrown object plus launcher bonus */
- tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
+ auto tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
/* Actually "fire" the object */
- bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
+ auto bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
+ int chance;
+ auto weapon_exp = player_ptr->weapon_exp[j_ptr->tval][j_ptr->sval];
if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW)) {
- chance = (player_ptr->skill_thb + (player_ptr->weapon_exp[j_ptr->tval][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
+ chance = (player_ptr->skill_thb + (weapon_exp / 400 + bonus) * BTH_PLUS_ADJ);
} else {
- chance = (player_ptr->skill_thb + ((player_ptr->weapon_exp[j_ptr->tval][j_ptr->sval] - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
+ chance = (player_ptr->skill_thb + ((weapon_exp - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
}
PlayerEnergy(player_ptr).set_player_turn_energy(j_ptr->get_bow_energy());
- tmul = bow_tmul(j_ptr->sval);
+ auto tmul = j_ptr->get_arrow_magnification();
/* Get extra "power" from "extra might" */
if (player_ptr->xtra_might) {
project_length = tdis + 1;
/* Get a direction (or cancel) */
+ DIRECTION dir;
if (!get_aim_dir(player_ptr, &dir)) {
PlayerEnergy(player_ptr).reset_player_turn();
}
/* Take a (partial) turn */
- PlayerEnergy(player_ptr).div_player_turn_energy((ENERGY)thits);
+ PlayerEnergy(player_ptr).div_player_turn_energy(thits);
player_ptr->is_fired = true;
/* Sniper - Difficult to shot twice at 1 turn */
}
/* Sniper - Repeat shooting when double shots */
- for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
+ for (auto i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
/* Start at the player */
y = player_ptr->y;
x = player_ptr->x;
hit_body = false;
/* Travel until stopped */
- for (cur_dis = 0; cur_dis <= tdis;) {
+ for (auto cur_dis = 0; cur_dis <= tdis;) {
grid_type *g_ptr;
/* Hack -- Stop at the target */
auto *r_ptr = &monraces_info[m_ptr->r_idx];
/* Check the visibility */
- visible = m_ptr->ml;
+ auto visible = m_ptr->ml;
/* Note the collision */
hit_body = true;
}
/* Chance of breakage (during attacks) */
- j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
+ auto j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
if (stick_to) {
MONSTER_IDX m_idx = player_ptr->current_floor_ptr->grid_array[y][x].m_idx;
return dam;
}
-/*
- * Return bow tmul
- */
-int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
-{
- int tmul = 0;
-
- /* Analyze the launcher */
- switch (sval) {
- /* Sling and ammo */
- case SV_SLING: {
- tmul = 2;
- break;
- }
-
- /* Short Bow and Arrow */
- case SV_SHORT_BOW: {
- tmul = 2;
- break;
- }
-
- /* Long Bow and Arrow */
- case SV_LONG_BOW: {
- tmul = 3;
- break;
- }
-
- /* Bow of irresponsiblity and Arrow */
- case SV_NAMAKE_BOW: {
- tmul = 3;
- break;
- }
-
- /* Light Crossbow and Bolt */
- case SV_LIGHT_XBOW: {
- tmul = 3;
- break;
- }
-
- /* Heavy Crossbow and Bolt */
- case SV_HEAVY_XBOW: {
- tmul = 4;
- break;
- }
- }
-
- return tmul;
-}
-
/*!
* @brief 射撃時クリティカルによるダメージ期待値修正計算(スナイパーの集中処理と武器経験値) / critical happens at i / 10000
* @param player_ptr プレイヤーへの参照ポインタ
class PlayerType;
bool test_hit_fire(PlayerType *player_ptr, int chance, MonsterEntity *m_ptr, int vis, char *o_name);
int critical_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam);
-int bow_tmul(OBJECT_SUBTYPE_VALUE sval);
int calc_crit_ratio_shot(PlayerType *player_ptr, int plus_ammo, int plus_bow);
int calc_expect_crit_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam);
int calc_expect_crit(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, bool dokubari, bool impact);
#include <set>
#include <unordered_map>
+namespace {
+constexpr auto ITEM_NOT_BOW = "This item is not a bow!";
+}
+
BaseitemKey::BaseitemKey(const ItemKindType type_value, const std::optional<int> &subtype_value)
: type_value(type_value)
, subtype_value(subtype_value)
short BaseitemKey::get_bow_energy() const
{
if ((this->type_value != ItemKindType::BOW) || !this->subtype_value.has_value()) {
- throw std::logic_error("This item is not a bow!");
+ throw std::logic_error(ITEM_NOT_BOW);
}
switch (this->subtype_value.value()) {
}
}
+int BaseitemKey::get_arrow_magnification() const
+{
+ if ((this->type_value != ItemKindType::BOW) || !this->subtype_value.has_value()) {
+ throw std::logic_error(ITEM_NOT_BOW);
+ }
+
+ switch (this->subtype_value.value()) {
+ case SV_SLING:
+ case SV_SHORT_BOW:
+ return 2;
+ case SV_LONG_BOW:
+ case SV_NAMAKE_BOW:
+ case SV_LIGHT_XBOW:
+ return 3;
+ case SV_HEAVY_XBOW:
+ return 4;
+ default:
+ return 0;
+ }
+}
+
bool BaseitemKey::is_mushrooms() const
{
if (!this->subtype_value.has_value()) {