Skip to content

Commit

Permalink
Merge branch 'develop' into macos-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
backwardsEric committed Nov 20, 2024
2 parents 3463502 + 1931c5c commit 65ebfac
Show file tree
Hide file tree
Showing 59 changed files with 727 additions and 713 deletions.
4 changes: 2 additions & 2 deletions src/blue-magic/blue-magic-caster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static bool cast_blue_dispel(PlayerType *player_ptr)
const Pos2D pos(target_row, target_col);
const auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
const auto m_idx = grid.m_idx;
if ((m_idx == 0) || !grid.has_los() || !projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) {
if ((m_idx == 0) || !grid.has_los() || !projectable(player_ptr, player_ptr->get_position(), pos)) {
return true;
}

Expand Down Expand Up @@ -98,7 +98,7 @@ static std::optional<std::string> exe_blue_teleport_back(PlayerType *player_ptr)
const auto &floor = *player_ptr->current_floor_ptr;
const Pos2D pos(target_row, target_col);
const auto &grid = floor.get_grid(pos);
if (!grid.has_monster() || !grid.has_los() || !projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) {
if (!grid.has_monster() || !grid.has_los() || !projectable(player_ptr, player_ptr->get_position(), pos)) {
return std::nullopt;
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd-action/cmd-mane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static bool use_mane(PlayerType *player_ptr, MonsterAbilityType spell)
const auto m_idx = grid.m_idx;
auto should_dispel = m_idx == 0;
should_dispel &= grid.has_los();
should_dispel &= projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col);
should_dispel &= projectable(player_ptr, player_ptr->get_position(), pos);
if (!should_dispel) {
break;
}
Expand Down Expand Up @@ -959,7 +959,7 @@ static bool use_mane(PlayerType *player_ptr, MonsterAbilityType spell)
const auto &grid_target = floor.get_grid(pos);
auto should_teleport = grid_target.has_monster();
should_teleport &= grid_target.has_los();
should_teleport &= projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col);
should_teleport &= projectable(player_ptr, player_ptr->get_position(), pos);
if (!should_teleport) {
break;
}
Expand Down
22 changes: 10 additions & 12 deletions src/effect/effect-player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,25 @@ static bool process_bolt_reflection(PlayerType *player_ptr, EffectPlayerType *ep
}

msg_print(mes);
POSITION t_y;
POSITION t_x;
Pos2D pos(0, 0);
if (is_monster(ep_ptr->src_idx)) {
auto *floor_ptr = player_ptr->current_floor_ptr;
auto *m_ptr = &floor_ptr->m_list[ep_ptr->src_idx];
const auto &floor = *player_ptr->current_floor_ptr;
const auto &monster = floor.m_list[ep_ptr->src_idx];
do {
t_y = m_ptr->fy - 1 + randint1(3);
t_x = m_ptr->fx - 1 + randint1(3);
const Pos2DVec vec(randint1(3) - 1, randint1(3) - 1);
pos = monster.get_position() + vec;
max_attempts--;
} while (max_attempts && in_bounds2u(floor_ptr, t_y, t_x) && !projectable(player_ptr, player_ptr->y, player_ptr->x, t_y, t_x));
} while (max_attempts && in_bounds2u(&floor, pos.y, pos.x) && !projectable(player_ptr, player_ptr->get_position(), pos));

if (max_attempts < 1) {
t_y = m_ptr->fy;
t_x = m_ptr->fx;
pos = monster.get_position();
}
} else {
t_y = player_ptr->y - 1 + randint1(3);
t_x = player_ptr->x - 1 + randint1(3);
const Pos2DVec vec(randint1(3) - 1, randint1(3) - 1);
pos = player_ptr->get_position() + vec;
}

(*project)(player_ptr, 0, 0, t_y, t_x, ep_ptr->dam, ep_ptr->attribute, (PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE), std::nullopt);
(*project)(player_ptr, 0, 0, pos.y, pos.x, ep_ptr->dam, ep_ptr->attribute, (PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE), std::nullopt);
disturb(player_ptr, true, true);
return true;
}
Expand Down
20 changes: 11 additions & 9 deletions src/effect/effect-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
for (auto dist = 0; dist <= rad; dist++) {
for (auto y = by - dist; y <= by + dist; y++) {
for (auto x = bx - dist; x <= bx + dist; x++) {
const Pos2D pos(y, x);
const Pos2D pos_breath(by, bx);
if (!in_bounds2(player_ptr->current_floor_ptr, y, x)) {
continue;
}
Expand All @@ -247,7 +249,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
}
break;
default:
if (!projectable(player_ptr, by, bx, y, x)) {
if (!projectable(player_ptr, pos_breath, pos)) {
continue;
}
break;
Expand Down Expand Up @@ -303,7 +305,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO

if (flag & PROJECT_KILL) {
see_s_msg = is_monster(src_idx) ? is_seen(player_ptr, &player_ptr->current_floor_ptr->m_list[src_idx])
: (is_player(src_idx) ? true : (player_can_see_bold(player_ptr, y1, x1) && projectable(player_ptr, player_ptr->y, player_ptr->x, y1, x1)));
: (is_player(src_idx) ? true : (player_can_see_bold(player_ptr, y1, x1) && projectable(player_ptr, player_ptr->get_position(), { y1, x1 })));
}

if (flag & (PROJECT_GRID)) {
Expand Down Expand Up @@ -370,17 +372,17 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
MonraceDefinition *ref_ptr = &m_ptr->get_monrace();
if ((flag & PROJECT_REFLECTABLE) && grid.m_idx && ref_ptr->misc_flags.has(MonsterMiscType::REFLECTING) && (!m_ptr->is_riding() || !(flag & PROJECT_PLAYER)) && (!src_idx || path_n > 1) && !one_in_(10)) {

POSITION t_y, t_x;
Pos2D pos_target(0, 0);
int max_attempts = 10;
do {
t_y = y1 - 1 + randint1(3);
t_x = x1 - 1 + randint1(3);
pos_target.y = y1 - 1 + randint1(3);
pos_target.x = x1 - 1 + randint1(3);
max_attempts--;
} while (max_attempts && in_bounds2u(player_ptr->current_floor_ptr, t_y, t_x) && !projectable(player_ptr, pos.y, pos.x, t_y, t_x));
} while (max_attempts && in_bounds2u(player_ptr->current_floor_ptr, pos_target.y, pos_target.x) && !projectable(player_ptr, pos, pos_target));

if (max_attempts < 1) {
t_y = y1;
t_x = x1;
pos_target.y = y1;
pos_target.x = x1;
}

if (is_seen(player_ptr, m_ptr)) {
Expand All @@ -406,7 +408,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
flag |= PROJECT_PLAYER;
}

project(player_ptr, grid.m_idx, 0, t_y, t_x, dam, typ, flag);
project(player_ptr, grid.m_idx, 0, pos_target.y, pos_target.x, dam, typ, flag);
continue;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/floor/floor-leaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ static bool check_pet_preservation_conditions(PlayerType *player_ptr, MonsterEnt
return false;
}

auto dis = distance(player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx);
const auto p_pos = player_ptr->get_position();
const auto m_pos = m_ptr->get_position();
const auto dis = distance(player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx);
if (m_ptr->is_confused() || m_ptr->is_stunned() || m_ptr->is_asleep() || m_ptr->has_parent()) {
return true;
}

const auto should_preserve = m_ptr->is_named();
auto sight_from_player = player_ptr->current_floor_ptr->has_los({ m_ptr->fy, m_ptr->fx });
sight_from_player &= projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx);
auto sight_from_player = player_ptr->current_floor_ptr->has_los(m_pos);
sight_from_player &= projectable(player_ptr, player_ptr->get_position(), m_ptr->get_position());
auto sight_from_monster = los(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x);
sight_from_monster &= projectable(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x);
sight_from_monster &= projectable(player_ptr, m_pos, p_pos);
if (should_preserve && (sight_from_player || sight_from_monster)) {
return dis > 3;
}
Expand Down
3 changes: 2 additions & 1 deletion src/floor/floor-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@ OBJECT_IDX drop_near(PlayerType *player_ptr, ItemEntity *j_ptr, PERCENTAGE chanc

ty = y + dy;
tx = x + dx;
const Pos2D pos_target(ty, tx);
if (!in_bounds(floor_ptr, ty, tx)) {
continue;
}
if (!projectable(player_ptr, y, x, ty, tx)) {
if (!projectable(player_ptr, { y, x }, pos_target)) {
continue;
}

Expand Down
9 changes: 5 additions & 4 deletions src/floor/floor-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ void wipe_o_list(FloorType *floor_ptr)
*/
void scatter(PlayerType *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
{
auto *floor_ptr = player_ptr->current_floor_ptr;
const Pos2D pos(y, x);
const auto &floor = *player_ptr->current_floor_ptr;
POSITION nx, ny;
while (true) {
ny = rand_spread(y, d);
nx = rand_spread(x, d);

if (!in_bounds(floor_ptr, ny, nx)) {
const Pos2D pos_neighbor(ny, nx);
if (!in_bounds(&floor, ny, nx)) {
continue;
}
if ((d > 1) && (distance(y, x, ny, nx) > d)) {
Expand All @@ -175,7 +176,7 @@ void scatter(PlayerType *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POS
continue;
}

if (projectable(player_ptr, y, x, ny, nx)) {
if (projectable(player_ptr, { y, x }, pos_neighbor)) {
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/floor/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ Pos2D mmove2(const Pos2D &pos_orig, const Pos2D &pos1, const Pos2D &pos2)
*/
bool is_seen(PlayerType *player_ptr, MonsterEntity *m_ptr)
{
bool is_inside_view = !ignore_unview;
auto is_inside_view = !ignore_unview;
is_inside_view |= AngbandSystem::get_instance().is_phase_out();
is_inside_view |= player_can_see_bold(player_ptr, m_ptr->fy, m_ptr->fx) && projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx);
const auto m_pos = m_ptr->get_position();
is_inside_view |= player_can_see_bold(player_ptr, m_ptr->fy, m_ptr->fx) && projectable(player_ptr, player_ptr->get_position(), m_pos);
return m_ptr->ml && is_inside_view;
}
12 changes: 5 additions & 7 deletions src/grid/trap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,23 +574,21 @@ void hit_trap(PlayerType *player_ptr, bool break_trap)
for (lev = player_ptr->current_floor_ptr->dun_level; lev >= 20; lev -= 1 + lev / 16) {
const auto num = levs[std::min(lev / 10, 9)];
for (auto i = 0; i < num; i++) {
POSITION x1 = rand_spread(p_pos.x, 7);
POSITION y1 = rand_spread(p_pos.y, 5);

if (!in_bounds(player_ptr->current_floor_ptr, y1, x1)) {
const Pos2D pos(rand_spread(p_pos.y, 5), rand_spread(p_pos.x, 7));
if (!in_bounds(player_ptr->current_floor_ptr, pos.y, pos.x)) {
continue;
}

/* Require line of projection */
if (!projectable(player_ptr, player_ptr->y, player_ptr->x, y1, x1)) {
if (!projectable(player_ptr, p_pos, pos)) {
continue;
}

if (auto m_idx = summon_specific(player_ptr, y1, x1, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET))) {
if (auto m_idx = summon_specific(player_ptr, pos.y, pos.x, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET))) {
evil_idx = *m_idx;
}

if (auto m_idx = summon_specific(player_ptr, y1, x1, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET))) {
if (auto m_idx = summon_specific(player_ptr, pos.y, pos.x, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET))) {
good_idx = *m_idx;
}

Expand Down
81 changes: 7 additions & 74 deletions src/lore/lore-calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,72 +45,6 @@ std::string dice_to_string(int base_damage, int dice_num, int dice_side, int dic
return ss.str();
}

/*!
* @brief モンスターの詳細情報(HP,AC,スキルダメージの量)を得ることができるかを返す
* @param r_idx モンスターの種族ID
* @return モンスターの詳細情報を得る条件が満たされているならtrue、そうでないならfalse
* @details
* The higher the level, the fewer kills needed.
*/
bool know_details(MonraceId r_idx)
{
const auto &monrace = monraces_info[r_idx];
const auto level = monrace.level;
const auto kills = monrace.r_tkills;

if (monrace.r_cast_spell == MAX_UCHAR) {
return true;
}
if (kills > 304 / (4 + level)) {
return true;
}
if (monrace.kind_flags.has_not(MonsterKindType::UNIQUE)) {
return false;
}
if (kills > 304 / (38 + (5 * level) / 4)) {
return true;
}
return false;
}

/*!
* @brief モンスターの打撃威力を知ることができるかどうかを返す
* Determine if the "damage" of the given attack is known
* @param r_idx モンスターの種族ID
* @param i 確認したい攻撃手番
* @return 敵のダメージダイスを知る条件が満たされているならtrue、そうでないならfalse
* @details
* <pre>
* the higher the level of the monster, the fewer the attacks you need,
* the more damage an attack does, the more attacks you need
* </pre>
*/
bool know_blow_damage(MonraceId r_idx, int i)
{
const auto &monrace = monraces_info[r_idx];
auto level = monrace.level;
auto a = monrace.r_blows[i];
auto d = monrace.blows[i].damage_dice.maxroll();

if (d >= ((4 + level) * MAX_UCHAR) / 80) {
d = ((4 + level) * MAX_UCHAR - 1) / 80;
}

if ((4 + level) * a > 80 * d) {
return true;
}

if (monrace.kind_flags.has_not(MonsterKindType::UNIQUE)) {
return false;
}

if ((4 + level) * (2 * a) > 80 * d) {
return true;
}

return false;
}

/*!
* @brief lore_ptrにダメージを与えるスキルの情報を追加する
* @param lore_ptr 知識情報
Expand All @@ -120,19 +54,18 @@ bool know_blow_damage(MonraceId r_idx, int i)
*/
void add_lore_of_damage_skill(PlayerType *player_ptr, lore_type *lore_ptr, MonsterAbilityType ms_type, concptr msg, byte color)
{
MonraceId r_idx = lore_ptr->r_idx;

if (!know_details(r_idx) && !lore_ptr->know_everything) {
if (!lore_ptr->is_details_known() && !lore_ptr->know_everything) {
// ダメージ量の情報なし
lore_ptr->lore_msgs.emplace_back(format(msg, ""), color);
return;
}

int base_damage = monspell_race_damage(player_ptr, ms_type, r_idx, BASE_DAM);
int dice_num = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_NUM);
int dice_side = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_SIDE);
int dice_mult = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_MULT);
int dice_div = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_DIV);
const auto monrace_id = lore_ptr->r_idx;
const auto base_damage = monspell_race_damage(player_ptr, ms_type, monrace_id, BASE_DAM);
const auto dice_num = monspell_race_damage(player_ptr, ms_type, monrace_id, DICE_NUM);
const auto dice_side = monspell_race_damage(player_ptr, ms_type, monrace_id, DICE_SIDE);
const auto dice_mult = monspell_race_damage(player_ptr, ms_type, monrace_id, DICE_MULT);
const auto dice_div = monspell_race_damage(player_ptr, ms_type, monrace_id, DICE_DIV);
std::stringstream dam_info;
dam_info << '(' << dice_to_string(base_damage, dice_num, dice_side, dice_mult, dice_div) << ')';
lore_ptr->lore_msgs.emplace_back(format(msg, dam_info.str().data()), color);
Expand Down
2 changes: 0 additions & 2 deletions src/lore/lore-calculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ enum class MonraceId : short;
struct lore_type;
class PlayerType;
std::string dice_to_string(int base_damage, int dice_num, int dice_side, int dice_mult, int dice_div);
bool know_details(MonraceId r_idx);
bool know_blow_damage(MonraceId r_idx, int i);
void add_lore_of_damage_skill(PlayerType *player_ptr, lore_type *lore_ptr, MonsterAbilityType ms_type, concptr msg, byte color);
void set_flags_for_full_knowledge(lore_type *lore_ptr);
10 changes: 10 additions & 0 deletions src/lore/lore-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ bool lore_type::has_reinforce() const
return this->r_ptr->has_reinforce();
}

bool lore_type::is_details_known() const
{
return MonraceList::get_instance().get_monrace(this->r_idx).is_details_known();
}

bool lore_type::is_blow_damage_known(int num_blow) const
{
return MonraceList::get_instance().get_monrace(this->r_idx).is_blow_damage_known(num_blow);
}

std::vector<lore_msg> lore_type::build_speed_description() const
{
std::vector<lore_msg> texts;
Expand Down
2 changes: 2 additions & 0 deletions src/lore/lore-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ struct lore_type {
EnumClassFlagGroup<MonsterMiscType> misc_flags;

bool has_reinforce() const;
bool is_details_known() const;
bool is_blow_damage_known(int num_blow) const;

std::optional<std::vector<lore_msg>> build_kill_unique_description() const;
std::string build_revenge_description(bool has_defeated) const;
Expand Down
Loading

0 comments on commit 65ebfac

Please sign in to comment.