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 Jan 23, 2025
2 parents 3f3d3ea + 9cb7cff commit 8c794ad
Show file tree
Hide file tree
Showing 50 changed files with 743 additions and 726 deletions.
2 changes: 1 addition & 1 deletion src/effect/effect-feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool affect_feature(PlayerType *player_ptr, MONSTER_IDX src_idx, POSITION r, POS
if (player_ptr->is_located_at(pos)) {
break;
}
cave_set_feat(player_ptr, y, x, feat_door[DOOR_DOOR].closed);
cave_set_feat(player_ptr, pos, feat_door.at(DoorKind::DOOR).closed);
if (grid.is_mark()) {
obvious = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/effect/effect-monster-psi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ ProcessResult effect_monster_psi(PlayerType *player_ptr, EffectMonster *em_ptr)
if (em_ptr->seen) {
em_ptr->obvious = true;
}
if (!(los(player_ptr, em_ptr->m_ptr->fy, em_ptr->m_ptr->fx, player_ptr->y, player_ptr->x))) {
if (!los(*player_ptr->current_floor_ptr, em_ptr->m_ptr->get_position(), player_ptr->get_position())) {
if (em_ptr->seen_msg) {
msg_format(_("%sはあなたが見えないので影響されない!", "%s^ can't see you, and isn't affected!"), em_ptr->m_name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/effect/effect-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO
switch (typ) {
case AttributeType::LITE:
case AttributeType::LITE_WEAK:
if (!los(player_ptr, pos_breath.y, pos_breath.x, pos.y, pos.x)) {
if (!los(floor, pos_breath, pos)) {
continue;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/floor/floor-changer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void set_player_grid(FloorType &floor, const Pos2D &p_pos)
}

auto &grid = floor.get_grid(p_pos);
if (feat_uses_special(grid.feat)) {
if (grid.has_special_terrain()) {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/floor/floor-leaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "floor/wild.h"
#include "game-option/birth-options.h"
#include "game-option/play-record-options.h"
#include "grid/grid.h"
#include "inventory/inventory-slot-types.h"
#include "io/write-diary.h"
#include "mind/mind-ninja.h"
Expand Down Expand Up @@ -68,9 +67,10 @@ static bool check_pet_preservation_conditions(PlayerType *player_ptr, MonsterEnt
}

const auto should_preserve = m_ptr->is_named();
auto sight_from_player = player_ptr->current_floor_ptr->has_los(m_pos);
const auto &floor = *player_ptr->current_floor_ptr;
auto sight_from_player = floor.has_los(m_pos);
sight_from_player &= projectable(player_ptr, p_pos, m_pos);
auto sight_from_monster = los(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x);
auto sight_from_monster = los(floor, m_pos, p_pos);
sight_from_monster &= projectable(player_ptr, m_pos, p_pos);
if (should_preserve && (sight_from_player || sight_from_monster)) {
return dis > 3;
Expand Down Expand Up @@ -199,7 +199,7 @@ static void locate_connected_stairs(PlayerType *player_ptr, FloorType &floor, sa
if (num == 0) {
FloorChangeModesStore::get_instace()->set({ FloorChangeMode::RANDOM_PLACE, FloorChangeMode::NO_RETURN });
auto &grid = floor.get_grid(player_ptr->get_position());
if (!feat_uses_special(grid.feat)) {
if (!grid.has_special_terrain()) {
grid.special = 0;
}

Expand Down Expand Up @@ -394,7 +394,7 @@ static void refresh_new_floor_id(PlayerType *player_ptr, Grid *g_ptr)
}

new_floor_id = get_unused_floor_id(player_ptr);
if ((g_ptr != nullptr) && !feat_uses_special(g_ptr->feat)) {
if ((g_ptr != nullptr) && !g_ptr->has_special_terrain()) {
g_ptr->special = new_floor_id;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/floor/floor-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Pos2D scatter(PlayerType *player_ptr, const Pos2D &pos, int d, uint32_t mode)
continue;
}
if (mode & PROJECT_LOS) {
if (los(player_ptr, pos.y, pos.x, pos_neighbor.y, pos_neighbor.x)) {
if (los(floor, pos, pos_neighbor)) {
return pos_neighbor;
}

Expand Down
93 changes: 42 additions & 51 deletions src/floor/line-of-sight.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
#include "floor/line-of-sight.h"
#include "floor/cave.h"
#include "system/floor/floor-info.h"
#include "system/player-type-definition.h"

/*!
* @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
* @param player_ptr プレイヤーへの参照ポインタ
* @param y1 始点のy座標
* @param x1 始点のx座標
* @param y2 終点のy座標
* @param x2 終点のx座標
* @param floor フロアへの参照
* @param pos_from 始点の座標
* @param pos_to 終点の座標
* @return LOSが通っているならTRUEを返す。
* @details
* A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
* 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
*\n
* Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
* Returns TRUE if a line of sight can be traced from (pos_from.x,pos_from.y) to (pos_to.x,pos_to.y).\n
*\n
* The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
* the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
* passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
* The LOS begins at the center of the tile (pos_from.x,pos_from.y) and ends at the center of\n
* the tile (pos_to.x,pos_to.y). If los() is to return TRUE, all of the tiles this line\n
* passes through must be floor tiles, except for (pos_from.x,pos_from.y) and (pos_to.x,pos_to.y).\n
*\n
* We assume that the "mathematical corner" of a non-floor tile does not\n
* block line of sight.\n
Expand All @@ -46,33 +43,31 @@
*\n
* Use the "update_view()" function to determine player line-of-sight.\n
*/
bool los(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
bool los(const FloorType &floor, const Pos2D &pos_from, const Pos2D &pos_to)
{
POSITION dy = y2 - y1;
POSITION dx = x2 - x1;
POSITION ay = std::abs(dy);
POSITION ax = std::abs(dx);
const auto dy = pos_to.y - pos_from.y;
const auto dx = pos_to.x - pos_from.x;
const auto ay = std::abs(dy);
const auto ax = std::abs(dx);
if ((ax < 2) && (ay < 2)) {
return true;
}

/* Directly South/North */
auto *floor_ptr = player_ptr->current_floor_ptr;
POSITION tx, ty;
if (!dx) {
/* South -- check for walls */
if (dy > 0) {
for (ty = y1 + 1; ty < y2; ty++) {
if (!cave_los_bold(floor_ptr, ty, x1)) {
for (auto ty = pos_from.y + 1; ty < pos_to.y; ty++) {
if (!cave_los_bold(&floor, ty, pos_from.x)) {
return false;
}
}
}

/* North -- check for walls */
else {
for (ty = y1 - 1; ty > y2; ty--) {
if (!cave_los_bold(floor_ptr, ty, x1)) {
for (auto ty = pos_from.y - 1; ty > pos_to.y; ty--) {
if (!cave_los_bold(&floor, ty, pos_from.x)) {
return false;
}
}
Expand All @@ -86,17 +81,17 @@ bool los(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION
if (!dy) {
/* East -- check for walls */
if (dx > 0) {
for (tx = x1 + 1; tx < x2; tx++) {
if (!cave_los_bold(floor_ptr, y1, tx)) {
for (auto tx = pos_from.x + 1; tx < pos_to.x; tx++) {
if (!cave_los_bold(&floor, pos_from.y, tx)) {
return false;
}
}
}

/* West -- check for walls */
else {
for (tx = x1 - 1; tx > x2; tx--) {
if (!cave_los_bold(floor_ptr, y1, tx)) {
for (auto tx = pos_from.x - 1; tx > pos_to.x; tx--) {
if (!cave_los_bold(&floor, pos_from.y, tx)) {
return false;
}
}
Expand All @@ -105,42 +100,39 @@ bool los(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION
return true;
}

POSITION sx = (dx < 0) ? -1 : 1;
POSITION sy = (dy < 0) ? -1 : 1;
const auto sx = (dx < 0) ? -1 : 1;
const auto sy = (dy < 0) ? -1 : 1;

if (ax == 1) {
if (ay == 2) {
if (cave_los_bold(floor_ptr, y1 + sy, x1)) {
if (cave_los_bold(&floor, pos_from.y + sy, pos_from.x)) {
return true;
}
}
} else if (ay == 1) {
if (ax == 2) {
if (cave_los_bold(floor_ptr, y1, x1 + sx)) {
if (cave_los_bold(&floor, pos_from.y, pos_from.x + sx)) {
return true;
}
}
}

POSITION f2 = (ax * ay);
POSITION f1 = f2 << 1;
POSITION qy;
POSITION m;
const auto f2 = (ax * ay);
const auto f1 = f2 << 1;
if (ax >= ay) {
qy = ay * ay;
m = qy << 1;
tx = x1 + sx;
auto qy = ay * ay;
const auto m = qy << 1;
auto ty = pos_from.y;
auto tx = pos_from.x + sx;
if (qy == f2) {
ty = y1 + sy;
ty += sy;
qy -= f1;
} else {
ty = y1;
}

/* Note (below) the case (qy == f2), where */
/* the LOS exactly meets the corner of a tile. */
while (x2 - tx) {
if (!cave_los_bold(floor_ptr, ty, tx)) {
while (pos_to.x - tx) {
if (!cave_los_bold(&floor, ty, tx)) {
return false;
}

Expand All @@ -153,7 +145,7 @@ bool los(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION

if (qy > f2) {
ty += sy;
if (!cave_los_bold(floor_ptr, ty, tx)) {
if (!cave_los_bold(&floor, ty, tx)) {
return false;
}
qy -= f1;
Expand All @@ -170,20 +162,19 @@ bool los(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION
}

/* Travel vertically */
POSITION qx = ax * ax;
m = qx << 1;
ty = y1 + sy;
auto qx = ax * ax;
const auto m = qx << 1;
auto ty = pos_from.y + sy;
auto tx = pos_from.x;
if (qx == f2) {
tx = x1 + sx;
tx += sx;
qx -= f1;
} else {
tx = x1;
}

/* Note (below) the case (qx == f2), where */
/* the LOS exactly meets the corner of a tile. */
while (y2 - ty) {
if (!cave_los_bold(floor_ptr, ty, tx)) {
while (pos_to.y - ty) {
if (!cave_los_bold(&floor, ty, tx)) {
return false;
}

Expand All @@ -196,7 +187,7 @@ bool los(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION

if (qx > f2) {
tx += sx;
if (!cave_los_bold(floor_ptr, ty, tx)) {
if (!cave_los_bold(&floor, ty, tx)) {
return false;
}
qx -= f1;
Expand Down
6 changes: 3 additions & 3 deletions src/floor/line-of-sight.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "system/angband.h"
#include "util/point-2d.h"

class PlayerType;
bool los(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2);
class FloorType;
bool los(const FloorType &floor, const Pos2D &pos_from, const Pos2D &pos_to);
3 changes: 2 additions & 1 deletion src/floor/pattern-walk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "status/experience.h"
#include "system/dungeon/dungeon-definition.h"
#include "system/enums/dungeon/dungeon-id.h"
#include "system/enums/terrain/terrain-tag.h"
#include "system/floor/floor-info.h"
#include "system/grid-type-definition.h"
#include "system/player-type-definition.h"
Expand Down Expand Up @@ -124,7 +125,7 @@ bool pattern_effect(PlayerType *player_ptr)
(void)restore_level(player_ptr);
(void)cure_critical_wounds(player_ptr, 1000);

cave_set_feat(player_ptr, player_ptr->y, player_ptr->x, feat_pattern_old);
cave_set_feat(player_ptr, player_ptr->get_position(), TerrainTag::PATTERN_OLD);
msg_print(_("「パターン」のこの部分は他の部分より強力でないようだ。", "This section of the Pattern looks less powerful."));

/*
Expand Down
Loading

0 comments on commit 8c794ad

Please sign in to comment.