diff options
-rw-r--r-- | lib/core/s_aux.lua | 65 | ||||
-rw-r--r-- | lib/mods/theme/core/s_aux.lua | 65 | ||||
-rw-r--r-- | lib/mods/theme/scpt/init.lua | 3 | ||||
-rw-r--r-- | lib/mods/theme/scpt/library.lua | 40 | ||||
-rw-r--r-- | lib/mods/theme/scpt/s_udun.lua | 39 | ||||
-rw-r--r-- | lib/mods/theme/scpt/spells.lua | 166 | ||||
-rw-r--r-- | lib/scpt/init.lua | 3 | ||||
-rw-r--r-- | lib/scpt/library.lua | 39 | ||||
-rw-r--r-- | lib/scpt/s_udun.lua | 39 | ||||
-rw-r--r-- | lib/scpt/spells.lua | 142 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/angband.h | 6 | ||||
-rw-r--r-- | src/cmd2.c | 2 | ||||
-rw-r--r-- | src/cmd5.c | 45 | ||||
-rw-r--r-- | src/defines.h | 39 | ||||
-rw-r--r-- | src/externs.h | 16 | ||||
-rw-r--r-- | src/q_library.c | 9 | ||||
-rw-r--r-- | src/spells.pkg | 8 | ||||
-rw-r--r-- | src/spells3.c | 68 | ||||
-rw-r--r-- | src/spells4.c | 423 | ||||
-rw-r--r-- | src/types.h | 17 |
21 files changed, 592 insertions, 643 deletions
diff --git a/lib/core/s_aux.lua b/lib/core/s_aux.lua index 6cdcbd82..20cf4964 100644 --- a/lib/core/s_aux.lua +++ b/lib/core/s_aux.lua @@ -81,7 +81,6 @@ __spell_spell = {} __spell_info = {} __spell_desc = {} __spell_school = {} -school_book = {} -- Find a spell by name function find_spell(name) @@ -262,44 +261,6 @@ function spell_school_name(s) return sch_str end --- Print the book and the spells -function print_book(book, spl, obj) - local x, y, index, sch, size, s - - x = 0 - y = 2 - size = 0 - - -- Hack if the book is 255 it is a random book - if book == 255 then - school_book[book] = {spl} - end - - -- Parse all spells - for index, s in school_book[book] do - local color = TERM_L_DARK - local lvl, na = get_level_school(s, 50, -50) - local xx, sch_str - - if is_ok_spell(s, obj) then - if get_mana(s) > get_power(s) then color = TERM_ORANGE - else color = TERM_L_GREEN end - end - - sch_str = spell_school_name(s) - - if na then - c_prt(color, format("%c) %-20s%-16s %3s %4s %3d%s %s", size + strbyte("a"), spell(s).name, sch_str, na, get_mana(s), spell_chance(s), "%", __spell_info[s]()), y, x) - else - c_prt(color, format("%c) %-20s%-16s %3d %4s %3d%s %s", size + strbyte("a"), spell(s).name, sch_str, lvl, get_mana(s), spell_chance(s), "%", __spell_info[s]()), y, x) - end - y = y + 1 - size = size + 1 - end - prt(format(" %-20s%-16s Level Cost Fail Info", "Name", "School"), 1, x) - return y -end - -- Output the desc when sued as a device function print_device_desc(s) local index, desc @@ -309,32 +270,6 @@ function print_device_desc(s) end end -function book_spells_num(book) - local size, index, sch - - size = 0 - - -- Hack if the book is 255 it is a random book - if book == 255 then - return 1 - end - - -- Parse all spells - for index, s in school_book[book] do - size = size + 1 - end - return size -end - -function spell_in_book(book, spell) - local i, s - - for i, s in school_book[book] do - if s == spell then return TRUE end - end - return FALSE -end - function check_affect(s, name, default) local s_ptr = __tmp_spells[s] local a diff --git a/lib/mods/theme/core/s_aux.lua b/lib/mods/theme/core/s_aux.lua index 6cdcbd82..20cf4964 100644 --- a/lib/mods/theme/core/s_aux.lua +++ b/lib/mods/theme/core/s_aux.lua @@ -81,7 +81,6 @@ __spell_spell = {} __spell_info = {} __spell_desc = {} __spell_school = {} -school_book = {} -- Find a spell by name function find_spell(name) @@ -262,44 +261,6 @@ function spell_school_name(s) return sch_str end --- Print the book and the spells -function print_book(book, spl, obj) - local x, y, index, sch, size, s - - x = 0 - y = 2 - size = 0 - - -- Hack if the book is 255 it is a random book - if book == 255 then - school_book[book] = {spl} - end - - -- Parse all spells - for index, s in school_book[book] do - local color = TERM_L_DARK - local lvl, na = get_level_school(s, 50, -50) - local xx, sch_str - - if is_ok_spell(s, obj) then - if get_mana(s) > get_power(s) then color = TERM_ORANGE - else color = TERM_L_GREEN end - end - - sch_str = spell_school_name(s) - - if na then - c_prt(color, format("%c) %-20s%-16s %3s %4s %3d%s %s", size + strbyte("a"), spell(s).name, sch_str, na, get_mana(s), spell_chance(s), "%", __spell_info[s]()), y, x) - else - c_prt(color, format("%c) %-20s%-16s %3d %4s %3d%s %s", size + strbyte("a"), spell(s).name, sch_str, lvl, get_mana(s), spell_chance(s), "%", __spell_info[s]()), y, x) - end - y = y + 1 - size = size + 1 - end - prt(format(" %-20s%-16s Level Cost Fail Info", "Name", "School"), 1, x) - return y -end - -- Output the desc when sued as a device function print_device_desc(s) local index, desc @@ -309,32 +270,6 @@ function print_device_desc(s) end end -function book_spells_num(book) - local size, index, sch - - size = 0 - - -- Hack if the book is 255 it is a random book - if book == 255 then - return 1 - end - - -- Parse all spells - for index, s in school_book[book] do - size = size + 1 - end - return size -end - -function spell_in_book(book, spell) - local i, s - - for i, s in school_book[book] do - if s == spell then return TRUE end - end - return FALSE -end - function check_affect(s, name, default) local s_ptr = __tmp_spells[s] local a diff --git a/lib/mods/theme/scpt/init.lua b/lib/mods/theme/scpt/init.lua index 2a24ecff..a65db8ac 100644 --- a/lib/mods/theme/scpt/init.lua +++ b/lib/mods/theme/scpt/init.lua @@ -20,9 +20,6 @@ tome_dofile("spells.lua") -- Post-spell creation initialization initialize_bookable_spells() --- Add some quests -tome_dofile("library.lua") - -- Add joke stuff tome_dofile("drunk.lua") tome_dofile("joke.lua") diff --git a/lib/mods/theme/scpt/library.lua b/lib/mods/theme/scpt/library.lua deleted file mode 100644 index 35f95094..00000000 --- a/lib/mods/theme/scpt/library.lua +++ /dev/null @@ -1,40 +0,0 @@ --- Library quest in Minas Anor - --- Partially based on Fireproofing quest - -library_quest = {} - --- Book creation helpers --- Print a spell (taken from s_aux) -function library_quest.print_spell(color, y, spl) - local x, index, sch, size, s - - x = 0 - size = 0 - book = 255 - obj = nil - - -- Hack if the book is 255 it is a random book - if book == 255 then - school_book[book] = {spl} - end - - -- Parse all spells - for index, s in school_book[book] do - local lvl, na = get_level_school(s, 50, -50) - local xx, sch_str - - sch_str = spell_school_name(s) - - if s == spl then - if na then - c_prt(color, format("%-20s%-16s %3s %4s %3d%s %s", spell(s).name, sch_str, na, get_mana(s), spell_chance(s), "%", __spell_info[s]()), y, x) - else - c_prt(color, format("%-20s%-16s %3d %4s %3d%s %s", spell(s).name, sch_str, lvl, get_mana(s), spell_chance(s), "%", __spell_info[s]()), y, x) - end - y = y + 1 - size = size + 1 - end - end - return y -end diff --git a/lib/mods/theme/scpt/s_udun.lua b/lib/mods/theme/scpt/s_udun.lua index 3ddfeb14..bb12ac7f 100644 --- a/lib/mods/theme/scpt/s_udun.lua +++ b/lib/mods/theme/scpt/s_udun.lua @@ -72,42 +72,3 @@ FLAMEOFUDUN = add_spell "Turns you into a powerful Balrog", } } - - --- Return the number of Udun/Melkor spells in a given book -function udun_in_book(sval, pval) - local i, y, index, sch, s - - i = 0 - - -- Hack if the book is 255 it is a random book - if sval == 255 then - school_book[sval] = {pval} - end - -- Parse all spells - for index, s in school_book[sval] do - for index, sch in __spell_school[s] do - if sch == SCHOOL_UDUN then i = i + 1 end - if sch == SCHOOL_MELKOR then i = i + 1 end - end - end - return i -end - --- Return the total level of spells -function levels_in_book(sval, pval) - local i, y, index, sch, s - - i = 0 - - -- Hack if the book is 255 it is a random book - if sval == 255 then - school_book[sval] = {pval} - end - - -- Parse all spells - for index, s in school_book[sval] do - i = i + __tmp_spells[s].level - end - return i -end diff --git a/lib/mods/theme/scpt/spells.lua b/lib/mods/theme/scpt/spells.lua index 36829356..eedd59ad 100644 --- a/lib/mods/theme/scpt/spells.lua +++ b/lib/mods/theme/scpt/spells.lua @@ -415,167 +415,5 @@ tome_dofile("s_stick.lua") -- Musics tome_dofile("s_music.lua") --- List of spellbooks - --- Create the crystal of mana -school_book[0] = { - MANATHRUST, DELCURSES, RESISTS, MANASHIELD, -} - --- The book of the eternal flame -school_book[1] = { - GLOBELIGHT, FIREGOLEM, FIREFLASH, FIREWALL, FIERYAURA, -} - --- The book of the blowing winds -school_book[2] = { - NOXIOUSCLOUD, POISONBLOOD, INVISIBILITY, STERILIZE, AIRWINGS, THUNDERSTORM, -} - --- The book of the impenetrable earth -school_book[3] = { - STONESKIN, DIG, STONEPRISON, SHAKE, STRIKE, -} - --- The book of the unstopable wave -school_book[4] = { - GEYSER, VAPOR, ENTPOTION, TIDALWAVE, ICESTORM -} - --- Create the book of translocation -school_book[5] = { - BLINK, DISARM, TELEPORT, TELEAWAY, RECALL, PROBABILITY_TRAVEL, -} - --- Create the book of the tree -school_book[6] = { - GROWTREE, HEALING, RECOVERY, REGENERATION, SUMMONANNIMAL, GROW_ATHELAS, -} - --- Create the book of Knowledge -school_book[7] = { - SENSEMONSTERS, SENSEHIDDEN, REVEALWAYS, IDENTIFY, VISION, STARIDENTIFY, -} - --- Create the book of the Time -school_book[8] = { - MAGELOCK, SLOWMONSTER, ESSENCESPEED, BANISHMENT, -} - --- Create the book of meta spells -school_book[9] = { - RECHARGE, DISPERSEMAGIC, SPELLBINDER, TRACKER, INERTIA_CONTROL, -} - --- Create the book of the mind -school_book[10] = { - CHARM, CONFUSE, ARMOROFFEAR, STUN, -} - --- Create the book of hellflame -school_book[11] = { - DRAIN, GENOCIDE, WRAITHFORM, FLAMEOFUDUN, -} - --- Create the book of eru -school_book[20] = { - ERU_SEE, ERU_LISTEN, ERU_UNDERSTAND, ERU_PROT, -} - --- Create the book of manwe -school_book[21] = { - MANWE_BLESS, MANWE_SHIELD, MANWE_CALL, MANWE_AVATAR, -} - --- Create the book of tulkas -school_book[22] = { - TULKAS_AIM, TULKAS_SPIN, TULKAS_WAVE, -} - --- Create the book of melkor -school_book[23] = { - MELKOR_CURSE, MELKOR_CORPSE_EXPLOSION, MELKOR_MIND_STEAL, -} - --- Create the book of yavanna -school_book[24] = { - YAVANNA_CHARM_ANIMAL, YAVANNA_GROW_GRASS, YAVANNA_TREE_ROOTS, YAVANNA_WATER_BITE, YAVANNA_UPROOT, -} - --- Create the book of beginner's cantrip -school_book[50] = { - MANATHRUST, GLOBELIGHT, ENTPOTION, BLINK, SENSEMONSTERS, SENSEHIDDEN, -} - --- Create the book of teleporatation -school_book[51] = { - BLINK, TELEPORT, TELEAWAY -} - --- Create the book of summoning -school_book[52] = { - FIREGOLEM, SUMMONANNIMAL -} - - --- Create the Armageddon Demonblade -school_book[55] = { - DEMON_BLADE, DEMON_MADNESS, DEMON_FIELD, -} - --- Create the Shield Demonblade -school_book[56] = { - DOOM_SHIELD, DEMON_CLOAK, UNHOLY_WORD, -} - --- Create the Control Demonblade -school_book[57] = { - DEMON_SUMMON, DISCHARGE_MINION, CONTROL_DEMON, -} - --- Create the Drums -school_book[58] = { - MUSIC_STOP, MUSIC_HOLD, MUSIC_CONF, MUSIC_STUN, -} - --- Create the Harps -school_book[59] = { - MUSIC_STOP, MUSIC_LITE, MUSIC_HERO, MUSIC_HEAL, MUSIC_TIME, MUSIC_MIND, -} - --- Create the Horns -school_book[60] = { - MUSIC_STOP, MUSIC_BLOW, MUSIC_WIND, MUSIC_YLMIR, MUSIC_AMBARKANTA, -} - --- Book of the Player, filled in by the Library Quest -school_book[61] = { } - --- Geomancy spells, not a real book -school_book[62] = { - CALL_THE_ELEMENTS, CHANNEL_ELEMENTS, ELEMENTAL_WAVE, VAPORIZE, GEOLYSIS, DRIPPING_TREAD, GROW_BARRIER, ELEMENTAL_MINION -} - --- Aule book [63] -school_book[BOOK_AULE] = -{ - AULE_FIREBRAND, AULE_ENCHANT_WEAPON, AULE_ENCHANT_ARMOUR, AULE_CHILD, -} - --- Varda book [64] -school_book[BOOK_VARDA] = -{ - VARDA_LIGHT_VALINOR, VARDA_CALL_ALMAREN, VARDA_EVENSTAR, VARDA_STARKINDLER, -} - --- Ulmo book [65] -school_book[BOOK_ULMO] = -{ - ULMO_BELEGAER, ULMO_DRAUGHT_ULMONAN, ULMO_CALL_ULUMURI, ULMO_WRATH, -} - --- Mandos book [66] -school_book[BOOK_MANDOS] = -{ - MANDOS_TEARS_LUTHIEN, MANDOS_SPIRIT_FEANTURI, MANDOS_TALE_DOOM, MANDOS_CALL_HALLS -}
\ No newline at end of file +-- Initialize spellbooks +init_school_books() diff --git a/lib/scpt/init.lua b/lib/scpt/init.lua index 655c4bd7..55a6ce63 100644 --- a/lib/scpt/init.lua +++ b/lib/scpt/init.lua @@ -20,9 +20,6 @@ tome_dofile("spells.lua") -- Post-spell creation initialization initialize_bookable_spells() --- Add some quests -tome_dofile("library.lua") - -- Add joke stuff tome_dofile("drunk.lua") tome_dofile("joke.lua") diff --git a/lib/scpt/library.lua b/lib/scpt/library.lua deleted file mode 100644 index 7e25904e..00000000 --- a/lib/scpt/library.lua +++ /dev/null @@ -1,39 +0,0 @@ --- Library quest in Minas Anor - --- Partially based on Fireproofing quest - -library_quest = {} - --- Print a spell (taken from s_aux) -function library_quest.print_spell(color, y, spl) - local x, index, sch, size, s - - x = 0 - size = 0 - book = 255 - obj = nil - - -- Hack if the book is 255 it is a random book - if book == 255 then - school_book[book] = {spl} - end - - -- Parse all spells - for index, s in school_book[book] do - local lvl, na = get_level_school(s, 50, -50) - local xx, sch_str - - sch_str = spell_school_name(s) - - if s == spl then - if na then - c_prt(color, format("%-20s%-16s %3s %4s %3d%s %s", spell(s).name, sch_str, na, get_mana(s), spell_chance(s), "%", __spell_info[s]()), y, x) - else - c_prt(color, format("%-20s%-16s %3d %4s %3d%s %s", spell(s).name, sch_str, lvl, get_mana(s), spell_chance(s), "%", __spell_info[s]()), y, x) - end - y = y + 1 - size = size + 1 - end - end - return y -end diff --git a/lib/scpt/s_udun.lua b/lib/scpt/s_udun.lua index 3ddfeb14..bb12ac7f 100644 --- a/lib/scpt/s_udun.lua +++ b/lib/scpt/s_udun.lua @@ -72,42 +72,3 @@ FLAMEOFUDUN = add_spell "Turns you into a powerful Balrog", } } - - --- Return the number of Udun/Melkor spells in a given book -function udun_in_book(sval, pval) - local i, y, index, sch, s - - i = 0 - - -- Hack if the book is 255 it is a random book - if sval == 255 then - school_book[sval] = {pval} - end - -- Parse all spells - for index, s in school_book[sval] do - for index, sch in __spell_school[s] do - if sch == SCHOOL_UDUN then i = i + 1 end - if sch == SCHOOL_MELKOR then i = i + 1 end - end - end - return i -end - --- Return the total level of spells -function levels_in_book(sval, pval) - local i, y, index, sch, s - - i = 0 - - -- Hack if the book is 255 it is a random book - if sval == 255 then - school_book[sval] = {pval} - end - - -- Parse all spells - for index, s in school_book[sval] do - i = i + __tmp_spells[s].level - end - return i -end diff --git a/lib/scpt/spells.lua b/lib/scpt/spells.lua index 24b4f02b..4bd5d7ea 100644 --- a/lib/scpt/spells.lua +++ b/lib/scpt/spells.lua @@ -317,143 +317,5 @@ tome_dofile("s_stick.lua") -- Musics tome_dofile("s_music.lua") --- List of spellbooks - --- Create the crystal of mana -school_book[0] = { - MANATHRUST, DELCURSES, RESISTS, MANASHIELD, -} - --- The book of the eternal flame -school_book[1] = { - GLOBELIGHT, FIREGOLEM, FIREFLASH, FIREWALL, FIERYAURA, -} - --- The book of the blowing winds -school_book[2] = { - NOXIOUSCLOUD, POISONBLOOD, INVISIBILITY, STERILIZE, AIRWINGS, THUNDERSTORM, -} - --- The book of the impenetrable earth -school_book[3] = { - STONESKIN, DIG, STONEPRISON, SHAKE, STRIKE, -} - --- The book of the unstopable wave -school_book[4] = { - GEYSER, VAPOR, ENTPOTION, TIDALWAVE, ICESTORM -} - --- Create the book of translocation -school_book[5] = { - BLINK, DISARM, TELEPORT, TELEAWAY, RECALL, PROBABILITY_TRAVEL, -} - --- Create the book of the tree -school_book[6] = { - GROWTREE, HEALING, RECOVERY, REGENERATION, SUMMONANNIMAL, -} - --- Create the book of Knowledge -school_book[7] = { - SENSEMONSTERS, SENSEHIDDEN, REVEALWAYS, IDENTIFY, VISION, STARIDENTIFY, -} - --- Create the book of the Time -school_book[8] = { - MAGELOCK, SLOWMONSTER, ESSENCESPEED, BANISHMENT, -} - --- Create the book of meta spells -school_book[9] = { - RECHARGE, DISPERSEMAGIC, SPELLBINDER, TRACKER, INERTIA_CONTROL, -} - --- Create the book of the mind -school_book[10] = { - CHARM, CONFUSE, ARMOROFFEAR, STUN, -} - --- Create the book of hellflame -school_book[11] = { - DRAIN, GENOCIDE, WRAITHFORM, FLAMEOFUDUN, -} - --- Create the book of eru -school_book[20] = { - ERU_SEE, ERU_LISTEN, ERU_UNDERSTAND, ERU_PROT, -} - --- Create the book of manwe -school_book[21] = { - MANWE_BLESS, MANWE_SHIELD, MANWE_CALL, MANWE_AVATAR, -} - --- Create the book of tulkas -school_book[22] = { - TULKAS_AIM, TULKAS_SPIN, TULKAS_WAVE, -} - --- Create the book of melkor -school_book[23] = { - MELKOR_CURSE, MELKOR_CORPSE_EXPLOSION, MELKOR_MIND_STEAL, -} - --- Create the book of yavanna -school_book[24] = { - YAVANNA_CHARM_ANIMAL, YAVANNA_GROW_GRASS, YAVANNA_TREE_ROOTS, YAVANNA_WATER_BITE, YAVANNA_UPROOT, -} - --- Create the book of beginner's cantrip -school_book[50] = { - MANATHRUST, GLOBELIGHT, ENTPOTION, BLINK, SENSEMONSTERS, SENSEHIDDEN, -} - --- Create the book of teleporatation -school_book[51] = { - BLINK, TELEPORT, TELEAWAY -} - --- Create the book of summoning -school_book[52] = { - FIREGOLEM, SUMMONANNIMAL -} - - --- Create the Armageddon Demonblade -school_book[55] = { - DEMON_BLADE, DEMON_MADNESS, DEMON_FIELD, -} - --- Create the Shield Demonblade -school_book[56] = { - DOOM_SHIELD, DEMON_CLOAK, UNHOLY_WORD, -} - --- Create the Control Demonblade -school_book[57] = { - DEMON_SUMMON, DISCHARGE_MINION, CONTROL_DEMON, -} - --- Create the Drums -school_book[58] = { - MUSIC_STOP, MUSIC_HOLD, MUSIC_CONF, MUSIC_STUN, -} - --- Create the Harps -school_book[59] = { - MUSIC_STOP, MUSIC_LITE, MUSIC_HERO, MUSIC_HEAL, MUSIC_TIME, MUSIC_MIND, -} - --- Create the Horns -school_book[60] = { - MUSIC_STOP, MUSIC_BLOW, MUSIC_WIND, MUSIC_YLMIR, MUSIC_AMBARKANTA, -} - --- Book of the Player, filled in by the Library Quest -school_book[61] = { } - --- Geomancy spells, not a real book -school_book[62] = { - CALL_THE_ELEMENTS, CHANNEL_ELEMENTS, ELEMENTAL_WAVE, VAPORIZE, GEOLYSIS, DRIPPING_TREAD, GROW_BARRIER, ELEMENTAL_MINION -} +-- Initialize spellbooks +init_school_books() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b286a477..3a640e74 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,6 +62,7 @@ TOLUA_FILE(dungeon w_dun.c) # tome executable INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lua) ADD_EXECUTABLE(tome ${EXECUTABLE_OPTIONS} ${SRCS}) TARGET_LINK_LIBRARIES(tome lua ${LIBS}) diff --git a/src/angband.h b/src/angband.h index cac38122..93e3b76e 100644 --- a/src/angband.h +++ b/src/angband.h @@ -45,6 +45,12 @@ extern "C" { /* + * SGLIB + */ +#include "sglib.h" + + +/* * Now, include the define's, the type's, and the extern's */ #include "defines.h" @@ -4696,7 +4696,7 @@ void do_cmd_sacrifice(void) /* In books it depends of the spell levels*/ if (o_ptr->tval == TV_BOOK) { - int x = exec_lua(format("return levels_in_book(%d, %d)", o_ptr->sval, o_ptr->pval)); + int x = levels_in_book(o_ptr->sval, o_ptr->pval); inc_piety(GOD_MELKOR, 2 * x); } @@ -15,22 +15,9 @@ #include "lua/lua.h" #include "tolua.h" -extern lua_State *L; - -static int spell_x(int sval, int pval, int i) -{ - if (sval == 255) - { - return pval; - } - else - { - char buf[128]; - sprintf(buf, "school_book[%d][%d]", sval, i+1); - return get_lua_int(buf); - } -} +#include <assert.h> +extern lua_State *L; /* Maximum number of tries for teleporting */ #define MAX_TRIES 300 @@ -2148,25 +2135,13 @@ bool_ get_item_hook_find_spell(int *item) } } /* A random book ? */ - else if ((o_ptr->sval == 255) && (o_ptr->pval == spell)) + else if (school_book_contains_spell(o_ptr->sval, spell)) { *item = i; hack_force_spell = spell; hack_force_spell_obj = o_ptr; return TRUE; } - /* A normal book */ - else if (o_ptr->sval != 255) - { - sprintf(buf2, "return spell_in_book(%d, %d)", o_ptr->sval, spell); - if (exec_lua(buf2)) - { - *item = i; - hack_force_spell = spell; - hack_force_spell_obj = o_ptr; - return TRUE; - } - } } return FALSE; } @@ -2258,7 +2233,7 @@ s32b get_school_spell(cptr do_what, cptr check_fct, s16b force_book) if (hack_force_spell == -1) { - num = exec_lua(format("return book_spells_num(%d)", sval)); + num = school_book_length(sval); /* Build a prompt (accept all spells) */ strnfmt(out_val, 78, "(Spells %c-%c, Descs %c-%c, *=List, ESC=exit) %^s which spell? ", @@ -2281,7 +2256,7 @@ s32b get_school_spell(cptr do_what, cptr check_fct, s16b force_book) Term_save(); /* Display a list of spells */ - call_lua("print_book", "(d,d,O)", "d", sval, pval, o_ptr, &where); + where = print_book(sval, pval, o_ptr); } /* Hide the list */ @@ -2340,7 +2315,7 @@ s32b get_school_spell(cptr do_what, cptr check_fct, s16b force_book) } /* Display a list of spells */ - call_lua("print_book", "(d,d,O)", "d", sval, pval, o_ptr, &where); + where = print_book(sval, pval, o_ptr); print_spell_desc(spell_x(sval, pval, i), where); } else @@ -2453,7 +2428,7 @@ void browse_school_spell(int book, int pval, object_type *o_ptr) window_stuff(); } - num = exec_lua(format("return book_spells_num(%d)", book)); + num = school_book_length(book); /* Build a prompt (accept all spells) */ strnfmt(out_val, 78, "(Spells %c-%c, ESC=exit) cast which spell? ", @@ -2464,13 +2439,13 @@ void browse_school_spell(int book, int pval, object_type *o_ptr) Term_save(); /* Display a list of spells */ - call_lua("print_book", "(d,d,O)", "d", book, pval, o_ptr, &where); + where = print_book(book, pval, o_ptr); /* Get a spell from the user */ while (get_com(out_val, &choice)) { /* Display a list of spells */ - call_lua("print_book", "(d,d,O)", "d", book, pval, o_ptr, &where); + where = print_book(book, pval, o_ptr); /* Note verify */ ask = (isupper(choice)); @@ -2492,7 +2467,7 @@ void browse_school_spell(int book, int pval, object_type *o_ptr) Term_load(); /* Display a list of spells */ - call_lua("print_book", "(d,d,O)", "d", book, pval, o_ptr, &where); + where = print_book(book, pval, o_ptr); print_spell_desc(spell_x(book, pval, i), where); } diff --git a/src/defines.h b/src/defines.h index b4a02a11..7457134a 100644 --- a/src/defines.h +++ b/src/defines.h @@ -4718,3 +4718,42 @@ #define AB_FAR_REACHING 8 #define AB_TRAPPING 9 #define AB_UNDEAD_FORM 10 + +/** + * Spell school books/tomes + */ +#define TOME_MANA 0 +#define TOME_FIRE 1 +#define TOME_WINDS 2 +#define TOME_EARTH 3 +#define TOME_WATER 4 +#define TOME_TRANSLOCATION 5 +#define TOME_NATURE 6 +#define TOME_KNOWLEDGE 7 +#define TOME_TIME 8 +#define TOME_META 9 +#define TOME_MIND 10 +#define TOME_HELLFLAME 11 +#define TOME_ERU 20 +#define TOME_MANWE 21 +#define TOME_TULKAS 22 +#define TOME_MELKOR 23 +#define TOME_YAVANNA 24 +#define BOOK_CANTRIPS 50 +#define BOOK_TELEPORTATION 51 +#define BOOK_SUMMONING 52 +#define BOOK_DEMON_SWORD 55 +#define BOOK_DEMON_SHIELD 56 +#define BOOK_DEMON_HELM 57 +#define BOOK_DRUMS 58 +#define BOOK_HARPS 59 +#define BOOK_HORNS 60 +#define BOOK_PLAYER 61 +#define BOOK_GEOMANCY 62 +#define BOOK_AULE 63 +#define BOOK_VARDA 64 +#define BOOK_ULMO 65 +#define BOOK_MANDOS 66 +#define BOOK_RANDOM 255 + +#define SCHOOL_BOOKS_SIZE 256 diff --git a/src/externs.h b/src/externs.h index 798ab111..d933b2be 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1673,6 +1673,7 @@ extern s32b WRAITHFORM; extern s32b FLAMEOFUDUN; int udun_in_book(s32b sval, s32b pval); +int levels_in_book(s32b sval, s32b pval); bool_ *udun_drain(); char *udun_drain_info(); @@ -1899,7 +1900,22 @@ bool_ *varda_star_kindler_spell(); char *varda_star_kindler_info(); /* spells4.c */ + +SGLIB_DEFINE_LIST_PROTOTYPES(spell_idx_list, compare_spell_idx, next); + +extern s32b SCHOOL_UDUN; +extern s32b SCHOOL_MELKOR; + void print_spell_desc(int s, int y); +void init_school_books(); +school_book_type *school_books_at(int sval); +void school_book_add_spell(school_book_type *school_book, s32b spell_idx); +void random_book_setup(s16b sval, s32b spell_idx); +int print_spell(cptr label, byte color, int y, s32b s); +int print_book(s16b sval, s32b pval, object_type *obj); +int school_book_length(int sval); +int spell_x(int sval, int pval, int i); +bool_ school_book_contains_spell(int sval, s32b spell_idx); /* randart.c */ extern int get_activation_power(void); diff --git a/src/q_library.c b/src/q_library.c index 0c4ad5e3..bbbcae4c 100644 --- a/src/q_library.c +++ b/src/q_library.c @@ -136,16 +136,13 @@ static bool_ library_quest_book_contains_spell(int spell) return FALSE; } -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)); -} - static void quest_library_finalize_book() { int i = 0; for (i = 1; i <= 3; i++) { - exec_lua(format("school_book[61][%d] = %d", i, library_quest_book_get_slot(i))); + school_book_type *school_book = school_books_at(BOOK_PLAYER); + school_book_add_spell(school_book, library_quest_book_get_slot(i)); } } @@ -209,7 +206,7 @@ static void library_quest_print_spells(int first, int current) color = TERM_ORANGE; } - library_quest_print_spell(color, row, spell); + print_spell(NULL, color, row, spell); if (row == height - 1) { return; diff --git a/src/spells.pkg b/src/spells.pkg index 6f284a9d..18620ccd 100644 --- a/src/spells.pkg +++ b/src/spells.pkg @@ -2900,3 +2900,11 @@ bool_ *varda_evenstar_spell(); char *varda_evenstar_info(); bool_ *varda_star_kindler_spell(); char *varda_star_kindler_info(); + +/** + * spells4.c + */ +void init_school_books(); + +extern s32b SCHOOL_UDUN; +extern s32b SCHOOL_MELKOR; diff --git a/src/spells3.c b/src/spells3.c index 119e128f..b7019e0f 100644 --- a/src/spells3.c +++ b/src/spells3.c @@ -2911,10 +2911,70 @@ char *tulkas_whirlwind_info() /* Return the number of Udun/Melkor spells in a given book */ int udun_in_book(s32b sval, s32b pval) { - char buf[128]; - sprintf(buf, "return udun_in_book(" FMTs32b "," FMTs32b ")", - sval, pval); - return exec_lua(buf); + int count = 0; + school_book_type *school_book; + spell_idx_list *spell_idx = NULL; + struct sglib_spell_idx_list_iterator it; + + random_book_setup(sval, pval); + + /* Get the school book */ + school_book = school_books_at(sval); + + /* Go through spells */ + for (spell_idx = sglib_spell_idx_list_it_init(&it, school_book->spell_idx_list); + spell_idx != NULL; + spell_idx = sglib_spell_idx_list_it_next(&it)) + { + int j; + int n; + char buf[128]; + + sprintf(buf, "__spell_school[" FMTs32b "+1]", spell_idx->i); + n = get_lua_list_size(buf); + + for (j = 0; j < n; j++) + { + int sch; + sprintf(buf, "__spell_school[" FMTs32b "][%d+1]", spell_idx->i, j); + sch = get_lua_int(buf); + + if ((sch == SCHOOL_UDUN) || + (sch == SCHOOL_MELKOR)) + { + count++; + } + } + } + + return count; +} + +int levels_in_book(s32b sval, s32b pval) +{ + int levels = 0; + school_book_type *school_book; + spell_idx_list *spell_idx = NULL; + struct sglib_spell_idx_list_iterator it; + + random_book_setup(sval, pval); + + /* Get the school book */ + school_book = school_books_at(sval); + + /* Parse all spells */ + for (spell_idx = sglib_spell_idx_list_it_init(&it, school_book->spell_idx_list); + spell_idx != NULL; + spell_idx = sglib_spell_idx_list_it_next(&it)) + { + char buf[128]; + s32b s = spell_idx->i; + + sprintf(buf, "__tmp_spells[" FMTs32b "].level", s); + levels += get_lua_int(buf); + } + + return levels; } static bool_ udun_object_is_drainable(object_type *o_ptr) diff --git a/src/spells4.c b/src/spells4.c index 7f59d186..0429e1c1 100644 --- a/src/spells4.c +++ b/src/spells4.c @@ -2,6 +2,18 @@ #include <assert.h> +school_book_type school_books[SCHOOL_BOOKS_SIZE]; + +s32b SCHOOL_UDUN; +s32b SCHOOL_MELKOR; + +static int compare_spell_idx(spell_idx_list *a, spell_idx_list *b) +{ + return SGLIB_NUMERIC_COMPARATOR(a->i, b->i); +} + +SGLIB_DEFINE_LIST_FUNCTIONS(spell_idx_list, compare_spell_idx, next); + static bool_ uses_piety_to_cast(int s) { char buf[128]; @@ -60,3 +72,414 @@ void print_spell_desc(int s, int y) y++; } } + +school_book_type *school_books_at(int i) +{ + assert(i >= 0); + assert(i < SCHOOL_BOOKS_SIZE); + return &school_books[i]; +} + +static void school_book_init(school_book_type *school_book) +{ + school_book->spell_idx_list = NULL; +} + +static void spell_idx_init(spell_idx_list *p, s32b spell_idx) +{ + assert(p != NULL); + + p->i = spell_idx; + p->next = NULL; +} + +static spell_idx_list *new_spell_idx(void *ctx, s32b spell_idx) +{ + spell_idx_list *e = malloc(sizeof(spell_idx_list)); + spell_idx_init(e, spell_idx); + return e; +} + +void school_book_add_spell(school_book_type *school_book, s32b spell_idx) +{ + spell_idx_list *e; + + assert(school_book != NULL); + + e = new_spell_idx(school_book, spell_idx); + sglib_spell_idx_list_add(&school_book->spell_idx_list, e); +} + +int school_book_length(int sval) +{ + school_book_type *school_book = school_books_at(sval); + + if (sval == BOOK_RANDOM) + { + return 1; + } + + /* Parse all spells */ + return sglib_spell_idx_list_len(school_book->spell_idx_list); +} + +int spell_x(int sval, int pval, int i) +{ + assert(i >= 0); + + if (sval == BOOK_RANDOM) + { + return pval; + } + else + { + school_book_type *school_book; + spell_idx_list *spell_idx = NULL; + struct sglib_spell_idx_list_iterator it; + + school_book = school_books_at(sval); + + for (spell_idx = sglib_spell_idx_list_it_init(&it, school_book->spell_idx_list); + (spell_idx != NULL) && (i > 0); + spell_idx = sglib_spell_idx_list_it_next(&it)) + { + i--; + } + + assert(spell_idx != NULL); /* Went off the end of the list? */ + + return spell_idx->i; + } +} + +bool_ school_book_contains_spell(int sval, s32b spell_idx) +{ + school_book_type *school_book = NULL; + spell_idx_list e; + + random_book_setup(sval, spell_idx); + + school_book = school_books_at(sval); + + spell_idx_init(&e, spell_idx); + return NULL != sglib_spell_idx_list_find_member(school_book->spell_idx_list, &e); +} + +void push_spell(int book_idx, s32b spell_idx) +{ + school_book_type *school_book = school_books_at(book_idx); + assert(school_book != NULL); + school_book_add_spell(school_book, spell_idx); +} + +void init_school_books() +{ + int i; + + /* Initialize the new school books */ + for (i = 0; i<SCHOOL_BOOKS_SIZE; i++) + { + school_book_init(&school_books[i]); + } + + /* Note: We're adding the spells in the reverse order that + they appear in each book. This is because the list + operations insert at the front. */ + + /* Create the crystal of mana */ + push_spell(TOME_MANA, MANASHIELD); + push_spell(TOME_MANA, RESISTS); + push_spell(TOME_MANA, DELCURSES); + push_spell(TOME_MANA, MANATHRUST); + + /* The book of the eternal flame */ + push_spell(TOME_FIRE, FIERYAURA); + push_spell(TOME_FIRE, FIREWALL); + push_spell(TOME_FIRE, FIREFLASH); + push_spell(TOME_FIRE, FIREGOLEM); + push_spell(TOME_FIRE, GLOBELIGHT); + + /* The book of the blowing winds */ + push_spell(TOME_WINDS, THUNDERSTORM); + push_spell(TOME_WINDS, AIRWINGS); + push_spell(TOME_WINDS, STERILIZE); + push_spell(TOME_WINDS, INVISIBILITY); + push_spell(TOME_WINDS, POISONBLOOD); + push_spell(TOME_WINDS, NOXIOUSCLOUD); + + /* The book of the impenetrable earth */ + push_spell(TOME_EARTH, STRIKE); + push_spell(TOME_EARTH, SHAKE); + push_spell(TOME_EARTH, STONEPRISON); + push_spell(TOME_EARTH, DIG); + push_spell(TOME_EARTH, STONESKIN); + + /* The book of the unstopable wave */ + push_spell(TOME_WATER, ICESTORM); + push_spell(TOME_WATER, TIDALWAVE); + push_spell(TOME_WATER, ENTPOTION); + push_spell(TOME_WATER, VAPOR); + push_spell(TOME_WATER, GEYSER); + + /* Create the book of translocation */ + push_spell(TOME_TRANSLOCATION, PROBABILITY_TRAVEL); + push_spell(TOME_TRANSLOCATION, RECALL); + push_spell(TOME_TRANSLOCATION, TELEAWAY); + push_spell(TOME_TRANSLOCATION, TELEPORT); + push_spell(TOME_TRANSLOCATION, DISARM); + push_spell(TOME_TRANSLOCATION, BLINK); + + /* Create the book of the tree */ + if (game_module_idx == MODULE_THEME) + { + push_spell(TOME_NATURE, GROW_ATHELAS); + } + push_spell(TOME_NATURE, SUMMONANNIMAL); + push_spell(TOME_NATURE, REGENERATION); + push_spell(TOME_NATURE, RECOVERY); + push_spell(TOME_NATURE, HEALING); + push_spell(TOME_NATURE, GROWTREE); + + /* Create the book of Knowledge */ + push_spell(TOME_KNOWLEDGE, STARIDENTIFY); + push_spell(TOME_KNOWLEDGE, VISION); + push_spell(TOME_KNOWLEDGE, IDENTIFY); + push_spell(TOME_KNOWLEDGE, REVEALWAYS); + push_spell(TOME_KNOWLEDGE, SENSEHIDDEN); + push_spell(TOME_KNOWLEDGE, SENSEMONSTERS); + + /* Create the book of the Time */ + push_spell(TOME_TIME, BANISHMENT); + push_spell(TOME_TIME, ESSENCESPEED); + push_spell(TOME_TIME, SLOWMONSTER); + push_spell(TOME_TIME, MAGELOCK); + + /* Create the book of meta spells */ + push_spell(TOME_META, INERTIA_CONTROL); + push_spell(TOME_META, TRACKER); + push_spell(TOME_META, SPELLBINDER); + push_spell(TOME_META, DISPERSEMAGIC); + push_spell(TOME_META, RECHARGE); + + /* Create the book of the mind */ + push_spell(TOME_MIND, STUN); + push_spell(TOME_MIND, ARMOROFFEAR); + push_spell(TOME_MIND, CONFUSE); + push_spell(TOME_MIND, CHARM); + + /* Create the book of hellflame */ + push_spell(TOME_HELLFLAME, FLAMEOFUDUN); + push_spell(TOME_HELLFLAME, WRAITHFORM); + push_spell(TOME_HELLFLAME, GENOCIDE); + push_spell(TOME_HELLFLAME, DRAIN); + + /* Create the book of eru */ + push_spell(TOME_ERU, ERU_PROT); + push_spell(TOME_ERU, ERU_UNDERSTAND); + push_spell(TOME_ERU, ERU_LISTEN); + push_spell(TOME_ERU, ERU_SEE); + + /* Create the book of manwe */ + push_spell(TOME_MANWE, MANWE_AVATAR); + push_spell(TOME_MANWE, MANWE_CALL); + push_spell(TOME_MANWE, MANWE_SHIELD); + push_spell(TOME_MANWE, MANWE_BLESS); + + /* Create the book of tulkas */ + push_spell(TOME_TULKAS, TULKAS_WAVE); + push_spell(TOME_TULKAS, TULKAS_SPIN); + push_spell(TOME_TULKAS, TULKAS_AIM); + + /* Create the book of melkor */ + push_spell(TOME_MELKOR, MELKOR_MIND_STEAL); + push_spell(TOME_MELKOR, MELKOR_CORPSE_EXPLOSION); + push_spell(TOME_MELKOR, MELKOR_CURSE); + + /* Create the book of yavanna */ + push_spell(TOME_YAVANNA, YAVANNA_UPROOT); + push_spell(TOME_YAVANNA, YAVANNA_WATER_BITE); + push_spell(TOME_YAVANNA, YAVANNA_TREE_ROOTS); + push_spell(TOME_YAVANNA, YAVANNA_GROW_GRASS); + push_spell(TOME_YAVANNA, YAVANNA_CHARM_ANIMAL); + + /* Create the book of beginner's cantrip */ + push_spell(BOOK_CANTRIPS, SENSEHIDDEN); + push_spell(BOOK_CANTRIPS, SENSEMONSTERS); + push_spell(BOOK_CANTRIPS, BLINK); + push_spell(BOOK_CANTRIPS, ENTPOTION); + push_spell(BOOK_CANTRIPS, GLOBELIGHT); + push_spell(BOOK_CANTRIPS, MANATHRUST); + + /* Create the book of teleporatation */ + push_spell(BOOK_TELEPORTATION, TELEAWAY); + push_spell(BOOK_TELEPORTATION, TELEPORT); + push_spell(BOOK_TELEPORTATION, BLINK); + + /* Create the book of summoning */ + push_spell(BOOK_SUMMONING, SUMMONANNIMAL); + push_spell(BOOK_SUMMONING, FIREGOLEM); + + /* Create the Armageddon Demonblade */ + push_spell(BOOK_DEMON_SWORD, DEMON_FIELD); + push_spell(BOOK_DEMON_SWORD, DEMON_MADNESS); + push_spell(BOOK_DEMON_SWORD, DEMON_BLADE); + + /* Create the Shield Demonblade */ + push_spell(BOOK_DEMON_SHIELD, UNHOLY_WORD); + push_spell(BOOK_DEMON_SHIELD, DEMON_CLOAK); + push_spell(BOOK_DEMON_SHIELD, DOOM_SHIELD); + + /* Create the Control Demonblade */ + push_spell(BOOK_DEMON_HELM, CONTROL_DEMON); + push_spell(BOOK_DEMON_HELM, DISCHARGE_MINION); + push_spell(BOOK_DEMON_HELM, DEMON_SUMMON); + + /* Create the Drums */ + push_spell(BOOK_DRUMS, MUSIC_STUN); + push_spell(BOOK_DRUMS, MUSIC_CONF); + push_spell(BOOK_DRUMS, MUSIC_HOLD); + push_spell(BOOK_DRUMS, MUSIC_STOP); + + /* Create the Harps */ + push_spell(BOOK_HARPS, MUSIC_MIND); + push_spell(BOOK_HARPS, MUSIC_TIME); + push_spell(BOOK_HARPS, MUSIC_HEAL); + push_spell(BOOK_HARPS, MUSIC_HERO); + push_spell(BOOK_HARPS, MUSIC_LITE); + push_spell(BOOK_HARPS, MUSIC_STOP); + + /* Create the Horns */ + push_spell(BOOK_HORNS, MUSIC_AMBARKANTA); + push_spell(BOOK_HORNS, MUSIC_YLMIR); + push_spell(BOOK_HORNS, MUSIC_WIND); + push_spell(BOOK_HORNS, MUSIC_BLOW); + push_spell(BOOK_HORNS, MUSIC_STOP); + + /* Book of the Player, filled in by the Library Quest */ + push_spell(BOOK_PLAYER, -1); + + /* Geomancy spells, not a real book */ + push_spell(BOOK_GEOMANCY, ELEMENTAL_MINION); + push_spell(BOOK_GEOMANCY, GROW_BARRIER); + push_spell(BOOK_GEOMANCY, DRIPPING_TREAD); + push_spell(BOOK_GEOMANCY, GEOLYSIS); + push_spell(BOOK_GEOMANCY, VAPORIZE); + push_spell(BOOK_GEOMANCY, ELEMENTAL_WAVE); + push_spell(BOOK_GEOMANCY, CHANNEL_ELEMENTS); + push_spell(BOOK_GEOMANCY, CALL_THE_ELEMENTS); + + if (game_module_idx == MODULE_THEME) + { + /* Aule */ + push_spell(BOOK_AULE, AULE_CHILD); + push_spell(BOOK_AULE, AULE_ENCHANT_ARMOUR); + push_spell(BOOK_AULE, AULE_ENCHANT_WEAPON); + push_spell(BOOK_AULE, AULE_FIREBRAND); + + /* Varda */ + push_spell(BOOK_VARDA, VARDA_STARKINDLER); + push_spell(BOOK_VARDA, VARDA_EVENSTAR); + push_spell(BOOK_VARDA, VARDA_CALL_ALMAREN); + push_spell(BOOK_VARDA, VARDA_LIGHT_VALINOR); + + /* Ulmo */ + push_spell(BOOK_ULMO, ULMO_WRATH); + push_spell(BOOK_ULMO, ULMO_CALL_ULUMURI); + push_spell(BOOK_ULMO, ULMO_DRAUGHT_ULMONAN); + push_spell(BOOK_ULMO, ULMO_BELEGAER); + + /* Mandos */ + push_spell(BOOK_MANDOS, MANDOS_CALL_HALLS); + push_spell(BOOK_MANDOS, MANDOS_TALE_DOOM); + push_spell(BOOK_MANDOS, MANDOS_SPIRIT_FEANTURI); + push_spell(BOOK_MANDOS, MANDOS_TEARS_LUTHIEN); + } + + /* Random spell book; just initialize to anything */ + push_spell(BOOK_RANDOM, -1); +} + +void random_book_setup(s16b sval, s32b spell_idx) +{ + if (sval == BOOK_RANDOM) + { + school_book_type *school_book = school_books_at(sval); + + assert(school_book->spell_idx_list != NULL); + school_book->spell_idx_list->i = spell_idx; + } +} + +static cptr spell_school_name(s32b s) +{ + return string_exec_lua(format("return spell_school_name(%d)", s)); +} + +int print_spell(cptr label_, byte color, int y, s32b s) +{ + s32b level; + bool_ na; + cptr sch_str = spell_school_name(s); + cptr spell_info = get_spell_info(s); + cptr label = (label_ == NULL) ? "" : label_; + char level_str[8] = "n/a"; + char buf[128]; + + get_level_school(s, 50, -50, &level, &na); + + if (!na) + { + sprintf(level_str, "%3d", level); + } + + sprintf(buf, "%s%-20s%-16s %s %4d %3d%% %s", + label, + school_spells[s].name, + sch_str, + level_str, + get_mana(s), + spell_chance(s), + spell_info); + c_prt(color, buf, y, 0); + + return y + 1; +} + +int print_book(s16b sval, s32b pval, object_type *obj) +{ + int y = 2; + int i; + school_book_type *school_book; + spell_idx_list *spell_idx; + struct sglib_spell_idx_list_iterator it; + + random_book_setup(sval, pval); + + school_book = school_books_at(sval); + + /* Parse all spells */ + i = 0; + for (spell_idx = sglib_spell_idx_list_it_init(&it, school_book->spell_idx_list); + spell_idx != NULL; + spell_idx = sglib_spell_idx_list_it_next(&it)) + { + s32b s = spell_idx->i; + byte color = TERM_L_DARK; + int is_ok; + char label[8]; + + call_lua("is_ok_spell", "(d,O)", "d", s, obj, &is_ok); + if (is_ok) + { + color = (get_mana(s) > get_power(s)) ? TERM_ORANGE : TERM_L_GREEN; + } + + sprintf(label, "%c) ", 'a' + i); + + y = print_spell(label, color, y, s); + i++; + } + + prt(format(" %-20s%-16s Level Cost Fail Info", "Name", "School"), 1, 0); + return y; +} diff --git a/src/types.h b/src/types.h index 8d12fa68..ea8ca019 100644 --- a/src/types.h +++ b/src/types.h @@ -2469,6 +2469,23 @@ struct school_type }; /* + * Spell index list. + */ +typedef struct spell_idx_list spell_idx_list; +struct spell_idx_list { + s32b i; /* Spell index */ + spell_idx_list *next; /* for list */ +}; + +/* + * School book. + */ +typedef struct school_book_type school_book_type; +struct school_book_type { + spell_idx_list *spell_idx_list; +}; + +/* * Desc for GF_FOO */ typedef struct gf_name_type gf_name_type; |