summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-05-15 19:24:05 +0200
committerBardur Arantsson <bardur@scientician.net>2012-05-15 19:47:45 +0200
commitb446c8368b172aa29d312cf7eeca5e8547e73c81 (patch)
tree5f095e42e22b3a3b8c199b91ede0b13bef989e54 /src
parent6bd3fd4881765ec278b9c3896cd4cff15fe33265 (diff)
Lua: Move "bookable_spells" to C
Diffstat (limited to 'src')
-rw-r--r--src/externs.h2
-rw-r--r--src/q_library.c105
-rw-r--r--src/util.pkg5
3 files changed, 92 insertions, 20 deletions
diff --git a/src/externs.h b/src/externs.h
index b6c8ea88..f19e2db8 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -612,6 +612,8 @@ extern hook_return process_hooks_return[20];
extern bool_ process_hooks_ret(int h_idx, char *ret, char *fmt, ...);
extern bool_ process_hooks(int h_idx, char *fmt, ...);
+extern void initialize_bookable_spells();
+
/* help.c */
extern void ingame_help(bool_ enable);
diff --git a/src/q_library.c b/src/q_library.c
index d19b15d8..7ccbd9cf 100644
--- a/src/q_library.c
+++ b/src/q_library.c
@@ -10,6 +10,78 @@
#define MONSTER_IRON_GOLEM 367
#define MONSTER_MITHRIL_GOLEM 464
+#define MAX_BOOKABLE_SPELLS 128
+
+static s16b bookable_spells[MAX_BOOKABLE_SPELLS];
+static s16b bookable_spells_size = 0;
+
+static void push_spell(s16b spell_idx)
+{
+ assert(bookable_spells_size < MAX_BOOKABLE_SPELLS);
+ bookable_spells[bookable_spells_size++] = spell_idx;
+}
+
+void initialize_bookable_spells()
+{
+ push_spell(MANATHRUST);
+ push_spell(DELCURSES);
+ push_spell(GLOBELIGHT);
+ push_spell(FIREGOLEM);
+ push_spell(FIREFLASH);
+ push_spell(FIREWALL);
+ push_spell(GEYSER);
+ push_spell(VAPOR);
+ push_spell(ENTPOTION);
+ push_spell(NOXIOUSCLOUD);
+ push_spell(POISONBLOOD);
+ push_spell(STONESKIN);
+ push_spell(DIG);
+ push_spell(RECHARGE);
+ push_spell(DISPERSEMAGIC);
+ push_spell(BLINK);
+ push_spell(DISARM);
+ push_spell(TELEPORT);
+ push_spell(SENSEMONSTERS);
+ push_spell(SENSEHIDDEN);
+ push_spell(REVEALWAYS);
+ push_spell(IDENTIFY);
+ push_spell(VISION);
+ push_spell(MAGELOCK);
+ push_spell(SLOWMONSTER);
+ push_spell(ESSENCESPEED);
+ push_spell(CHARM);
+ push_spell(CONFUSE);
+ push_spell(ARMOROFFEAR);
+ push_spell(STUN);
+ push_spell(GROWTREE);
+ push_spell(HEALING);
+ push_spell(RECOVERY);
+ push_spell(ERU_SEE);
+ push_spell(ERU_LISTEN);
+ push_spell(MANWE_BLESS);
+ push_spell(MANWE_SHIELD);
+ push_spell(YAVANNA_CHARM_ANIMAL);
+ push_spell(YAVANNA_GROW_GRASS);
+ push_spell(YAVANNA_TREE_ROOTS);
+ push_spell(TULKAS_AIM);
+ push_spell(TULKAS_SPIN);
+ push_spell(MELKOR_CURSE);
+ push_spell(MELKOR_CORPSE_EXPLOSION);
+ push_spell(DRAIN);
+
+ if (game_module_idx == MODULE_THEME)
+ {
+ push_spell(AULE_FIREBRAND);
+ push_spell(AULE_CHILD);
+ push_spell(VARDA_LIGHT_VALINOR);
+ push_spell(VARDA_EVENSTAR);
+ push_spell(ULMO_BELEGAER);
+ push_spell(ULMO_WRATH);
+ push_spell(MANDOS_TEARS_LUTHIEN);
+ push_spell(MANDOS_TALE_DOOM);
+ }
+}
+
static s16b library_quest_place_random(int minY, int minX, int maxY, int maxX, int r_idx)
{
int y = randint(maxY - minY + 1) + minY;
@@ -64,14 +136,6 @@ static bool_ library_quest_book_contains_spell(int spell)
return FALSE;
}
-static int library_quest_bookable_spells_at(int i) {
- return exec_lua(format("return library_quest.bookable_spells[%d]", i + 1));
-}
-
-static int library_quest_getn_bookable_spells() {
- return exec_lua("return getn(library_quest.bookable_spells)");
-}
-
static int library_quest_print_spell(int color, int row, int spell) {
return exec_lua(format("library_quest.print_spell(%d,%d,%d)", color, row, spell));
}
@@ -117,7 +181,7 @@ static void library_quest_print_spells(int first, int current)
{
int width, height;
int slots, row;
- int nspells, index;
+ int index;
Term_clear();
Term_get_size(&width, &height);
@@ -137,9 +201,8 @@ static void library_quest_print_spells(int first, int current)
row = 3;
- nspells = library_quest_getn_bookable_spells();
- for (index = 0; index < nspells; index++) {
- int spell = library_quest_bookable_spells_at(index);
+ for (index = 0; index < bookable_spells_size; index++) {
+ int spell = bookable_spells[index];
if (index >= first) {
int color;
if (index == current) {
@@ -183,7 +246,7 @@ static void library_quest_fill_book()
while (done == FALSE)
{
char ch;
- int dir, total;
+ int dir, spell_idx;
library_quest_print_spells(first, current);
@@ -191,6 +254,8 @@ static void library_quest_fill_book()
ch = inkey();
dir = get_keymap_dir(ch);
+ spell_idx = bookable_spells[current];
+
if (ch == ESCAPE) {
if (library_quest_book_slots_left() == 0) {
flush();
@@ -205,23 +270,23 @@ static void library_quest_fill_book()
} else if (ch == 'p') {
current = current - height;
} else if (ch == 'I') {
- library_quest_print_spell_desc(library_quest_bookable_spells_at(current), 0);
+ library_quest_print_spell_desc(spell_idx, 0);
inkey();
} else if (dir == 2) {
current = current + 1;
} else if (dir == 8) {
current = current - 1;
} else if (dir == 6) {
- if (library_quest_book_contains_spell(library_quest_bookable_spells_at(current)) == FALSE) {
- library_quest_add_spell(library_quest_bookable_spells_at(current));
+ if (library_quest_book_contains_spell(spell_idx) == FALSE)
+ {
+ library_quest_add_spell(spell_idx);
}
} else if (dir == 4) {
- library_quest_remove_spell(library_quest_bookable_spells_at(current));
+ library_quest_remove_spell(spell_idx);
}
- total = library_quest_getn_bookable_spells();
- if (current >= total) {
- current = total - 1;
+ if (current >= bookable_spells_size) {
+ current = bookable_spells_size - 1;
} else if (current < 0) {
current = 0;
}
diff --git a/src/util.pkg b/src/util.pkg
index 2ec70acf..a32ef927 100644
--- a/src/util.pkg
+++ b/src/util.pkg
@@ -2375,3 +2375,8 @@ extern s16b resolve_mimic_name(cptr name);
* Timers
*/
void timer_aggravate_evil_enable();
+
+/**
+ * Initialize bookable spells.
+ */
+void initialize_bookable_spells();