From d8961189cb1fbe7e98ba9a5a6c20e3a96ac64b81 Mon Sep 17 00:00:00 2001
From: Hourier <66951241+Hourier@users.noreply.github.com>
Date: Sat, 12 Feb 2022 12:04:05 +0900
Subject: [PATCH] [Refactor] #2118 Separated apply-magic-lite.cpp/h from
apply-magic-others.cpp/h
---
Hengband/Hengband/Hengband.vcxproj | 2 +
Hengband/Hengband/Hengband.vcxproj.filters | 9 ++-
src/Makefile.am | 1 +
src/object-enchant/apply-magic.cpp | 4 ++
src/object-enchant/others/apply-magic-lite.cpp | 81 ++++++++++++++++++++++++
src/object-enchant/others/apply-magic-lite.h | 24 +++++++
src/object-enchant/others/apply-magic-others.cpp | 51 ---------------
7 files changed, 118 insertions(+), 54 deletions(-)
create mode 100644 src/object-enchant/others/apply-magic-lite.cpp
create mode 100644 src/object-enchant/others/apply-magic-lite.h
diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj
index 8956953c3..c93b446c4 100644
--- a/Hengband/Hengband/Hengband.vcxproj
+++ b/Hengband/Hengband/Hengband.vcxproj
@@ -273,6 +273,7 @@
+
@@ -938,6 +939,7 @@
+
diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters
index 6ab010c60..f38c1b83b 100644
--- a/Hengband/Hengband/Hengband.vcxproj.filters
+++ b/Hengband/Hengband/Hengband.vcxproj.filters
@@ -2373,6 +2373,9 @@
object-enchant\others
+
+ object-enchant\others
+
@@ -5100,9 +5103,6 @@
monster-race
-
- object-enchant
-
object-enchant\protector
@@ -5157,6 +5157,9 @@
monster-race
+
+ object-enchant\others
+
diff --git a/src/Makefile.am b/src/Makefile.am
index b3396ff59..4297e8c29 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -597,6 +597,7 @@ hengband_SOURCES = \
object-enchant/vorpal-weapon.cpp object-enchant/vorpal-weapon.h \
\
object-enchant/others/apply-magic-amulet.cpp object-enchant/others/apply-magic-amulet.h \
+ object-enchant/others/apply-magic-lite.cpp object-enchant/others/apply-magic-lite.h \
object-enchant/others/apply-magic-ring.cpp object-enchant/others/apply-magic-ring.h \
object-enchant/others/apply-magic-others.cpp object-enchant/others/apply-magic-others.h \
\
diff --git a/src/object-enchant/apply-magic.cpp b/src/object-enchant/apply-magic.cpp
index 5b43b0c83..a4f6a2f91 100644
--- a/src/object-enchant/apply-magic.cpp
+++ b/src/object-enchant/apply-magic.cpp
@@ -14,6 +14,7 @@
#include "object-enchant/object-curse.h"
#include "object-enchant/object-ego.h"
#include "object-enchant/others/apply-magic-amulet.h"
+#include "object-enchant/others/apply-magic-lite.h"
#include "object-enchant/others/apply-magic-others.h"
#include "object-enchant/others/apply-magic-ring.h"
#include "object-enchant/protector/apply-magic-armor.h"
@@ -173,6 +174,9 @@ void apply_magic_to_object(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH lev,
case ItemKindType::AMULET:
AmuletEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
break;
+ case ItemKindType::LITE:
+ LiteEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
+ break;
default:
apply_magic_others(player_ptr, o_ptr, power);
break;
diff --git a/src/object-enchant/others/apply-magic-lite.cpp b/src/object-enchant/others/apply-magic-lite.cpp
new file mode 100644
index 000000000..48b68960d
--- /dev/null
+++ b/src/object-enchant/others/apply-magic-lite.cpp
@@ -0,0 +1,81 @@
+#include "object-enchant/others/apply-magic-lite.h"
+#include "artifact/random-art-generator.h"
+#include "inventory/inventory-slot-types.h"
+#include "object-enchant/object-ego.h"
+#include "sv-definition/sv-lite-types.h"
+#include "system/object-type-definition.h"
+#include "system/player-type-definition.h"
+
+LiteEnchanter::LiteEnchanter(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH level, int power)
+ : player_ptr(player_ptr)
+ , o_ptr(o_ptr)
+ , level(level)
+ , power(power)
+{
+ if (o_ptr->sval == SV_LITE_TORCH) {
+ if (o_ptr->pval > 0)
+ o_ptr->xtra4 = randint1(o_ptr->pval);
+ o_ptr->pval = 0;
+ }
+
+ if (o_ptr->sval == SV_LITE_LANTERN) {
+ if (o_ptr->pval > 0)
+ o_ptr->xtra4 = randint1(o_ptr->pval);
+ o_ptr->pval = 0;
+ }
+}
+
+void LiteEnchanter::apply_magic()
+{
+ if (this->power > 2) {
+ become_random_artifact(this->player_ptr, this->o_ptr, false);
+ } else if ((this->power == 2) || ((this->power == 1) && one_in_(3))) {
+ while (!this->o_ptr->name2) {
+ while (true) {
+ bool okay_flag = true;
+
+ this->o_ptr->name2 = get_random_ego(INVEN_LITE, true);
+
+ switch (this->o_ptr->name2) {
+ case EGO_LITE_LONG:
+ if (this->o_ptr->sval == SV_LITE_FEANOR)
+ okay_flag = false;
+ }
+
+ if (okay_flag)
+ break;
+ }
+ }
+ } else if (this->power == -2) {
+ this->o_ptr->name2 = get_random_ego(INVEN_LITE, false);
+ switch (this->o_ptr->name2) {
+ case EGO_LITE_DARKNESS:
+ this->o_ptr->xtra4 = 0;
+
+ if (this->o_ptr->sval == SV_LITE_TORCH) {
+ this->o_ptr->art_flags.set(TR_LITE_M1);
+ } else if (this->o_ptr->sval == SV_LITE_LANTERN) {
+ this->o_ptr->art_flags.set(TR_LITE_M2);
+ } else if (this->o_ptr->sval == SV_LITE_FEANOR) {
+ this->o_ptr->art_flags.set(TR_LITE_M3);
+ }
+ break;
+ }
+ }
+}
+
+void LiteEnchanter::enchant()
+{
+}
+
+void LiteEnchanter::give_ego_index()
+{
+}
+
+void LiteEnchanter::give_high_ego_index()
+{
+}
+
+void LiteEnchanter::give_cursed()
+{
+}
diff --git a/src/object-enchant/others/apply-magic-lite.h b/src/object-enchant/others/apply-magic-lite.h
new file mode 100644
index 000000000..11267caf7
--- /dev/null
+++ b/src/object-enchant/others/apply-magic-lite.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "object-enchant/enchanter-base.h"
+#include "system/angband.h"
+
+class ObjectType;
+class PlayerType;
+class LiteEnchanter : EnchanterBase {
+public:
+ LiteEnchanter(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH level, int power);
+ void apply_magic() override;
+
+protected:
+ void enchant() override;
+ void give_ego_index() override;
+ void give_high_ego_index() override;
+ void give_cursed() override;
+
+private:
+ PlayerType *player_ptr;
+ ObjectType *o_ptr;
+ DEPTH level;
+ int power;
+};
diff --git a/src/object-enchant/others/apply-magic-others.cpp b/src/object-enchant/others/apply-magic-others.cpp
index ff633b64d..5013a9da3 100644
--- a/src/object-enchant/others/apply-magic-others.cpp
+++ b/src/object-enchant/others/apply-magic-others.cpp
@@ -51,57 +51,6 @@ void apply_magic_others(PlayerType *player_ptr, ObjectType *o_ptr, int power)
o_ptr->pval = 0;
break;
}
- case ItemKindType::LITE: {
- if (o_ptr->sval == SV_LITE_TORCH) {
- if (o_ptr->pval > 0)
- o_ptr->xtra4 = randint1(o_ptr->pval);
- o_ptr->pval = 0;
- }
-
- if (o_ptr->sval == SV_LITE_LANTERN) {
- if (o_ptr->pval > 0)
- o_ptr->xtra4 = randint1(o_ptr->pval);
- o_ptr->pval = 0;
- }
-
- if (power > 2) {
- become_random_artifact(player_ptr, o_ptr, false);
- } else if ((power == 2) || ((power == 1) && one_in_(3))) {
- while (!o_ptr->name2) {
- while (true) {
- bool okay_flag = true;
-
- o_ptr->name2 = get_random_ego(INVEN_LITE, true);
-
- switch (o_ptr->name2) {
- case EGO_LITE_LONG:
- if (o_ptr->sval == SV_LITE_FEANOR)
- okay_flag = false;
- }
-
- if (okay_flag)
- break;
- }
- }
- } else if (power == -2) {
- o_ptr->name2 = get_random_ego(INVEN_LITE, false);
- switch (o_ptr->name2) {
- case EGO_LITE_DARKNESS:
- o_ptr->xtra4 = 0;
-
- if (o_ptr->sval == SV_LITE_TORCH) {
- o_ptr->art_flags.set(TR_LITE_M1);
- } else if (o_ptr->sval == SV_LITE_LANTERN) {
- o_ptr->art_flags.set(TR_LITE_M2);
- } else if (o_ptr->sval == SV_LITE_FEANOR) {
- o_ptr->art_flags.set(TR_LITE_M3);
- }
- break;
- }
- }
-
- break;
- }
case ItemKindType::WAND:
case ItemKindType::STAFF: {
/* The wand or staff gets a number of initial charges equal
--
2.11.0