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 19, 2024
2 parents b53dfde + b3a21f3 commit 3463502
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 252 deletions.
24 changes: 2 additions & 22 deletions src/grid/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,6 @@ std::pair<int, Pos2D> count_dt(PlayerType *player_ptr, GridCountKind gck, bool u
auto count = 0;
Pos2D pos(0, 0);
const auto &floor = *player_ptr->current_floor_ptr;
const auto &dungeon = floor.get_dungeon_definition();
for (auto d = 0; d < 9; d++) {
if ((d == 8) && !under) {
continue;
Expand All @@ -1061,27 +1060,8 @@ std::pair<int, Pos2D> count_dt(PlayerType *player_ptr, GridCountKind gck, bool u
continue;
}

switch (gck) {
case GridCountKind::OPEN:
if (!dungeon.is_open(grid.get_feat_mimic())) {
continue;
}

break;
case GridCountKind::CLOSED_DOOR:
if (!grid.get_terrain_mimic().is_closed_door()) {
continue;
}

break;
case GridCountKind::TRAP:
if (!grid.get_terrain_mimic().is_trap()) {
continue;
}

break;
default:
THROW_EXCEPTION(std::logic_error, format("Invalid GridCountKind is Specified! %d", enum2i(gck)));
if (!floor.check_terrain_state(pos_neighbor, gck)) {
continue;
}

++count;
Expand Down
54 changes: 27 additions & 27 deletions src/knowledge/knowledge-inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,41 +60,41 @@ static void print_flag(tr_type tr, const TrFlags &flags, FILE *fff)

/*!
* @brief 特殊なアイテムかどうかを調べる
* @param o_ptr アイテムへの参照ポインタ
* @param item アイテムへの参照
* @param tval アイテム主分類番号
* @return 特殊なアイテムならTRUE
*/
static bool determine_spcial_item_type(ItemEntity *o_ptr, ItemKindType tval)
static bool determine_spcial_item_type(const ItemEntity &item, ItemKindType tval)
{
const auto bi_key = BaseitemKey(tval, o_ptr->bi_key.sval());
const auto bi_key = BaseitemKey(tval, item.bi_key.sval());
auto is_special_item_type = bi_key == BaseitemKey(ItemKindType::AMULET, SV_AMULET_RESISTANCE);
is_special_item_type |= bi_key == BaseitemKey(ItemKindType::RING, SV_RING_LORDLY);
is_special_item_type |= bi_key == BaseitemKey(ItemKindType::SHIELD, SV_DRAGON_SHIELD);
is_special_item_type |= bi_key == BaseitemKey(ItemKindType::HELM, SV_DRAGON_HELM);
is_special_item_type |= bi_key == BaseitemKey(ItemKindType::GLOVES, SV_SET_OF_DRAGON_GLOVES);
is_special_item_type |= bi_key == BaseitemKey(ItemKindType::BOOTS, SV_PAIR_OF_DRAGON_GREAVE);
is_special_item_type |= o_ptr->is_fixed_or_random_artifact();
return (o_ptr->is_wearable() && o_ptr->is_ego()) || is_special_item_type;
is_special_item_type |= item.is_fixed_or_random_artifact();
return (item.is_wearable() && item.is_ego()) || is_special_item_type;
}

/*!
* @brief アイテムに耐性の表示をする必要があるかを判定する
* @param o_ptr アイテムへの参照ポインタ
* @param item アイテムへの参照
* @param tval アイテム主分類番号
* @return 必要があるならTRUE
*/
static bool check_item_knowledge(ItemEntity *o_ptr, ItemKindType tval)
static bool check_item_knowledge(const ItemEntity &item, ItemKindType tval)
{
if (!o_ptr->is_valid()) {
if (!item.is_valid()) {
return false;
}
if (o_ptr->bi_key.tval() != tval) {
if (item.bi_key.tval() != tval) {
return false;
}
if (!o_ptr->is_known()) {
if (!item.is_known()) {
return false;
}
if (!determine_spcial_item_type(o_ptr, tval)) {
if (!determine_spcial_item_type(item, tval)) {
return false;
}

Expand All @@ -103,13 +103,13 @@ static bool check_item_knowledge(ItemEntity *o_ptr, ItemKindType tval)

/*!
* @brief 鑑定済アイテムの耐性を表示する
* @param o_ptr アイテムへの参照ポインタ
* @param item アイテムへの参照
* @param fff 一時ファイルへの参照ポインタ
* @todo ここの関数から表示用の関数に移したい
*/
static void display_identified_resistances_flag(ItemEntity *o_ptr, FILE *fff)
static void display_identified_resistances_flag(const ItemEntity &item, FILE *fff)
{
auto flags = o_ptr->get_flags_known();
auto flags = item.get_flags_known();

print_im_or_res_flag(TR_IM_ACID, TR_RES_ACID, flags, fff);
print_im_or_res_flag(TR_IM_ELEC, TR_RES_ELEC, flags, fff);
Expand Down Expand Up @@ -145,28 +145,28 @@ static void display_identified_resistances_flag(ItemEntity *o_ptr, FILE *fff)
* @brief アイテム1つ当たりの耐性を表示する
* @param player_ptr プレイヤーへの参照ポインタ
* @param fff 一時ファイルへの参照ポインタ
* @param o_ptr アイテムへの参照ポインタ
* @param item アイテムへの参照
* @param where アイテムの場所 (手持ち、家等) を示す文字列への参照ポインタ
* @details 28文字ちょうどになるまで右側をスペースでパディングする
*/
static void do_cmd_knowledge_inventory_aux(PlayerType *player_ptr, FILE *fff, ItemEntity *o_ptr, char *where)
static void do_cmd_knowledge_inventory_aux(PlayerType *player_ptr, FILE *fff, const ItemEntity &item, char *where)
{
constexpr auto max_item_length = 26;
std::stringstream ss;
ss << describe_flavor(player_ptr, *o_ptr, OD_NAME_ONLY, max_item_length);
ss << describe_flavor(player_ptr, item, OD_NAME_ONLY, max_item_length);
const int item_length = ss.tellp();
constexpr auto max_display_length = 28;
for (auto i = item_length; i < max_display_length; i++) {
ss << ' ';
}

fprintf(fff, "%s %s", where, ss.str().data());
if (!o_ptr->is_fully_known()) {
if (!item.is_fully_known()) {
fputs(_("-------不明--------------- -------不明---------\n", "-------unknown------------ -------unknown------\n"), fff);
return;
}

display_identified_resistances_flag(o_ptr, fff);
display_identified_resistances_flag(item, fff);
}

/*!
Expand Down Expand Up @@ -214,12 +214,12 @@ static void show_wearing_equipment_resistances(PlayerType *player_ptr, ItemKindT
char where[32];
strcpy(where, _("", "E "));
for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
auto *o_ptr = &player_ptr->inventory_list[i];
if (!check_item_knowledge(o_ptr, tval)) {
const auto &item = player_ptr->inventory_list[i];
if (!check_item_knowledge(item, tval)) {
continue;
}

do_cmd_knowledge_inventory_aux(player_ptr, fff, o_ptr, where);
do_cmd_knowledge_inventory_aux(player_ptr, fff, item, where);
add_res_label(label_number, fff);
}
}
Expand All @@ -236,12 +236,12 @@ static void show_holding_equipment_resistances(PlayerType *player_ptr, ItemKindT
char where[32];
strcpy(where, _("", "I "));
for (int i = 0; i < INVEN_PACK; i++) {
auto *o_ptr = &player_ptr->inventory_list[i];
if (!check_item_knowledge(o_ptr, tval)) {
const auto &item = player_ptr->inventory_list[i];
if (!check_item_knowledge(item, tval)) {
continue;
}

do_cmd_knowledge_inventory_aux(player_ptr, fff, o_ptr, where);
do_cmd_knowledge_inventory_aux(player_ptr, fff, item, where);
add_res_label(label_number, fff);
}
}
Expand All @@ -261,11 +261,11 @@ static void show_home_equipment_resistances(PlayerType *player_ptr, ItemKindType
strcpy(where, _("", "H "));
for (int i = 0; i < store_ptr->stock_num; i++) {
const auto &item = store_ptr->stock[i];
if (!check_item_knowledge(item.get(), tval)) {
if (!check_item_knowledge(*item, tval)) {
continue;
}

do_cmd_knowledge_inventory_aux(player_ptr, fff, item.get(), where);
do_cmd_knowledge_inventory_aux(player_ptr, fff, *item, where);
add_res_label(label_number, fff);
}
}
Expand Down
16 changes: 2 additions & 14 deletions src/knowledge/knowledge-monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,8 @@ void do_cmd_knowledge_kill_count(PlayerType *player_ptr)
return;
}

auto total = 0;
for (const auto &[monrace_id, monrace] : monraces_info) {
if (monrace.kind_flags.has(MonsterKindType::UNIQUE)) {
if (monrace.max_num == 0) {
total++;
}
} else {
if (monrace.r_pkills > 0) {
total += monrace.r_pkills;
}
}
}

const auto &monraces = MonraceList::get_instance();
const auto total = monraces.calc_defeat_count();
if (total < 1) {
fprintf(fff, _("あなたはまだ敵を倒していない。\n\n", "You have defeated no enemies yet.\n\n"));
} else {
Expand All @@ -177,7 +166,6 @@ void do_cmd_knowledge_kill_count(PlayerType *player_ptr)
#endif
}

const auto &monraces = MonraceList::get_instance();
std::vector<MonraceId> monrace_ids = monraces.get_valid_monrace_ids();
std::stable_sort(monrace_ids.begin(), monrace_ids.end(), [&monraces](auto x, auto y) { return monraces.order(x, y); });
for (const auto monrace_id : monrace_ids) {
Expand Down
97 changes: 34 additions & 63 deletions src/knowledge/knowledge-uniques.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,63 @@

#include "knowledge/knowledge-uniques.h"
#include "core/show-file.h"
#include "game-option/cheat-options.h"
#include "io-dump/dump-util.h"
#include "system/monster-race-info.h"
#include "system/player-type-definition.h"
#include "term/z-form.h"
#include "util/angband-files.h"
#include "util/string-processor.h"

struct unique_list_type {
unique_list_type(bool is_alive);
class UniqueList {
public:
UniqueList(bool is_alive);
int num_uniques[10]{};
bool is_alive;
std::vector<MonraceId> monrace_ids{};
int num_uniques_surface = 0;
int num_uniques_over100 = 0;
int num_uniques_total = 0;
int max_lev = -1;

void sweep();
};

unique_list_type::unique_list_type(bool is_alive)
UniqueList::UniqueList(bool is_alive)
: is_alive(is_alive)
{
}

/*!
* @brief モンスターリストを走査し、生きているか死んでいるユニークだけを抽出する
* @param r_ptr モンスター種別への参照ポインタ
* @param is_alive 生きているユニークのリストならばTRUE、撃破したユニークのリストならばFALSE
* @return is_aliveの条件に見合うユニークがいたらTRUE、それ以外はFALSE
* @details 闘技場のモンスターとは再戦できないので、生きているなら表示から外す
*/
static bool sweep_uniques(MonraceDefinition *r_ptr, bool is_alive)
void UniqueList::sweep()
{
if (r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE)) {

return false;
}

if (!cheat_know && !r_ptr->r_sights) {
return false;
}
auto &monraces = MonraceList::get_instance();
for (auto &[monrace_id, monrace] : monraces) {
if (!monrace.is_valid() || !monrace.should_display(this->is_alive)) {
continue;
}

const auto is_except_arena = is_alive ? (r_ptr->rarity > 100) && (r_ptr->misc_flags.has_not(MonsterMiscType::QUESTOR)) : false;
if (is_except_arena) {
return false;
}
if (!monrace.level) {
this->num_uniques_surface++;
this->monrace_ids.push_back(monrace_id);
continue;
}

if (is_alive) {
if (r_ptr->max_num == 0) {
return false;
const auto lev = (monrace.level - 1) / 10;
if (lev >= 10) {
this->num_uniques_over100++;
this->monrace_ids.push_back(monrace_id);
continue;
}
} else {
if (r_ptr->max_num > 0) {
return false;

this->num_uniques[lev]++;
if (this->max_lev < lev) {
this->max_lev = lev;
}
}

return true;
this->monrace_ids.push_back(monrace_id);
}
}

static void display_uniques(unique_list_type *unique_list_ptr, FILE *fff)
static void display_uniques(UniqueList *unique_list_ptr, FILE *fff)
{
if (unique_list_ptr->num_uniques_surface) {
concptr surface_desc = unique_list_ptr->is_alive ? _(" 地上 生存: %3d体\n", " Surface alive: %3d\n")
Expand Down Expand Up @@ -124,44 +120,19 @@ static void display_uniques(unique_list_type *unique_list_ptr, FILE *fff)
*/
void do_cmd_knowledge_uniques(PlayerType *player_ptr, bool is_alive)
{
unique_list_type tmp_list(is_alive);
unique_list_type *unique_list_ptr = &tmp_list;
UniqueList unique_list(is_alive);
FILE *fff = nullptr;
GAME_TEXT file_name[FILE_NAME_SIZE];
if (!open_temporary_file(&fff, file_name)) {
return;
}

for (auto &[monrace_id, monrace] : monraces_info) {
if (!monrace.is_valid()) {
continue;
}
if (!sweep_uniques(&monrace, unique_list_ptr->is_alive)) {
continue;
}

if (monrace.level) {
int lev = (monrace.level - 1) / 10;
if (lev < 10) {
unique_list_ptr->num_uniques[lev]++;
if (unique_list_ptr->max_lev < lev) {
unique_list_ptr->max_lev = lev;
}
} else {
unique_list_ptr->num_uniques_over100++;
}
} else {
unique_list_ptr->num_uniques_surface++;
}

unique_list_ptr->monrace_ids.push_back(monrace_id);
}

unique_list.sweep();
const auto &monraces = MonraceList::get_instance();
std::stable_sort(unique_list_ptr->monrace_ids.begin(), unique_list_ptr->monrace_ids.end(), [&monraces](auto x, auto y) { return monraces.order(x, y); });
display_uniques(unique_list_ptr, fff);
std::stable_sort(unique_list.monrace_ids.begin(), unique_list.monrace_ids.end(), [&monraces](auto x, auto y) { return monraces.order(x, y); });
display_uniques(&unique_list, fff);
angband_fclose(fff);
concptr title_desc = unique_list_ptr->is_alive ? _("まだ生きているユニーク・モンスター", "Alive Uniques") : _("もう撃破したユニーク・モンスター", "Dead Uniques");
concptr title_desc = unique_list.is_alive ? _("まだ生きているユニーク・モンスター", "Alive Uniques") : _("もう撃破したユニーク・モンスター", "Dead Uniques");
FileDisplayer(player_ptr->name).display(true, file_name, 0, 0, title_desc);
fd_kill(file_name);
}
Loading

0 comments on commit 3463502

Please sign in to comment.