Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

変愚「obj_desc_list を構成していた生配列を全てvector とstring に変えた」のマージ #4604

Merged
merged 10 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions src/io-dump/random-art-info-dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "system/item-entity.h"
#include "system/player-type-definition.h"
#include "util/angband-files.h"
#include "util/finalizer.h"
#include "view/display-messages.h"
#include "wizard/artifact-analyzer.h"
#include "wizard/fixed-artifacts-spoiler.h"
Expand All @@ -23,29 +24,31 @@
*/
static void spoiler_print_randart(ItemEntity *o_ptr, obj_desc_list *art_ptr)
{
const auto finalizer = util::make_finalizer([art_ptr]() {
fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc.data());
});
const auto *pval_ptr = &art_ptr->pval_info;
fprintf(spoiler_file, "%s\n", art_ptr->description);
fprintf(spoiler_file, "%s\n", art_ptr->description.data());
if (!o_ptr->is_fully_known()) {
fprintf(spoiler_file, _("%s不明\n", "%sUnknown\n"), spoiler_indent);
} else {
if (!pval_ptr->pval_desc.empty()) {
std::stringstream ss;
ss << pval_ptr->pval_desc << _("の修正:", " to");
spoiler_outlist(ss.str(), pval_ptr->pval_affects, item_separator);
}
return;
}

spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator);
spoiler_outlist(_("武器属性:", ""), art_ptr->brands, list_separator);
spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, item_separator);
spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, item_separator);
spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustains, item_separator);
spoiler_outlist("", art_ptr->misc_magic, list_separator);
if (art_ptr->activation) {
fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent, art_ptr->activation);
}
if (!pval_ptr->pval_desc.empty()) {
std::stringstream ss;
ss << pval_ptr->pval_desc << _("の修正:", " to");
spoiler_outlist(ss.str(), pval_ptr->pval_affects, item_separator);
}

fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc);
spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator);
spoiler_outlist(_("武器属性:", ""), art_ptr->brands, list_separator);
spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, item_separator);
spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, item_separator);
spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustenances, item_separator);
spoiler_outlist("", art_ptr->misc_magic, list_separator);
if (!art_ptr->activation.empty()) {
fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent, art_ptr->activation.data());
}
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion src/object/object-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static concptr item_activation_aux(ItemEntity *o_ptr)
* @param o_ptr 名称を取得する元のオブジェクト構造体参照ポインタ
* @return concptr 発動名称を返す文字列ポインタ
*/
concptr activation_explanation(ItemEntity *o_ptr)
std::string activation_explanation(ItemEntity *o_ptr)
{
auto flags = object_flags(o_ptr);
if (!flags.has(TR_ACTIVATE) && !flags.has(TR_INVEN_ACTIVATE)) {
Expand Down
3 changes: 2 additions & 1 deletion src/object/object-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

#include "object/tval-types.h"
#include "system/angband.h"
#include <string>

#define OBJ_GOLD_LIST 480 /* First "gold" entry */

class BaseitemKey;
class ItemEntity;
class PlayerType;
concptr activation_explanation(ItemEntity *o_ptr);
std::string activation_explanation(ItemEntity *o_ptr);
char index_to_label(int i);
int16_t wield_slot(PlayerType *player_ptr, const ItemEntity *o_ptr);
bool check_book_realm(PlayerType *player_ptr, const BaseitemKey &bi_key);
Expand Down
4 changes: 3 additions & 1 deletion src/perception/identification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "util/buffer-shaper.h"
#include "util/enum-converter.h"
#include <algorithm>
#include <array>
#include <string>

/*!
* @brief オブジェクトの*鑑定*内容を詳述して表示する /
Expand All @@ -37,7 +39,7 @@
*/
bool screen_object(PlayerType *player_ptr, ItemEntity *o_ptr, BIT_FLAGS mode)
{
concptr info[128];
std::array<std::string, 128> info{};
int trivial_info = 0;
auto flags = object_flags(o_ptr);

Expand Down
146 changes: 60 additions & 86 deletions src/wizard/artifact-analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,7 @@
#include "util/enum-range.h"
#include "util/string-processor.h"
#include "wizard/spoiler-util.h"

/*!
* @brief アーティファクトの特性一覧を出力する /
* Write a line to the spoiler file and then "underline" it with hypens
* @param art_flags アーティファクトのフラグ群
* @param flag_ptr フラグ記述情報の参照ポインタ
* @param desc_ptr 記述内容を返すための文字列参照ポインタ
* @param n_elmnts フラグの要素数
* @return desc_ptrと同じアドレス
* @details
* <pre>
* This function does most of the actual "analysis". Given a set of bit flags
* (which will be from one of the flags fields from the object in question),
* a "flag description structure", a "description list", and the number of
* elements in the "flag description structure", this function sets the
* "description list" members to the appropriate descriptions contained in
* the "flag description structure".
* The possibly updated description pointer is returned.
* </pre>
*/
static concptr *spoiler_flag_aux(const TrFlags &art_flags, const flag_desc *flag_ptr, concptr *desc_ptr, const int n_elmnts)
{
for (int i = 0; i < n_elmnts; ++i) {
if (art_flags.has(flag_ptr[i].flag)) {
*desc_ptr++ = flag_ptr[i].desc;
}
}

return desc_ptr;
}
#include <sstream>

/*!
* @brief アイテムの特定記述内容を返す /
Expand All @@ -62,11 +33,10 @@ static std::string analyze_general(PlayerType *player_ptr, ItemEntity *o_ptr)
* @param o_ptr オブジェクト構造体の参照ポインタ
* @param slay_list 種族スレイ構造体の参照ポインタ
*/
static void analyze_slay(ItemEntity *o_ptr, concptr *slay_list)
static std::vector<std::string> analyze_slay(ItemEntity *o_ptr)
{
auto flags = object_flags(o_ptr);
slay_list = spoiler_flag_aux(flags, slay_flags_desc, slay_list, N_ELEMENTS(slay_flags_desc));
*slay_list = nullptr;
return extract_spoiler_flags(flags, slay_flags_desc);
}

/*!
Expand All @@ -75,11 +45,10 @@ static void analyze_slay(ItemEntity *o_ptr, concptr *slay_list)
* @param o_ptr オブジェクト構造体の参照ポインタ
* @param brand_list 属性ブランド構造体の参照ポインタ
*/
static void analyze_brand(ItemEntity *o_ptr, concptr *brand_list)
static std::vector<std::string> analyze_brand(ItemEntity *o_ptr)
{
auto flags = object_flags(o_ptr);
brand_list = spoiler_flag_aux(flags, brand_flags_desc, brand_list, N_ELEMENTS(brand_flags_desc));
*brand_list = nullptr;
return extract_spoiler_flags(flags, brand_flags_desc);
}

/*!
Expand All @@ -88,11 +57,10 @@ static void analyze_brand(ItemEntity *o_ptr, concptr *brand_list)
* @param o_ptr オブジェクト構造体の参照ポインタ
* @param resist_list 通常耐性構造体の参照ポインタ
*/
static void analyze_resist(ItemEntity *o_ptr, concptr *resist_list)
static std::vector<std::string> analyze_resist(ItemEntity *o_ptr)
{
auto flags = object_flags(o_ptr);
resist_list = spoiler_flag_aux(flags, resist_flags_desc, resist_list, N_ELEMENTS(resist_flags_desc));
*resist_list = nullptr;
return extract_spoiler_flags(flags, resist_flags_desc);
}

/*!
Expand All @@ -101,11 +69,10 @@ static void analyze_resist(ItemEntity *o_ptr, concptr *resist_list)
* @param o_ptr オブジェクト構造体の参照ポインタ
* @param immune_list 免疫構造体の参照ポインタ
*/
static void analyze_immune(ItemEntity *o_ptr, concptr *immune_list)
static std::vector<std::string> analyze_immune(ItemEntity *o_ptr)
{
auto flags = object_flags(o_ptr);
immune_list = spoiler_flag_aux(flags, immune_flags_desc, immune_list, N_ELEMENTS(immune_flags_desc));
*immune_list = nullptr;
return extract_spoiler_flags(flags, immune_flags_desc);
}

/*!
Expand All @@ -114,11 +81,10 @@ static void analyze_immune(ItemEntity *o_ptr, concptr *immune_list)
* @param o_ptr オブジェクト構造体の参照ポインタ
* @param immune_list 弱点構造体の参照ポインタ
*/
static void analyze_vulnerable(ItemEntity *o_ptr, concptr *vulnerable_list)
static std::vector<std::string> analyze_vulnerable(ItemEntity *o_ptr)
{
auto flags = object_flags(o_ptr);
vulnerable_list = spoiler_flag_aux(flags, vulnerable_flags_desc, vulnerable_list, N_ELEMENTS(vulnerable_flags_desc));
*vulnerable_list = nullptr;
return extract_spoiler_flags(flags, vulnerable_flags_desc);
}

/*!
Expand All @@ -127,16 +93,18 @@ static void analyze_vulnerable(ItemEntity *o_ptr, concptr *vulnerable_list)
* @param o_ptr オブジェクト構造体の参照ポインタ
* @param sustain_list 維持特性構造体の参照ポインタ
*/
static void analyze_sustains(ItemEntity *o_ptr, concptr *sustain_list)
static std::vector<std::string> analyze_sustains(ItemEntity *o_ptr)
{
auto flags = object_flags(o_ptr);
if (flags.has_all_of(EnumRange(TR_SUST_STR, TR_SUST_CHR))) {
*sustain_list++ = _("全能力", "All stats");
} else if (flags.has_any_of(EnumRange(TR_SUST_STR, TR_SUST_CHR))) {
sustain_list = spoiler_flag_aux(flags, sustain_flags_desc, sustain_list, N_ELEMENTS(sustain_flags_desc));
return { _("全能力", "All stats") };
}

if (flags.has_any_of(EnumRange(TR_SUST_STR, TR_SUST_CHR))) {
return extract_spoiler_flags(flags, sustain_flags_desc);
}

*sustain_list = nullptr;
return {};
}

/*!
Expand Down Expand Up @@ -229,33 +197,36 @@ static std::vector<std::string> analyze_misc_magic(ItemEntity *o_ptr)
* @param o_ptr オブジェクト構造体の参照ポインタ
* @param addition 追加ランダム耐性構造体の参照ポインタ
*/
static void analyze_addition(ItemEntity *o_ptr, char *addition, size_t addition_sz)
static std::string analyze_addition(ItemEntity *o_ptr)
{
const auto &artifact = o_ptr->get_fixed_artifact();
strcpy(addition, "");

std::stringstream ss;
if (artifact.gen_flags.has_all_of({ ItemGenerationTraitType::XTRA_POWER, ItemGenerationTraitType::XTRA_H_RES })) {
angband_strcat(addition, _("能力and耐性", "Ability and Resistance"), addition_sz);
ss << _("能力and耐性", "Ability and Resistance");
} else if (artifact.gen_flags.has(ItemGenerationTraitType::XTRA_POWER)) {
angband_strcat(addition, _("能力", "Ability"), addition_sz);
ss << _("能力", "Ability");
if (artifact.gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
angband_strcat(addition, _("(1/2でand耐性)", "(plus Resistance about 1/2)"), addition_sz);
ss << _("(1/2でand耐性)", "(plus Resistance about 1/2)");
}
} else if (artifact.gen_flags.has(ItemGenerationTraitType::XTRA_H_RES)) {
angband_strcat(addition, _("耐性", "Resistance"), addition_sz);
ss << _("耐性", "Resistance");
if (artifact.gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
angband_strcat(addition, _("(1/2でand能力)", "(plus Ability about 1/2)"), addition_sz);
ss << _("(1/2でand能力)", "(plus Ability about 1/2)");
}
} else if (artifact.gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER)) {
angband_strcat(addition, _("能力or耐性", "Ability or Resistance"), addition_sz);
ss << _("能力or耐性", "Ability or Resistance");
}

if (artifact.gen_flags.has(ItemGenerationTraitType::XTRA_DICE)) {
if (strlen(addition) > 0) {
angband_strcat(addition, _("、", ", "), addition_sz);
}
angband_strcat(addition, _("ダイス数", "Dice number"), addition_sz);
if (artifact.gen_flags.has_not(ItemGenerationTraitType::XTRA_DICE)) {
return ss.str();
}

if (ss.tellp() > 0) {
ss << _("、", ", ");
}

ss << _("ダイス数", "Dice number");
return ss.str();
}

/*!
Expand All @@ -265,12 +236,13 @@ static void analyze_addition(ItemEntity *o_ptr, char *addition, size_t addition_
* @param o_ptr オブジェクト構造体の参照ポインタ
* @param misc_desc 基本情報を収める文字列参照ポインタ
*/
static void analyze_misc(ItemEntity *o_ptr, char *misc_desc, size_t misc_desc_sz)
static std::string analyze_misc(ItemEntity *o_ptr)
{
const auto &artifact = o_ptr->get_fixed_artifact();
const auto *mes = _("レベル %d, 希少度 %u, %d.%d kg, $%ld", "Level %d, Rarity %u, %d.%d lbs, %ld Gold");
strnfmt(misc_desc, misc_desc_sz, mes, (int)artifact.level, artifact.rarity,
_(lb_to_kg_integer(artifact.weight), artifact.weight / 10), _(lb_to_kg_fraction(artifact.weight), artifact.weight % 10), (long int)artifact.cost);
constexpr auto fmt = _("レベル %d, 希少度 %u, %d.%d kg, $%d", "Level %d, Rarity %u, %d.%d lbs, %d Gold");
const auto weight_integer = _(lb_to_kg_integer(artifact.weight), artifact.weight / 10);
const auto weight_fraction = _(lb_to_kg_fraction(artifact.weight), artifact.weight % 10);
return format(fmt, artifact.level, artifact.rarity, weight_integer, weight_fraction, artifact.cost);
}

/*!
Expand All @@ -281,17 +253,17 @@ static void analyze_misc(ItemEntity *o_ptr, char *misc_desc, size_t misc_desc_sz
*/
void object_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *desc_ptr)
{
angband_strcpy(desc_ptr->description, analyze_general(player_ptr, o_ptr), MAX_NLEN);
desc_ptr->description = analyze_general(player_ptr, o_ptr);
desc_ptr->pval_info.analyze(*o_ptr);
analyze_brand(o_ptr, desc_ptr->brands);
analyze_slay(o_ptr, desc_ptr->slays);
analyze_immune(o_ptr, desc_ptr->immunities);
analyze_resist(o_ptr, desc_ptr->resistances);
analyze_vulnerable(o_ptr, desc_ptr->vulnerables);
analyze_sustains(o_ptr, desc_ptr->sustains);
desc_ptr->brands = analyze_brand(o_ptr);
desc_ptr->slays = analyze_slay(o_ptr);
desc_ptr->immunities = analyze_immune(o_ptr);
desc_ptr->resistances = analyze_resist(o_ptr);
desc_ptr->vulnerabilities = analyze_vulnerable(o_ptr);
desc_ptr->sustenances = analyze_sustains(o_ptr);
desc_ptr->misc_magic = analyze_misc_magic(o_ptr);
analyze_addition(o_ptr, desc_ptr->addition, sizeof(desc_ptr->addition));
analyze_misc(o_ptr, desc_ptr->misc_desc, sizeof(desc_ptr->misc_desc));
desc_ptr->addition = analyze_addition(o_ptr);
desc_ptr->misc_desc = analyze_misc(o_ptr);
desc_ptr->activation = activation_explanation(o_ptr);
}

Expand All @@ -303,16 +275,18 @@ void object_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *de
*/
void random_artifact_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *desc_ptr)
{
angband_strcpy(desc_ptr->description, analyze_general(player_ptr, o_ptr), MAX_NLEN);
desc_ptr->description = analyze_general(player_ptr, o_ptr);
desc_ptr->pval_info.analyze(*o_ptr);
analyze_brand(o_ptr, desc_ptr->brands);
analyze_slay(o_ptr, desc_ptr->slays);
analyze_immune(o_ptr, desc_ptr->immunities);
analyze_resist(o_ptr, desc_ptr->resistances);
analyze_vulnerable(o_ptr, desc_ptr->vulnerables);
analyze_sustains(o_ptr, desc_ptr->sustains);
desc_ptr->brands = analyze_brand(o_ptr);
desc_ptr->slays = analyze_slay(o_ptr);
desc_ptr->immunities = analyze_immune(o_ptr);
desc_ptr->resistances = analyze_resist(o_ptr);
desc_ptr->vulnerabilities = analyze_vulnerable(o_ptr);
desc_ptr->sustenances = analyze_sustains(o_ptr);
desc_ptr->misc_magic = analyze_misc_magic(o_ptr);
desc_ptr->activation = activation_explanation(o_ptr);
sprintf(desc_ptr->misc_desc, _("重さ %d.%d kg", "Weight %d.%d lbs"), _(lb_to_kg_integer(o_ptr->weight), o_ptr->weight / 10),
_(lb_to_kg_fraction(o_ptr->weight), o_ptr->weight % 10));
constexpr auto weight_mes = _("重さ %d.%d kg", "Weight %d.%d lbs");
const auto weight_integer = _(lb_to_kg_integer(o_ptr->weight), o_ptr->weight / 10);
const auto weight_fraction = _(lb_to_kg_fraction(o_ptr->weight), o_ptr->weight % 10);
desc_ptr->misc_desc = format(weight_mes, weight_integer, weight_fraction);
}
Loading
Loading