-#include "wizard/fixed-artifacts-spoiler.h"
+#include "wizard/fixed-artifacts-spoiler.h"
#include "io/files-util.h"
#include "object/object-kind-hook.h"
#include "system/angband-version.h"
#include "view/display-messages.h"
#include "wizard/artifact-analyzer.h"
#include "wizard/spoiler-util.h"
+#include <sstream>
/*!
* @brief フラグ名称を出力する汎用関数
* @param header ヘッダに出力するフラグ群の名前
- * @param list フラグ名リスト
+ * @param descriptions フラグ名リスト
* @param separator フラグ表示の区切り記号
- * @todo 固定アーティファクトとランダムアーティファクトで共用、ここに置くべきかは要調整.
*/
-void spoiler_outlist(concptr header, concptr *list, char separator)
+void spoiler_outlist(std::string_view header, const std::vector<std::string> &descriptions, char separator)
{
- if (*list == nullptr) {
+ if (descriptions.empty()) {
return;
}
std::string line = spoiler_indent;
- if (header && (header[0])) {
+ if (!header.empty()) {
line.append(header).append(" ");
}
- while (true) {
- std::string elem = *list;
- if (list[1]) {
+ for (size_t i = 0; i < descriptions.size(); i++) {
+ auto elem = descriptions[i];
+ if (i < descriptions.size() - 1) {
elem.push_back(separator);
elem.push_back(' ');
}
if (line.length() + elem.length() <= MAX_LINE_LEN) {
line.append(elem);
- } else {
- if (line.length() > 1 && line[line.length() - 1] == ' ' && line[line.length() - 2] == list_separator) {
- line[line.length() - 2] = '\0';
- fprintf(spoiler_file, "%s\n", line.data());
- line = spoiler_indent;
- line.append(elem);
- } else {
- fprintf(spoiler_file, "%s\n", line.data());
- line = " ";
- line.append(elem);
- }
+ continue;
}
- if (!*++list) {
- break;
+ if (line.length() > 1 && line[line.length() - 1] == ' ' && line[line.length() - 2] == list_separator) {
+ line[line.length() - 2] = '\0';
+ fprintf(spoiler_file, "%s\n", line.data());
+ line = spoiler_indent;
+ line.append(elem);
+ } else {
+ fprintf(spoiler_file, "%s\n", line.data());
+ line = " ";
+ line.append(elem);
}
}
}
/*!
- * @brief アーティファクト情報を出力するためにダミー生成を行う /
- * Hack -- Create a "forged" artifact
- * @param o_ptr 一時生成先を保管するオブジェクト構造体
+ * @brief アーティファクト情報を出力するためにダミー生成を行う
* @param fixed_artifact_idx 生成するアーティファクトID
- * @return ç\94\9fæ\88\90ã\81\8cæ\88\90å\8a\9fã\81\97ã\81\9få ´å\90\88TRUEã\82\92è¿\94ã\81\99
+ * @return ç\94\9fæ\88\90ã\81\97ã\81\9fã\82¢ã\83¼ã\83\86ã\82£ã\83\95ã\82¡ã\82¯ã\83\88 (é\80£ç\95ªã\81§å\9f\8bã\81¾ã\81£ã\81¦ã\81\84ã\82\8bã\81®ã\81§ä¸\8då\98å\9c¨ä¾\8bå¤\96ã\81¯å\90\90ã\81\8bã\81ªã\81\84)
*/
-static bool make_fake_artifact(ItemEntity *o_ptr, FixedArtifactId fixed_artifact_idx)
+static ItemEntity make_fake_artifact(FixedArtifactId fixed_artifact_idx)
{
- auto &a_ref = artifacts_info.at(fixed_artifact_idx);
- if (a_ref.name.empty()) {
- return false;
- }
-
- const auto bi_id = lookup_baseitem_id(a_ref.bi_key);
- if (bi_id == 0) {
- return false;
- }
-
- o_ptr->prep(bi_id);
- o_ptr->fixed_artifact_idx = fixed_artifact_idx;
- o_ptr->pval = a_ref.pval;
- o_ptr->ac = a_ref.ac;
- o_ptr->dd = a_ref.dd;
- o_ptr->ds = a_ref.ds;
- o_ptr->to_a = a_ref.to_a;
- o_ptr->to_h = a_ref.to_h;
- o_ptr->to_d = a_ref.to_d;
- o_ptr->weight = a_ref.weight;
- return true;
+ const auto &artifact = ArtifactsInfo::get_instance().get_artifact(fixed_artifact_idx);
+ const auto bi_id = lookup_baseitem_id(artifact.bi_key);
+ ItemEntity item;
+ item.prep(bi_id);
+ item.fixed_artifact_idx = fixed_artifact_idx;
+ item.pval = artifact.pval;
+ item.ac = artifact.ac;
+ item.dd = artifact.dd;
+ item.ds = artifact.ds;
+ item.to_a = artifact.to_a;
+ item.to_h = artifact.to_h;
+ item.to_d = artifact.to_d;
+ item.weight = artifact.weight;
+ return item;
}
/*!
*/
static void spoiler_print_art(obj_desc_list *art_ptr)
{
- pval_info_type *pval_ptr = &art_ptr->pval_info;
- fprintf(spoiler_file, "%s\n", art_ptr->description);
- if (pval_ptr->pval_desc[0]) {
- spoiler_outlist(std::string(pval_ptr->pval_desc).append(_("の修正:", " to")).data(), pval_ptr->pval_affects, item_separator);
+ const auto *pval_ptr = &art_ptr->pval_info;
+ fprintf(spoiler_file, "%s\n", art_ptr->description.data());
+ 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);
}
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(_("弱点:", "Vulnerable"), art_ptr->vulnerables, item_separator);
- spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustains, item_separator);
+ spoiler_outlist(_("弱点:", "Vulnerable"), art_ptr->vulnerabilities, item_separator);
+ spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustenances, item_separator);
spoiler_outlist("", art_ptr->misc_magic, list_separator);
- if (art_ptr->addition[0]) {
- fprintf(spoiler_file, _("%s追加: %s\n", "%sAdditional %s\n"), spoiler_indent, art_ptr->addition);
+ if (!art_ptr->addition.empty()) {
+ fprintf(spoiler_file, _("%s追加: %s\n", "%sAdditional %s\n"), spoiler_indent, art_ptr->addition.data());
}
- if (art_ptr->activation) {
- fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent, art_ptr->activation);
+ if (!art_ptr->activation.empty()) {
+ fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent, art_ptr->activation.data());
}
- fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc);
+ fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc.data());
}
/*!
- * @brief アーティファクト情報のスポイラー出力を行うメインルーチン /
- * Create a spoiler file for artifacts
- * @param fname 生成ファイル名
+ * @brief アーティファクト情報のスポイラー出力を行うメインルーチン
*/
-SpoilerOutputResultType spoil_fixed_artifact(concptr fname)
+SpoilerOutputResultType spoil_fixed_artifact()
{
- char buf[1024];
- path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
- spoiler_file = angband_fopen(buf, FileOpenMode::WRITE);
+ const auto &path = path_build(ANGBAND_DIR_USER, "artifact.txt");
+ spoiler_file = angband_fopen(path, FileOpenMode::WRITE);
if (!spoiler_file) {
return SpoilerOutputResultType::FILE_OPEN_FAILED;
}
spoiler_blanklines(1);
for (auto tval : tval_list) {
- for (const auto &[a_idx, a_ref] : artifacts_info) {
- if (a_ref.bi_key.tval() != tval) {
- continue;
- }
-
- ItemEntity item;
- if (!make_fake_artifact(&item, a_idx)) {
+ for (const auto &[a_idx, artifact] : artifacts_info) {
+ if (artifact.bi_key.tval() != tval) {
continue;
}
+ const auto item = make_fake_artifact(a_idx);
PlayerType dummy;
- obj_desc_list artifact;
- object_analyze(&dummy, &item, &artifact);
- spoiler_print_art(&artifact);
+ obj_desc_list artifact_descriptions;
+ object_analyze(&dummy, &item, &artifact_descriptions);
+ spoiler_print_art(&artifact_descriptions);
}
}
}