summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:14 +0200
committerBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:14 +0200
commit2ec260320655504b88f8042d4b24e3e7910846a7 (patch)
tree35caeac1f630c5f452d3478deda76a60f406d673 /src
parent76b3632d13bbf57c6354bc10f67ea849f1d47279 (diff)
Split out spellbinder fields from player_type
Diffstat (limited to 'src')
-rw-r--r--src/loadsave.cc6
-rw-r--r--src/player_type.hpp5
-rw-r--r--src/spellbinder.hpp25
-rw-r--r--src/spells1.cc50
-rw-r--r--src/spells3.cc28
5 files changed, 73 insertions, 41 deletions
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 066e6a6e..ea9828d9 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -568,11 +568,11 @@ static bool_ do_extra(ls_flag_t flag)
/* Save/load spellbinder */
- do_byte(&p_ptr->spellbinder_num, flag);
- do_byte(&p_ptr->spellbinder_trigger, flag);
+ do_byte(&p_ptr->spellbinder.num, flag);
+ do_byte(&p_ptr->spellbinder.trigger, flag);
for (std::size_t i = 0; i < 4; i++)
{
- do_u32b(&p_ptr->spellbinder[i], flag);
+ do_u32b(&p_ptr->spellbinder.spells[i], flag);
}
// Quests
diff --git a/src/player_type.hpp b/src/player_type.hpp
index 0e89605c..fdaab57a 100644
--- a/src/player_type.hpp
+++ b/src/player_type.hpp
@@ -6,6 +6,7 @@
#include "inventory.hpp"
#include "object_type.hpp"
#include "powers.hpp"
+#include "spellbinder.hpp"
#include <array>
@@ -338,9 +339,7 @@ struct player_type
u32b maintain_sum = 0; /* Do we have partial summons */
- byte spellbinder_num = 0; /* Number of spells bound */
- u32b spellbinder[4] = { 0 }; /* Spell bounds */
- byte spellbinder_trigger = 0; /* Spellbinder trigger condition */
+ struct spellbinder spellbinder;
cptr mimic_name = nullptr;
diff --git a/src/spellbinder.hpp b/src/spellbinder.hpp
new file mode 100644
index 00000000..1f5cdd99
--- /dev/null
+++ b/src/spellbinder.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "h-basic.h"
+
+/**
+ * Spellbinder state
+ */
+struct spellbinder {
+
+ /**
+ * Number of bound spells.
+ */
+ byte num = 0;
+
+ /**
+ * Bound spells.
+ */
+ u32b spells[4] = { 0 };
+
+ /**
+ * Trigger condition.
+ */
+ byte trigger = 0;
+
+};
diff --git a/src/spells1.cc b/src/spells1.cc
index 58cf1fd7..9ebec08e 100644
--- a/src/spells1.cc
+++ b/src/spells1.cc
@@ -1203,16 +1203,17 @@ static u16b bolt_pict(int y, int x, int ny, int nx, int typ)
*/
void spellbinder_trigger()
{
- int i;
+ auto spellbinder = &p_ptr->spellbinder;
cmsg_print(TERM_L_GREEN, "The spellbinder is triggered!");
- for (i = 0; i < p_ptr->spellbinder_num; i++)
+ for (int i = 0; i < spellbinder->num; i++)
{
- msg_format("Triggering spell %s.", spell_type_name(spell_at(p_ptr->spellbinder[i])));
- lua_cast_school_spell(p_ptr->spellbinder[i], TRUE);
+ msg_format("Triggering spell %s.", spell_type_name(spell_at(spellbinder->spells[i])));
+ lua_cast_school_spell(spellbinder->spells[i], TRUE);
}
- p_ptr->spellbinder_num = 0;
- p_ptr->spellbinder_trigger = 0;
+
+ spellbinder->num = 0;
+ spellbinder->trigger = 0;
}
@@ -1403,23 +1404,28 @@ void take_hit(int damage, cptr hit_from)
percent = p_ptr->chp * 100 / p_ptr->mhp;
/* Check the spellbinder trigger */
- if (p_ptr->spellbinder_trigger == SPELLBINDER_HP75)
- {
- /* Trigger ?! */
- if (percent <= 75)
- spellbinder_trigger();
- }
- else if (p_ptr->spellbinder_trigger == SPELLBINDER_HP50)
+ switch (p_ptr->spellbinder.trigger)
{
- /* Trigger ?! */
- if (percent <= 50)
- spellbinder_trigger();
- }
- else if (p_ptr->spellbinder_trigger == SPELLBINDER_HP25)
- {
- /* Trigger ?! */
- if (percent <= 25)
- spellbinder_trigger();
+ case SPELLBINDER_HP75:
+ if (percent <= 75)
+ {
+ spellbinder_trigger();
+ }
+ break;
+
+ case SPELLBINDER_HP50:
+ if (percent <= 50)
+ {
+ spellbinder_trigger();
+ }
+ break;
+
+ case SPELLBINDER_HP25:
+ if (percent <= 25)
+ {
+ spellbinder_trigger();
+ }
+ break;
}
/* Melkor acn summon to help you */
diff --git a/src/spells3.cc b/src/spells3.cc
index fad11049..69267c7d 100644
--- a/src/spells3.cc
+++ b/src/spells3.cc
@@ -2324,7 +2324,9 @@ static int get_spellbinder_max()
casting_result meta_spellbinder()
{
- if (p_ptr->spellbinder_num != 0)
+ auto spellbinder = &p_ptr->spellbinder;
+
+ if (spellbinder->num != 0)
{
struct trigger {
int idx;
@@ -2339,11 +2341,11 @@ casting_result meta_spellbinder()
int trigger_idx = -1;
int i;
- assert(p_ptr->spellbinder_trigger >= 0);
+ assert(spellbinder->trigger >= 0);
for (trigger_idx = 0; triggers[trigger_idx].idx >= 0; trigger_idx++)
{
- if (triggers[trigger_idx].idx == p_ptr->spellbinder_trigger)
+ if (triggers[trigger_idx].idx == spellbinder->trigger)
{
break;
}
@@ -2352,9 +2354,9 @@ casting_result meta_spellbinder()
msg_print("The spellbinder is already active.");
msg_format("It will trigger at %s.", triggers[trigger_idx].desc);
msg_print("With the spells: ");
- for (i = 0; i < p_ptr->spellbinder_num; i++)
+ for (i = 0; i < spellbinder->num; i++)
{
- msg_print(spell_type_name(spell_at(p_ptr->spellbinder[i])));
+ msg_print(spell_type_name(spell_at(spellbinder->spells[i])));
}
/* Doesn't cost anything */
@@ -2373,28 +2375,28 @@ casting_result meta_spellbinder()
switch (c)
{
case 'a':
- p_ptr->spellbinder_trigger = SPELLBINDER_HP75;
+ spellbinder->trigger = SPELLBINDER_HP75;
break;
case 'b':
- p_ptr->spellbinder_trigger = SPELLBINDER_HP50;
+ spellbinder->trigger = SPELLBINDER_HP50;
break;
case 'c':
- p_ptr->spellbinder_trigger = SPELLBINDER_HP25;
+ spellbinder->trigger = SPELLBINDER_HP25;
break;
default:
return NO_CAST;
}
- p_ptr->spellbinder_num = get_spellbinder_max();
- i = p_ptr->spellbinder_num;
+ spellbinder->num = get_spellbinder_max();
+ i = spellbinder->num;
while (i > 0)
{
s32b s = get_school_spell("bind", 0);
if (s == -1)
{
- p_ptr->spellbinder_trigger = 0;
- p_ptr->spellbinder_num = 0;
+ spellbinder->trigger = 0;
+ spellbinder->num = 0;
return CAST_OBVIOUS;
} else {
if (spell_type_skill_level(spell_at(s)) > 7 + get_level_s(SPELLBINDER, 35))
@@ -2404,7 +2406,7 @@ casting_result meta_spellbinder()
}
}
- p_ptr->spellbinder[i] = s;
+ spellbinder->spells[i] = s;
i = i - 1;
}