OSDN Git Service

[Chore] UTF-8エンコーディングのファイルからBOMを削除
[hengbandforosx/hengbandosx.git] / src / object / object-value.cpp
index 57fdc96..e187d25 100644 (file)
-#include "object/object-value.h"
+#include "object/object-value.h"
 #include "monster-race/monster-race.h"
-#include "object-enchant/object-curse.h"
-#include "object-enchant/object-ego.h"
-#include "object-enchant/special-object-flags.h"
-#include "object-enchant/tr-types.h"
-#include "object-hook/hook-checker.h"
-#include "object-hook/hook-enchant.h"
-#include "object/object-broken.h"
 #include "object/object-flags.h"
-#include "object/object-kind.h"
 #include "object/object-value-calc.h"
-#include "perception/object-perception.h"
+#include "object/tval-types.h"
 #include "system/artifact-type-definition.h"
-#include "system/monster-race-definition.h"
-#include "system/object-type-definition.h"
+#include "system/baseitem-info.h"
+#include "system/item-entity.h"
+#include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
-#include "util/bit-flags-calculator.h"
-
-/*!
- * @brief 未鑑定なベースアイテムの基本価格を返す /
- * Return the "value" of an "unknown" item Make a guess at the value of non-aware items
- * @param o_ptr 未鑑定価格を確認したいオブジェクトの構造体参照ポインタ
- * @return オブジェクトの未鑑定価格
- */
-static PRICE object_value_base(const object_type *o_ptr)
-{
-    if (o_ptr->is_aware())
-        return (k_info[o_ptr->k_idx].cost);
-
-    switch (o_ptr->tval) {
-    case TV_FOOD:
-        return (5L);
-    case TV_POTION:
-        return (20L);
-    case TV_SCROLL:
-        return (20L);
-    case TV_STAFF:
-        return (70L);
-    case TV_WAND:
-        return (50L);
-    case TV_ROD:
-        return (90L);
-    case TV_RING:
-        return (45L);
-    case TV_AMULET:
-        return (45L);
-    case TV_FIGURINE: {
-        DEPTH level = r_info[o_ptr->pval].level;
-        if (level < 20)
-            return level * 50L;
-        else if (level < 30)
-            return 1000 + (level - 20) * 150L;
-        else if (level < 40)
-            return 2500 + (level - 30) * 350L;
-        else if (level < 50)
-            return 6000 + (level - 40) * 800L;
-        else
-            return 14000 + (level - 50) * 2000L;
-    }
-    case TV_CAPTURE:
-        if (!o_ptr->pval)
-            return 1000L;
-        else
-            return ((r_info[o_ptr->pval].level) * 50L + 1000);
-
-    default:
-        break;
-    }
-
-    return (0L);
-}
-
-/*!
- * @brief オブジェクト価格算出のメインルーチン /
- * Return the price of an item including plusses (and charges)
- * @param o_ptr 判明している現価格を確認したいオブジェクトの構造体参照ポインタ
- * @return オブジェクトの判明している現価格
- * @details
- * This function returns the "value" of the given item (qty one)\n
- *\n
- * Never notice "unknown" bonuses or properties, including "curses",\n
- * since that would give the player information he did not have.\n
- *\n
- * Note that discounted items stay discounted forever, even if\n
- * the discount is "forgotten" by the player via memory loss.\n
- */
-PRICE object_value(const object_type *o_ptr)
-{
-    PRICE value;
-
-    if (o_ptr->is_known()) {
-        if (o_ptr->is_broken())
-            return (0L);
-        if (o_ptr->is_cursed())
-            return (0L);
-
-        value = object_value_real(o_ptr);
-    } else {
-        if ((o_ptr->ident & (IDENT_SENSE)) && o_ptr->is_broken())
-            return (0L);
-        if ((o_ptr->ident & (IDENT_SENSE)) && o_ptr->is_cursed())
-            return (0L);
-
-        value = object_value_base(o_ptr);
-    }
-
-    if (o_ptr->discount)
-        value -= (value * o_ptr->discount / 100L);
-
-    return (value);
-}
 
 /*!
  * @brief オブジェクトの真の価格を算出する /
@@ -137,186 +35,208 @@ PRICE object_value(const object_type *o_ptr)
  *\n
  * Every wearable item with a "pval" bonus is worth extra (see below).\n
  */
-PRICE object_value_real(const object_type *o_ptr)
+PRICE object_value_real(const ItemEntity *o_ptr)
 {
-    TrFlags flgs;
-    object_kind *k_ptr = &k_info[o_ptr->k_idx];
+    const auto &baseitem = o_ptr->get_baseitem();
 
-    if (!k_info[o_ptr->k_idx].cost)
-        return (0L);
+    if (!baseitem.cost) {
+        return 0;
+    }
 
-    PRICE value = k_info[o_ptr->k_idx].cost;
-    object_flags(o_ptr, flgs);
+    PRICE value = baseitem.cost;
+    auto flags = object_flags(o_ptr);
     if (o_ptr->is_fixed_artifact()) {
-        artifact_type *a_ptr = &a_info[o_ptr->name1];
-        if (!a_ptr->cost)
-            return (0L);
+        const auto &artifact = o_ptr->get_fixed_artifact();
+        if (!artifact.cost) {
+            return 0;
+        }
 
-        value = a_ptr->cost;
+        value = artifact.cost;
         value += flag_cost(o_ptr, o_ptr->pval);
-        return (value);
+        return value;
     } else if (o_ptr->is_ego()) {
-        ego_item_type *e_ptr = &e_info[o_ptr->name2];
-        if (!e_ptr->cost)
-            return (0L);
+        const auto &ego = o_ptr->get_ego();
+        if (!ego.cost) {
+            return 0;
+        }
 
-        value += e_ptr->cost;
+        value += ego.cost;
         value += flag_cost(o_ptr, o_ptr->pval);
     } else {
-        bool flag = false;
-        for (int i = 0; i < TR_FLAG_SIZE; i++)
-            if (o_ptr->art_flags[i])
-                flag = true;
-
-        if (flag)
+        if (o_ptr->art_flags.any()) {
             value += flag_cost(o_ptr, o_ptr->pval);
+        }
     }
 
     /* Analyze pval bonus for normal object */
-    switch (o_ptr->tval) {
-    case TV_SHOT:
-    case TV_ARROW:
-    case TV_BOLT:
-    case TV_BOW:
-    case TV_DIGGING:
-    case TV_HAFTED:
-    case TV_POLEARM:
-    case TV_SWORD:
-    case TV_BOOTS:
-    case TV_GLOVES:
-    case TV_HELM:
-    case TV_CROWN:
-    case TV_SHIELD:
-    case TV_CLOAK:
-    case TV_SOFT_ARMOR:
-    case TV_HARD_ARMOR:
-    case TV_DRAG_ARMOR:
-    case TV_LITE:
-    case TV_AMULET:
-    case TV_RING:
-        if (!o_ptr->pval)
+    switch (o_ptr->bi_key.tval()) {
+    case ItemKindType::SHOT:
+    case ItemKindType::ARROW:
+    case ItemKindType::BOLT:
+    case ItemKindType::BOW:
+    case ItemKindType::DIGGING:
+    case ItemKindType::HAFTED:
+    case ItemKindType::POLEARM:
+    case ItemKindType::SWORD:
+    case ItemKindType::BOOTS:
+    case ItemKindType::GLOVES:
+    case ItemKindType::HELM:
+    case ItemKindType::CROWN:
+    case ItemKindType::SHIELD:
+    case ItemKindType::CLOAK:
+    case ItemKindType::SOFT_ARMOR:
+    case ItemKindType::HARD_ARMOR:
+    case ItemKindType::DRAG_ARMOR:
+    case ItemKindType::LITE:
+    case ItemKindType::AMULET:
+    case ItemKindType::RING:
+        if (!o_ptr->pval) {
             break;
-        if (o_ptr->pval < 0)
-            return (0L);
+        }
+        if (o_ptr->pval < 0) {
+            return 0;
+        }
 
-        if (has_flag(flgs, TR_STR))
+        if (flags.has(TR_STR)) {
             value += (o_ptr->pval * 200L);
-        if (has_flag(flgs, TR_INT))
+        }
+        if (flags.has(TR_INT)) {
             value += (o_ptr->pval * 200L);
-        if (has_flag(flgs, TR_WIS))
+        }
+        if (flags.has(TR_WIS)) {
             value += (o_ptr->pval * 200L);
-        if (has_flag(flgs, TR_DEX))
+        }
+        if (flags.has(TR_DEX)) {
             value += (o_ptr->pval * 200L);
-        if (has_flag(flgs, TR_CON))
+        }
+        if (flags.has(TR_CON)) {
             value += (o_ptr->pval * 200L);
-        if (has_flag(flgs, TR_CHR))
+        }
+        if (flags.has(TR_CHR)) {
             value += (o_ptr->pval * 200L);
-        if (has_flag(flgs, TR_MAGIC_MASTERY))
+        }
+        if (flags.has(TR_MAGIC_MASTERY)) {
             value += (o_ptr->pval * 100);
-        if (has_flag(flgs, TR_STEALTH))
+        }
+        if (flags.has(TR_STEALTH)) {
             value += (o_ptr->pval * 100L);
-        if (has_flag(flgs, TR_SEARCH))
+        }
+        if (flags.has(TR_SEARCH)) {
             value += (o_ptr->pval * 100L);
-        if (has_flag(flgs, TR_INFRA))
+        }
+        if (flags.has(TR_INFRA)) {
             value += (o_ptr->pval * 50L);
-        if (has_flag(flgs, TR_TUNNEL))
+        }
+        if (flags.has(TR_TUNNEL)) {
             value += (o_ptr->pval * 50L);
-        if (has_flag(flgs, TR_BLOWS))
+        }
+        if (flags.has(TR_BLOWS)) {
             value += (o_ptr->pval * 5000L);
-        if (has_flag(flgs, TR_SPEED))
+        }
+        if (flags.has(TR_SPEED)) {
             value += (o_ptr->pval * 10000L);
+        }
         break;
 
     default:
         break;
     }
 
-    switch (o_ptr->tval) {
-    case TV_WAND: {
+    switch (o_ptr->bi_key.tval()) {
+    case ItemKindType::WAND: {
         /* Pay extra for charges, depending on standard number of
          * charges.  Handle new-style wands correctly. -LM-
          */
-        value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
+        value += (value * o_ptr->pval / o_ptr->number / (baseitem.pval * 2));
         break;
     }
-    case TV_STAFF: {
+    case ItemKindType::STAFF: {
         /* Pay extra for charges, depending on standard number of
          * charges.  -LM-
          */
-        value += (value * o_ptr->pval / (k_ptr->pval * 2));
+        value += (value * o_ptr->pval / (baseitem.pval * 2));
         break;
     }
-    case TV_RING:
-    case TV_AMULET: {
-        if (o_ptr->to_h + o_ptr->to_d + o_ptr->to_a < 0)
-            return (0L);
+    case ItemKindType::RING:
+    case ItemKindType::AMULET: {
+        if (o_ptr->to_h + o_ptr->to_d + o_ptr->to_a < 0) {
+            return 0;
+        }
 
         value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
         break;
     }
-    case TV_BOOTS:
-    case TV_GLOVES:
-    case TV_CLOAK:
-    case TV_CROWN:
-    case TV_HELM:
-    case TV_SHIELD:
-    case TV_SOFT_ARMOR:
-    case TV_HARD_ARMOR:
-    case TV_DRAG_ARMOR: {
-        if (o_ptr->to_a < 0)
-            return (0L);
-
-        value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
+    case ItemKindType::BOOTS:
+    case ItemKindType::GLOVES:
+    case ItemKindType::CLOAK:
+    case ItemKindType::CROWN:
+    case ItemKindType::HELM:
+    case ItemKindType::SHIELD:
+    case ItemKindType::SOFT_ARMOR:
+    case ItemKindType::HARD_ARMOR:
+    case ItemKindType::DRAG_ARMOR: {
+        if (o_ptr->to_a < 0) {
+            return 0;
+        }
+
+        value += (((o_ptr->to_h - baseitem.to_h) + (o_ptr->to_d - baseitem.to_d)) * 200L + (o_ptr->to_a) * 100L);
         break;
     }
-    case TV_BOW:
-    case TV_DIGGING:
-    case TV_HAFTED:
-    case TV_SWORD:
-    case TV_POLEARM: {
-        if (o_ptr->to_h + o_ptr->to_d < 0)
-            return (0L);
+    case ItemKindType::BOW:
+    case ItemKindType::DIGGING:
+    case ItemKindType::HAFTED:
+    case ItemKindType::SWORD:
+    case ItemKindType::POLEARM: {
+        if (o_ptr->to_h + o_ptr->to_d < 0) {
+            return 0;
+        }
 
         value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 100L);
-        value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
-        value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
+        value += (o_ptr->dd - baseitem.dd) * o_ptr->ds * 250L;
+        value += (o_ptr->ds - baseitem.ds) * o_ptr->dd * 250L;
         break;
     }
-    case TV_SHOT:
-    case TV_ARROW:
-    case TV_BOLT: {
-        if (o_ptr->to_h + o_ptr->to_d < 0)
-            return (0L);
+    case ItemKindType::SHOT:
+    case ItemKindType::ARROW:
+    case ItemKindType::BOLT: {
+        if (o_ptr->to_h + o_ptr->to_d < 0) {
+            return 0;
+        }
 
         value += ((o_ptr->to_h + o_ptr->to_d) * 5L);
-        value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
-        value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
+        value += (o_ptr->dd - baseitem.dd) * o_ptr->ds * 5L;
+        value += (o_ptr->ds - baseitem.ds) * o_ptr->dd * 5L;
         break;
     }
-    case TV_FIGURINE: {
-        DEPTH level = r_info[o_ptr->pval].level;
-        if (level < 20)
+    case ItemKindType::FIGURINE: {
+        auto figure_r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
+        DEPTH level = monraces_info[figure_r_idx].level;
+        if (level < 20) {
             value = level * 50L;
-        else if (level < 30)
+        } else if (level < 30) {
             value = 1000 + (level - 20) * 150L;
-        else if (level < 40)
+        } else if (level < 40) {
             value = 2500 + (level - 30) * 350L;
-        else if (level < 50)
+        } else if (level < 50) {
             value = 6000 + (level - 40) * 800L;
-        else
+        } else {
             value = 14000 + (level - 50) * 2000L;
+        }
         break;
     }
-    case TV_CAPTURE: {
-        if (!o_ptr->pval)
+    case ItemKindType::CAPTURE: {
+        auto capture_r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
+        if (!MonsterRace(capture_r_idx).is_valid()) {
             value = 1000L;
-        else
-            value = ((r_info[o_ptr->pval].level) * 50L + 1000);
+        } else {
+            value = ((monraces_info[capture_r_idx].level) * 50L + 1000);
+        }
         break;
     }
-    case TV_CHEST: {
-        if (!o_ptr->pval)
+    case ItemKindType::CHEST: {
+        if (!o_ptr->pval) {
             value = 0L;
+        }
         break;
     }
 
@@ -324,8 +244,9 @@ PRICE object_value_real(const object_type *o_ptr)
         break;
     }
 
-    if (value < 0)
+    if (value < 0) {
         return 0L;
+    }
 
-    return (value);
+    return value;
 }