OSDN Git Service

[Refactor] #40233 Separated pricing.c/h from store.c/h
authorHourier <hourier@users.sourceforge.jp>
Thu, 16 Jul 2020 13:52:11 +0000 (22:52 +0900)
committerHourier <hourier@users.sourceforge.jp>
Thu, 16 Jul 2020 14:00:19 +0000 (23:00 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/store/pricing.c [new file with mode: 0644]
src/store/pricing.h [new file with mode: 0644]
src/store/purchase-order.c
src/store/sell-order.c
src/store/store.c
src/store/store.h
src/view/display-store.c

index 18b52ba..00b0969 100644 (file)
     <ClCompile Include="..\..\src\store\home.c" />\r
     <ClCompile Include="..\..\src\store\museum.c" />\r
     <ClCompile Include="..\..\src\store\owner-insults.c" />\r
+    <ClCompile Include="..\..\src\store\pricing.c" />\r
     <ClCompile Include="..\..\src\store\purchase-order.c" />\r
     <ClCompile Include="..\..\src\store\sell-order.c" />\r
     <ClCompile Include="..\..\src\view\display-inventory.c" />\r
     <ClInclude Include="..\..\src\store\home.h" />\r
     <ClInclude Include="..\..\src\store\museum.h" />\r
     <ClInclude Include="..\..\src\store\owner-insults.h" />\r
+    <ClInclude Include="..\..\src\store\pricing.h" />\r
     <ClInclude Include="..\..\src\store\purchase-order.h" />\r
     <ClInclude Include="..\..\src\store\sell-order.h" />\r
     <ClInclude Include="..\..\src\system\alloc-entries.h" />\r
index 6bb59d8..850a841 100644 (file)
     <ClCompile Include="..\..\src\store\museum.c">
       <Filter>store</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\store\pricing.c">
+      <Filter>store</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\combat\shoot.h">
     <ClInclude Include="..\..\src\store\museum.h">
       <Filter>store</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\store\pricing.h">
+      <Filter>store</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 3349d4e..4bcbacb 100644 (file)
@@ -649,6 +649,7 @@ hengband_SOURCES = \
        store/home.c store/home.h \
        store/store.c store/store.h \
        store/black-market.c store/black-market.h \
+       store/pricing.c store/pricing.h \
        store/purchase-order.c store/purchase-order.h \
        store/owner-insults.c store/owner-insults.h \
        store/purchase-order.c store/purchase-order.h \
diff --git a/src/store/pricing.c b/src/store/pricing.c
new file mode 100644 (file)
index 0000000..2061676
--- /dev/null
@@ -0,0 +1,75 @@
+#include "store/pricing.h"
+#include "market/gold-magnification-table.h"
+#include "object/object-value.h"
+#include "store/store-util.h"
+#include "store/store.h"
+
+/*!
+ * @brief 店舗価格を決定する. 無料にはならない /
+ * Determine the price of an item (qty one) in a store.
+ * @param o_ptr 店舗に並べるオブジェクト構造体の参照ポインタ
+ * @param greed 店主の強欲度
+ * @param flip TRUEならば店主にとっての買取価格、FALSEなら売出価格を計算
+ * @return アイテムの店舗価格
+ * @details
+ * <pre>
+ * This function takes into account the player's charisma, and the
+ * shop-keepers friendliness, and the shop-keeper's base greed, but
+ * never lets a shop-keeper lose money in a transaction.
+ * The "greed" value should exceed 100 when the player is "buying" the
+ * item, and should be less than 100 when the player is "selling" it.
+ * Hack -- the black market always charges twice as much as it should.
+ * Charisma adjustment runs from 80 to 130
+ * Racial adjustment runs from 95 to 130
+ * Since greed/charisma/racial adjustments are centered at 100, we need
+ * to adjust (by 200) to extract a usable multiplier.  Note that the
+ * "greed" value is always something (?).
+ * </pre>
+ */
+PRICE price_item(player_type *player_ptr, object_type *o_ptr, int greed, bool flip)
+{
+    PRICE price = object_value(player_ptr, o_ptr);
+    if (price <= 0)
+        return 0L;
+
+    int factor = rgold_adj[ot_ptr->owner_race][player_ptr->prace];
+    factor += adj_chr_gold[player_ptr->stat_ind[A_CHR]];
+    int adjust;
+    if (flip) {
+        adjust = 100 + (300 - (greed + factor));
+        if (adjust > 100)
+            adjust = 100;
+
+        if (cur_store_num == STORE_BLACK)
+            price = price / 2;
+
+        price = (price * adjust + 50L) / 100L;
+    } else {
+        adjust = 100 + ((greed + factor) - 300);
+        if (adjust < 100)
+            adjust = 100;
+
+        if (cur_store_num == STORE_BLACK)
+            price = price * 2;
+
+        price = (s32b)(((u32b)price * (u32b)adjust + 50UL) / 100UL);
+    }
+
+    if (price <= 0L)
+        return 1L;
+
+    return price;
+}
+
+/*!
+ * @brief 店舗の割引対象外にするかどうかを判定 /
+ * Eliminate need to bargain if player has haggled well in the past
+ * @param minprice アイテムの最低販売価格
+ * @return 割引を禁止するならTRUEを返す。
+ */
+bool noneedtobargain(PRICE minprice)
+{
+    PRICE good = st_ptr->good_buy;
+    PRICE bad = st_ptr->bad_buy;
+    return (minprice < 10L) || (good == MAX_SHORT) || (good > ((3 * bad) + (5 + (minprice / 50))));
+}
diff --git a/src/store/pricing.h b/src/store/pricing.h
new file mode 100644 (file)
index 0000000..bf92616
--- /dev/null
@@ -0,0 +1,6 @@
+#pragma once
+
+#include "system/angband.h"
+
+PRICE price_item(player_type *player_ptr, object_type *o_ptr, int greed, bool flip);
+bool noneedtobargain(PRICE minprice);
index 0926072..5bc55fe 100644 (file)
@@ -22,6 +22,7 @@
 #include "player/race-info-table.h"
 #include "store/home.h"
 #include "store/owner-insults.h"
+#include "store/pricing.h"
 #include "store/say-comments.h"
 #include "store/store-util.h"
 #include "store/store.h"
index f78d3f5..8866490 100644 (file)
@@ -27,6 +27,7 @@
 #include "spell-kind/spells-perception.h"
 #include "store/home.h"
 #include "store/owner-insults.h"
+#include "store/pricing.h"
 #include "store/say-comments.h"
 #include "store/store-util.h"
 #include "store/store.h"
index a996e99..1dab09b 100644 (file)
@@ -113,60 +113,6 @@ int cur_store_feat;
 bool allow_inc = FALSE;
 
 /*!
- * @brief 店舗価格を決定する. 無料にはならない /
- * Determine the price of an item (qty one) in a store.
- * @param o_ptr 店舗に並べるオブジェクト構造体の参照ポインタ
- * @param greed 店主の強欲度
- * @param flip TRUEならば店主にとっての買取価格、FALSEなら売出価格を計算
- * @return アイテムの店舗価格
- * @details
- * <pre>
- * This function takes into account the player's charisma, and the
- * shop-keepers friendliness, and the shop-keeper's base greed, but
- * never lets a shop-keeper lose money in a transaction.
- * The "greed" value should exceed 100 when the player is "buying" the
- * item, and should be less than 100 when the player is "selling" it.
- * Hack -- the black market always charges twice as much as it should.
- * Charisma adjustment runs from 80 to 130
- * Racial adjustment runs from 95 to 130
- * Since greed/charisma/racial adjustments are centered at 100, we need
- * to adjust (by 200) to extract a usable multiplier.  Note that the
- * "greed" value is always something (?).
- * </pre>
- */
-PRICE price_item(player_type *player_ptr, object_type *o_ptr, int greed, bool flip)
-{
-    PRICE price = object_value(player_ptr, o_ptr);
-    if (price <= 0)
-        return (0L);
-
-    int factor = rgold_adj[ot_ptr->owner_race][player_ptr->prace];
-    factor += adj_chr_gold[player_ptr->stat_ind[A_CHR]];
-    int adjust;
-    if (flip) {
-        adjust = 100 + (300 - (greed + factor));
-        if (adjust > 100)
-            adjust = 100;
-        if (cur_store_num == STORE_BLACK)
-            price = price / 2;
-
-        price = (price * adjust + 50L) / 100L;
-    } else {
-        adjust = 100 + ((greed + factor) - 300);
-        if (adjust < 100)
-            adjust = 100;
-        if (cur_store_num == STORE_BLACK)
-            price = price * 2;
-
-        price = (s32b)(((u32b)price * (u32b)adjust + 50UL) / 100UL);
-    }
-
-    if (price <= 0L)
-        return (1L);
-    return price;
-}
-
-/*!
  * @brief 店舗に品を置くスペースがあるかどうかの判定を返す /
  * Check to see if the shop will be carrying too many objects  -RAK-
  * @param o_ptr 店舗に置きたいオブジェクト構造体の参照ポインタ
@@ -235,26 +181,6 @@ int store_check_num(object_type *o_ptr)
 }
 
 /*!
- * @brief 店舗の割引対象外にするかどうかを判定 /
- * Eliminate need to bargain if player has haggled well in the past
- * @param minprice アイテムの最低販売価格
- * @return 割引を禁止するならTRUEを返す。
- */
-bool noneedtobargain(PRICE minprice)
-{
-    PRICE good = st_ptr->good_buy;
-    PRICE bad = st_ptr->bad_buy;
-    if (minprice < 10L)
-        return TRUE;
-    if (good == MAX_SHORT)
-        return TRUE;
-    if (good > ((3 * bad) + (5 + (minprice / 50))))
-        return TRUE;
-
-    return FALSE;
-}
-
-/*!
  * @brief 店舗からアイテムを選択する /
  * Get the ID of a store item and return its value     -RAK-
  * @param com_val 選択IDを返す参照ポインタ
index 384cdee..52c6a1d 100644 (file)
@@ -21,8 +21,6 @@ extern s16b inner_town_num;
 extern int cur_store_feat;
 extern bool allow_inc;
 
-PRICE price_item(player_type *player_ptr, object_type *o_ptr, int greed, bool flip);
-bool noneedtobargain(PRICE minprice);
 void store_shuffle(player_type *player_ptr, int which);
 void store_maintenance(player_type *player_ptr, int town_num, int store_num);
 void store_init(int town_num, int store_num);
index 3f3a6dd..834ffe2 100644 (file)
@@ -8,6 +8,7 @@
 #include "object/object-info.h"
 #include "object/object-kind.h"
 #include "player/race-info-table.h"
+#include "store/pricing.h"
 #include "store/store-util.h"
 #include "store/store.h" // todo 相互依存している、こっちは残す?.
 #include "system/object-type-definition.h"