• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: Commit

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revision2a940a1af0dd690ce905a9f3146dc3c91e7b1817 (tree)
Time2019-06-18 23:26:28
Authordeskull <deskull@user...>
Commiterdeskull

Log Message

[Refactor] #37353 enchant() と enchant_spell() を spells-object.c/h へ移動.

Change Summary

Incremental Difference

--- a/src/bldg.c
+++ b/src/bldg.c
@@ -43,6 +43,7 @@
4343 #include "cmd-spell.h"
4444 #include "rumor.h"
4545 #include "spells.h"
46+#include "spells-object.h"
4647 #include "spells-status.h"
4748 #include "realm-hex.h"
4849 #include "dungeon-file.h"
--- a/src/spells-object.c
+++ b/src/spells-object.c
@@ -31,6 +31,22 @@ typedef struct
3131 byte flag;
3232 } amuse_type;
3333
34+
35+/*!
36+ * @brief 装備強化処理の失敗率定数(千分率) /
37+ * Used by the "enchant" function (chance of failure)
38+ * (modified for Zangband, we need better stuff there...) -- TY
39+ * @return なし
40+ */
41+static int enchant_table[16] =
42+{
43+ 0, 10, 50, 100, 200,
44+ 300, 400, 500, 650, 800,
45+ 950, 987, 993, 995, 998,
46+ 1000
47+};
48+
49+
3450 /*
3551 * Scatter some "amusing" objects near the player
3652 */
@@ -1124,3 +1140,194 @@ bool pulish_shield(void)
11241140
11251141 return FALSE;
11261142 }
1143+
1144+/*!
1145+ * @brief 呪いの打ち破り処理 /
1146+ * Break the curse of an item
1147+ * @param o_ptr 呪い装備情報の参照ポインタ
1148+ * @return なし
1149+ */
1150+static void break_curse(object_type *o_ptr)
1151+{
1152+ if (object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25))
1153+ {
1154+ msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
1155+
1156+ o_ptr->curse_flags = 0L;
1157+ o_ptr->ident |= (IDENT_SENSE);
1158+ o_ptr->feeling = FEEL_NONE;
1159+ }
1160+}
1161+
1162+/*!
1163+ * @brief 装備修正強化処理 /
1164+ * Enchants a plus onto an item. -RAK-
1165+ * @param o_ptr 強化するアイテムの参照ポインタ
1166+ * @param n 強化基本量
1167+ * @param eflag 強化オプション(命中/ダメージ/AC)
1168+ * @return 強化に成功した場合TRUEを返す
1169+ * @details
1170+ * <pre>
1171+ * Revamped! Now takes item pointer, number of times to try enchanting,
1172+ * and a flag of what to try enchanting. Artifacts resist enchantment
1173+ * some of the time, and successful enchantment to at least +0 might
1174+ * break a curse on the item. -CFT-
1175+ *
1176+ * Note that an item can technically be enchanted all the way to +15 if
1177+ * you wait a very, very, long time. Going from +9 to +10 only works
1178+ * about 5% of the time, and from +10 to +11 only about 1% of the time.
1179+ *
1180+ * Note that this function can now be used on "piles" of items, and
1181+ * the larger the pile, the lower the chance of success.
1182+ * </pre>
1183+ */
1184+bool enchant(object_type *o_ptr, int n, int eflag)
1185+{
1186+ int i, chance, prob;
1187+ bool res = FALSE;
1188+ bool a = object_is_artifact(o_ptr);
1189+ bool force = (eflag & ENCH_FORCE);
1190+
1191+ /* Large piles resist enchantment */
1192+ prob = o_ptr->number * 100;
1193+
1194+ /* Missiles are easy to enchant */
1195+ if ((o_ptr->tval == TV_BOLT) ||
1196+ (o_ptr->tval == TV_ARROW) ||
1197+ (o_ptr->tval == TV_SHOT))
1198+ {
1199+ prob = prob / 20;
1200+ }
1201+
1202+ /* Try "n" times */
1203+ for (i = 0; i < n; i++)
1204+ {
1205+ /* Hack -- Roll for pile resistance */
1206+ if (!force && randint0(prob) >= 100) continue;
1207+
1208+ /* Enchant to hit */
1209+ if (eflag & ENCH_TOHIT)
1210+ {
1211+ if (o_ptr->to_h < 0) chance = 0;
1212+ else if (o_ptr->to_h > 15) chance = 1000;
1213+ else chance = enchant_table[o_ptr->to_h];
1214+
1215+ if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1216+ {
1217+ o_ptr->to_h++;
1218+ res = TRUE;
1219+
1220+ /* only when you get it above -1 -CFT */
1221+ if (o_ptr->to_h >= 0)
1222+ break_curse(o_ptr);
1223+ }
1224+ }
1225+
1226+ /* Enchant to damage */
1227+ if (eflag & ENCH_TODAM)
1228+ {
1229+ if (o_ptr->to_d < 0) chance = 0;
1230+ else if (o_ptr->to_d > 15) chance = 1000;
1231+ else chance = enchant_table[o_ptr->to_d];
1232+
1233+ if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1234+ {
1235+ o_ptr->to_d++;
1236+ res = TRUE;
1237+
1238+ /* only when you get it above -1 -CFT */
1239+ if (o_ptr->to_d >= 0)
1240+ break_curse(o_ptr);
1241+ }
1242+ }
1243+
1244+ /* Enchant to armor class */
1245+ if (eflag & ENCH_TOAC)
1246+ {
1247+ if (o_ptr->to_a < 0) chance = 0;
1248+ else if (o_ptr->to_a > 15) chance = 1000;
1249+ else chance = enchant_table[o_ptr->to_a];
1250+
1251+ if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1252+ {
1253+ o_ptr->to_a++;
1254+ res = TRUE;
1255+
1256+ /* only when you get it above -1 -CFT */
1257+ if (o_ptr->to_a >= 0)
1258+ break_curse(o_ptr);
1259+ }
1260+ }
1261+ }
1262+
1263+ /* Failure */
1264+ if (!res) return (FALSE);
1265+ p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
1266+ p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1267+
1268+ calc_android_exp();
1269+
1270+ /* Success */
1271+ return (TRUE);
1272+}
1273+
1274+
1275+/*!
1276+ * @brief 装備修正強化処理のメインルーチン /
1277+ * Enchant an item (in the p_ptr->inventory_list or on the floor)
1278+ * @param num_hit 命中修正量
1279+ * @param num_dam ダメージ修正量
1280+ * @param num_ac AC修正量
1281+ * @return 強化に成功した場合TRUEを返す
1282+ * @details
1283+ * Note that "num_ac" requires armour, else weapon
1284+ * Returns TRUE if attempted, FALSE if cancelled
1285+ */
1286+bool enchant_spell(HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
1287+{
1288+ OBJECT_IDX item;
1289+ bool okay = FALSE;
1290+ object_type *o_ptr;
1291+ GAME_TEXT o_name[MAX_NLEN];
1292+ concptr q, s;
1293+
1294+ /* Assume enchant weapon */
1295+ item_tester_hook = object_allow_enchant_weapon;
1296+
1297+ /* Enchant armor if requested */
1298+ if (num_ac) item_tester_hook = object_is_armour;
1299+
1300+ q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
1301+ s = _("強化できるアイテムがない。", "You have nothing to enchant.");
1302+
1303+ o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
1304+ if (!o_ptr) return (FALSE);
1305+
1306+ object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1307+#ifdef JP
1308+ msg_format("%s は明るく輝いた!", o_name);
1309+#else
1310+ msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
1311+#endif
1312+
1313+ /* Enchant */
1314+ if (enchant(o_ptr, num_hit, ENCH_TOHIT)) okay = TRUE;
1315+ if (enchant(o_ptr, num_dam, ENCH_TODAM)) okay = TRUE;
1316+ if (enchant(o_ptr, num_ac, ENCH_TOAC)) okay = TRUE;
1317+
1318+ /* Failure */
1319+ if (!okay)
1320+ {
1321+ if (flush_failure) flush();
1322+ msg_print(_("強化に失敗した。", "The enchantment failed."));
1323+ if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
1324+ }
1325+ else
1326+ chg_virtue(V_ENCHANT, 1);
1327+
1328+ calc_android_exp();
1329+
1330+ /* Something happened */
1331+ return (TRUE);
1332+}
1333+
--- a/src/spells-object.h
+++ b/src/spells-object.h
@@ -16,3 +16,12 @@ extern void phlogiston(void);
1616 extern bool bless_weapon(void);
1717 extern bool pulish_shield(void);
1818
19+/*
20+ * Bit flags for the "enchant()" function
21+ */
22+#define ENCH_TOHIT 0x01 /*!< 装備強化処理: 命中強化 / Enchant to hit */
23+#define ENCH_TODAM 0x02 /*!< 装備強化処理: ダメージ強化 / Enchant to damage */
24+#define ENCH_TOAC 0x04 /*!< 装備強化処理: AC強化 / Enchant to AC */
25+#define ENCH_FORCE 0x08 /*!< 装備強化処理: 無条件に成功させる / Force enchantment */
26+extern bool enchant(object_type *o_ptr, int n, int eflag);
27+extern bool enchant_spell(HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac);
--- a/src/spells.h
+++ b/src/spells.h
@@ -304,16 +304,6 @@ extern int remove_curse(void);
304304 extern int remove_all_curse(void);
305305 extern bool alchemy(void);
306306
307-/*
308- * Bit flags for the "enchant()" function
309- */
310-#define ENCH_TOHIT 0x01 /*!< 装備強化処理: 命中強化 / Enchant to hit */
311-#define ENCH_TODAM 0x02 /*!< 装備強化処理: ダメージ強化 / Enchant to damage */
312-#define ENCH_TOAC 0x04 /*!< 装備強化処理: AC強化 / Enchant to AC */
313-#define ENCH_FORCE 0x08 /*!< 装備強化処理: 無条件に成功させる / Force enchantment */
314-extern bool enchant(object_type *o_ptr, int n, int eflag);
315-extern bool enchant_spell(HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac);
316-
317307 extern bool artifact_scroll(void);
318308 extern bool ident_spell(bool only_equip);
319309 extern bool mundane_spell(bool only_equip);
--- a/src/spells3.c
+++ b/src/spells3.c
@@ -57,6 +57,8 @@
5757 #include "autopick.h"
5858 #include "targeting.h"
5959
60+#include "spells-object.h" // temp for brand_weapon()
61+
6062
6163 /*! テレポート先探索の試行数 / Maximum number of tries for teleporting */
6264 #define MAX_TRIES 100
@@ -1534,22 +1536,6 @@ void identify_pack(void)
15341536 }
15351537 }
15361538
1537-
1538-/*!
1539- * @brief 装備強化処理の失敗率定数(千分率) /
1540- * Used by the "enchant" function (chance of failure)
1541- * (modified for Zangband, we need better stuff there...) -- TY
1542- * @return なし
1543- */
1544-static int enchant_table[16] =
1545-{
1546- 0, 10, 50, 100, 200,
1547- 300, 400, 500, 650, 800,
1548- 950, 987, 993, 995, 998,
1549- 1000
1550-};
1551-
1552-
15531539 /*!
15541540 * @brief 装備の解呪処理 /
15551541 * Removes curses from items in p_ptr->inventory_list
@@ -1730,198 +1716,6 @@ bool alchemy(void)
17301716
17311717
17321718 /*!
1733- * @brief 呪いの打ち破り処理 /
1734- * Break the curse of an item
1735- * @param o_ptr 呪い装備情報の参照ポインタ
1736- * @return なし
1737- */
1738-static void break_curse(object_type *o_ptr)
1739-{
1740- if (object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25))
1741- {
1742- msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
1743-
1744- o_ptr->curse_flags = 0L;
1745- o_ptr->ident |= (IDENT_SENSE);
1746- o_ptr->feeling = FEEL_NONE;
1747- }
1748-}
1749-
1750-
1751-/*!
1752- * @brief 装備修正強化処理 /
1753- * Enchants a plus onto an item. -RAK-
1754- * @param o_ptr 強化するアイテムの参照ポインタ
1755- * @param n 強化基本量
1756- * @param eflag 強化オプション(命中/ダメージ/AC)
1757- * @return 強化に成功した場合TRUEを返す
1758- * @details
1759- * <pre>
1760- * Revamped! Now takes item pointer, number of times to try enchanting,
1761- * and a flag of what to try enchanting. Artifacts resist enchantment
1762- * some of the time, and successful enchantment to at least +0 might
1763- * break a curse on the item. -CFT-
1764- *
1765- * Note that an item can technically be enchanted all the way to +15 if
1766- * you wait a very, very, long time. Going from +9 to +10 only works
1767- * about 5% of the time, and from +10 to +11 only about 1% of the time.
1768- *
1769- * Note that this function can now be used on "piles" of items, and
1770- * the larger the pile, the lower the chance of success.
1771- * </pre>
1772- */
1773-bool enchant(object_type *o_ptr, int n, int eflag)
1774-{
1775- int i, chance, prob;
1776- bool res = FALSE;
1777- bool a = object_is_artifact(o_ptr);
1778- bool force = (eflag & ENCH_FORCE);
1779-
1780- /* Large piles resist enchantment */
1781- prob = o_ptr->number * 100;
1782-
1783- /* Missiles are easy to enchant */
1784- if ((o_ptr->tval == TV_BOLT) ||
1785- (o_ptr->tval == TV_ARROW) ||
1786- (o_ptr->tval == TV_SHOT))
1787- {
1788- prob = prob / 20;
1789- }
1790-
1791- /* Try "n" times */
1792- for (i = 0; i < n; i++)
1793- {
1794- /* Hack -- Roll for pile resistance */
1795- if (!force && randint0(prob) >= 100) continue;
1796-
1797- /* Enchant to hit */
1798- if (eflag & ENCH_TOHIT)
1799- {
1800- if (o_ptr->to_h < 0) chance = 0;
1801- else if (o_ptr->to_h > 15) chance = 1000;
1802- else chance = enchant_table[o_ptr->to_h];
1803-
1804- if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1805- {
1806- o_ptr->to_h++;
1807- res = TRUE;
1808-
1809- /* only when you get it above -1 -CFT */
1810- if (o_ptr->to_h >= 0)
1811- break_curse(o_ptr);
1812- }
1813- }
1814-
1815- /* Enchant to damage */
1816- if (eflag & ENCH_TODAM)
1817- {
1818- if (o_ptr->to_d < 0) chance = 0;
1819- else if (o_ptr->to_d > 15) chance = 1000;
1820- else chance = enchant_table[o_ptr->to_d];
1821-
1822- if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1823- {
1824- o_ptr->to_d++;
1825- res = TRUE;
1826-
1827- /* only when you get it above -1 -CFT */
1828- if (o_ptr->to_d >= 0)
1829- break_curse(o_ptr);
1830- }
1831- }
1832-
1833- /* Enchant to armor class */
1834- if (eflag & ENCH_TOAC)
1835- {
1836- if (o_ptr->to_a < 0) chance = 0;
1837- else if (o_ptr->to_a > 15) chance = 1000;
1838- else chance = enchant_table[o_ptr->to_a];
1839-
1840- if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
1841- {
1842- o_ptr->to_a++;
1843- res = TRUE;
1844-
1845- /* only when you get it above -1 -CFT */
1846- if (o_ptr->to_a >= 0)
1847- break_curse(o_ptr);
1848- }
1849- }
1850- }
1851-
1852- /* Failure */
1853- if (!res) return (FALSE);
1854- p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
1855- p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1856-
1857- calc_android_exp();
1858-
1859- /* Success */
1860- return (TRUE);
1861-}
1862-
1863-
1864-/*!
1865- * @brief 装備修正強化処理のメインルーチン /
1866- * Enchant an item (in the p_ptr->inventory_list or on the floor)
1867- * @param num_hit 命中修正量
1868- * @param num_dam ダメージ修正量
1869- * @param num_ac AC修正量
1870- * @return 強化に成功した場合TRUEを返す
1871- * @details
1872- * Note that "num_ac" requires armour, else weapon
1873- * Returns TRUE if attempted, FALSE if cancelled
1874- */
1875-bool enchant_spell(HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
1876-{
1877- OBJECT_IDX item;
1878- bool okay = FALSE;
1879- object_type *o_ptr;
1880- GAME_TEXT o_name[MAX_NLEN];
1881- concptr q, s;
1882-
1883- /* Assume enchant weapon */
1884- item_tester_hook = object_allow_enchant_weapon;
1885-
1886- /* Enchant armor if requested */
1887- if (num_ac) item_tester_hook = object_is_armour;
1888-
1889- q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
1890- s = _("強化できるアイテムがない。", "You have nothing to enchant.");
1891-
1892- o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
1893- if (!o_ptr) return (FALSE);
1894-
1895- object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1896-#ifdef JP
1897- msg_format("%s は明るく輝いた!", o_name);
1898-#else
1899- msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
1900-#endif
1901-
1902- /* Enchant */
1903- if (enchant(o_ptr, num_hit, ENCH_TOHIT)) okay = TRUE;
1904- if (enchant(o_ptr, num_dam, ENCH_TODAM)) okay = TRUE;
1905- if (enchant(o_ptr, num_ac, ENCH_TOAC)) okay = TRUE;
1906-
1907- /* Failure */
1908- if (!okay)
1909- {
1910- if (flush_failure) flush();
1911- msg_print(_("強化に失敗した。", "The enchantment failed."));
1912- if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
1913- }
1914- else
1915- chg_virtue(V_ENCHANT, 1);
1916-
1917- calc_android_exp();
1918-
1919- /* Something happened */
1920- return (TRUE);
1921-}
1922-
1923-
1924-/*!
19251719 * @brief アーティファクト生成の巻物処理 /
19261720 * @return 生成が実際に試みられたらTRUEを返す
19271721 */
Show on old repository browser