summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd5.cc1
-rw-r--r--src/cmd6.cc1
-rw-r--r--src/dungeon.cc1
-rw-r--r--src/externs.h7
-rw-r--r--src/lua_bind.cc1
-rw-r--r--src/object1.cc1
-rw-r--r--src/object2.cc29
-rw-r--r--src/script.cc1
-rw-r--r--src/spells1.cc1
-rw-r--r--src/spells3.cc1
-rw-r--r--src/spells4.cc1
-rw-r--r--src/spells5.cc27
-rw-r--r--src/spells5.hpp8
-rw-r--r--src/store.cc1
-rw-r--r--src/variable.cc2
15 files changed, 47 insertions, 36 deletions
diff --git a/src/cmd5.cc b/src/cmd5.cc
index 0b0da5a4..e03793be 100644
--- a/src/cmd5.cc
+++ b/src/cmd5.cc
@@ -17,6 +17,7 @@
#include "spell_type.hpp"
#include "quark.h"
+#include "spells5.hpp"
/* Maximum number of tries for teleporting */
#define MAX_TRIES 300
diff --git a/src/cmd6.cc b/src/cmd6.cc
index 64ce48d2..74b192f6 100644
--- a/src/cmd6.cc
+++ b/src/cmd6.cc
@@ -13,6 +13,7 @@
#include "angband.h"
#include "lua_bind.hpp"
#include "spell_type.hpp"
+#include "spells5.hpp"
#include "hooks.h"
#include <cassert>
diff --git a/src/dungeon.cc b/src/dungeon.cc
index 22ce130b..20b5684f 100644
--- a/src/dungeon.cc
+++ b/src/dungeon.cc
@@ -18,6 +18,7 @@
#include "quark.h"
#include "hooks.h"
#include "spell_type.hpp"
+#include "spells5.hpp"
#define TY_CURSE_CHANCE 100
#define DG_CURSE_CHANCE 50
diff --git a/src/externs.h b/src/externs.h
index c2d513d1..ee7bd9f8 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -509,8 +509,6 @@ extern hist_type *bg;
extern int max_bg_idx;
extern s32b extra_savefile_parts;
extern bool_ player_char_health;
-extern s16b school_spells_count;
-extern struct spell_type *school_spells[SCHOOL_SPELLS_MAX];
extern s16b schools_count;
extern school_type schools[SCHOOLS_MAX];
extern int project_time;
@@ -1361,11 +1359,6 @@ int spell_x(int sval, int pval, int i);
bool_ school_book_contains_spell(int sval, s32b spell_idx);
void lua_cast_school_spell(s32b spell_idx, bool_ no_cost);
-/* spells5.c */
-void school_spells_init();
-struct spell_type *spell_at(s32b index);
-s16b get_random_spell(s16b random_type, int lev);
-
/* spells6.c */
void schools_init();
diff --git a/src/lua_bind.cc b/src/lua_bind.cc
index 1bd22600..e0c6b05a 100644
--- a/src/lua_bind.cc
+++ b/src/lua_bind.cc
@@ -17,6 +17,7 @@
#include <functional>
#include "spell_type.hpp"
+#include "spells5.hpp"
#include "range.h"
/*
diff --git a/src/object1.cc b/src/object1.cc
index b6677850..9fef5eaf 100644
--- a/src/object1.cc
+++ b/src/object1.cc
@@ -15,6 +15,7 @@
#include "quark.h"
#include "spell_type.hpp"
#include "hooks.h"
+#include "spells5.hpp"
/*
* Hack -- note that "TERM_MULTI" is now just "TERM_VIOLET".
diff --git a/src/object2.cc b/src/object2.cc
index 0ecbcb1f..564248bf 100644
--- a/src/object2.cc
+++ b/src/object2.cc
@@ -15,6 +15,7 @@
#include "device_allocation.h"
#include "hooks.h"
#include "spells3.hpp"
+#include "spells5.hpp"
#include <cassert>
#include <vector>
@@ -3214,31 +3215,6 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
}
/*
- * Get a spell for a given stick(wand, staff, rod)
- */
-long get_random_stick(byte tval, int level)
-{
- int tries;
-
- for (tries = 0; tries < 1000; tries++)
- {
- long spell_idx = rand_int(school_spells_count);
- spell_type *spell = spell_at(spell_idx);
- device_allocation *device_allocation = spell_type_device_allocation(spell, tval);
-
- if ((device_allocation != NULL) &&
- (rand_int(spell_type_skill_level(spell) * 3) < level) &&
- (magik(100 - device_allocation->rarity)))
- {
- return spell_idx;
- }
- }
-
- return -1;
-}
-
-
-/*
* Randomized level
*/
static int randomized_level_in_range(range_type *range, int level)
@@ -3418,8 +3394,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
/* Decide the spell, pval == -1 means to bypass spell selection */
if (o_ptr->pval != -1)
{
- int spl = get_random_stick(TV_WAND, dun_level);
-
+ auto spl = get_random_stick(TV_WAND, dun_level);
if (spl == -1)
{
spl = MANATHRUST;
diff --git a/src/script.cc b/src/script.cc
index a9407352..55b89bdd 100644
--- a/src/script.cc
+++ b/src/script.cc
@@ -12,6 +12,7 @@
#include "angband.h"
#include "q_library.h"
+#include "spells5.hpp"
void init_lua_init()
diff --git a/src/spells1.cc b/src/spells1.cc
index 09dd4261..9207974c 100644
--- a/src/spells1.cc
+++ b/src/spells1.cc
@@ -12,6 +12,7 @@
#include "angband.h"
#include "spell_type.hpp"
+#include "spells5.hpp"
#include <chrono>
#include <thread>
diff --git a/src/spells3.cc b/src/spells3.cc
index 19594cbf..076c4372 100644
--- a/src/spells3.cc
+++ b/src/spells3.cc
@@ -1,4 +1,5 @@
#include "spells3.hpp"
+#include "spells5.hpp"
#include "angband.h"
#include <assert.h>
diff --git a/src/spells4.cc b/src/spells4.cc
index 4cd10e95..cd3946c1 100644
--- a/src/spells4.cc
+++ b/src/spells4.cc
@@ -6,6 +6,7 @@
#include "spell_type.hpp"
#include "spell_idx_list.hpp"
#include "spells3.hpp"
+#include "spells5.hpp"
#include <algorithm>
school_book_type school_books[SCHOOL_BOOKS_SIZE];
diff --git a/src/spells5.cc b/src/spells5.cc
index 31a085ad..4ce897b4 100644
--- a/src/spells5.cc
+++ b/src/spells5.cc
@@ -1,3 +1,4 @@
+#include "spells5.hpp"
#include <angband.h>
#include <assert.h>
@@ -6,6 +7,8 @@
#include "device_allocation.h"
#include "spells3.hpp"
+static s16b school_spells_count = 0;
+static struct spell_type *school_spells[SCHOOL_SPELLS_MAX];
static spell_type *spell_new(s32b *index, cptr name)
{
@@ -67,6 +70,30 @@ s16b get_random_spell(s16b random_type, int level)
return -1;
}
+/*
+ * Get a spell for a device of a given tval (wand or staff).
+ */
+s16b get_random_stick(byte tval, int level)
+{
+ int tries;
+
+ for (tries = 0; tries < 1000; tries++)
+ {
+ long spell_idx = rand_int(school_spells_count);
+ spell_type *spell = spell_at(spell_idx);
+ device_allocation *device_allocation = spell_type_device_allocation(spell, tval);
+
+ if ((device_allocation != NULL) &&
+ (rand_int(spell_type_skill_level(spell) * 3) < level) &&
+ (magik(100 - device_allocation->rarity)))
+ {
+ return spell_idx;
+ }
+ }
+
+ return -1;
+}
+
static void spells_init_tome()
{
{
diff --git a/src/spells5.hpp b/src/spells5.hpp
new file mode 100644
index 00000000..f94d0d39
--- /dev/null
+++ b/src/spells5.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "h-basic.h"
+
+void school_spells_init();
+struct spell_type *spell_at(s32b index);
+s16b get_random_spell(s16b random_type, int lev);
+s16b get_random_stick(byte tval, int level);
diff --git a/src/store.cc b/src/store.cc
index ce06df11..aaffb708 100644
--- a/src/store.cc
+++ b/src/store.cc
@@ -14,6 +14,7 @@
#include "spell_type.hpp"
#include "quark.h"
#include "hooks.h"
+#include "spells5.hpp"
#include <cassert>
diff --git a/src/variable.cc b/src/variable.cc
index c458cb30..60949c2d 100644
--- a/src/variable.cc
+++ b/src/variable.cc
@@ -1216,8 +1216,6 @@ bool_ player_char_health;
/*
* The spell list of schools
*/
-s16b school_spells_count = 0;
-spell_type *school_spells[SCHOOL_SPELLS_MAX];
s16b schools_count = 0;
school_type schools[SCHOOLS_MAX];