diff options
-rw-r--r-- | lib/core/s_aux.lua | 50 | ||||
-rw-r--r-- | lib/mods/theme/core/s_aux.lua | 50 | ||||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/cmd5.c | 20 | ||||
-rw-r--r-- | src/externs.h | 3 | ||||
-rw-r--r-- | src/lua_bind.c | 4 | ||||
-rw-r--r-- | src/q_library.c | 6 | ||||
-rw-r--r-- | src/spells4.c | 62 |
8 files changed, 91 insertions, 106 deletions
diff --git a/lib/core/s_aux.lua b/lib/core/s_aux.lua index 97643626..6cdcbd82 100644 --- a/lib/core/s_aux.lua +++ b/lib/core/s_aux.lua @@ -300,42 +300,12 @@ function print_book(book, spl, obj) return y end --- Output the describtion when it is used as a spell -function print_spell_desc(s, y) - local index, desc, x - - x = 0 - - if type(__spell_desc[s]) == "string" then c_prt(TERM_L_BLUE, __spell_desc[s], y, x) - else - for index, desc in __spell_desc[s] do - c_prt(TERM_L_BLUE, desc, y, x) - y = y + 1 - end - end - if check_affect(s, "piety", FALSE) then - c_prt(TERM_L_WHITE, "It uses piety to cast.", y, x) - y = y + 1 - end - if not check_affect(s, "blind") then - c_prt(TERM_ORANGE, "It is castable even while blinded.", y, x) - y = y + 1 - end - if not check_affect(s, "confusion") then - c_prt(TERM_ORANGE, "It is castable even while confused.", y, x) - y = y + 1 - end -end - -- Output the desc when sued as a device function print_device_desc(s) local index, desc - if type(__spell_desc[s]) == "string" then text_out(__spell_desc[s]) - else - for index, desc in __spell_desc[s] do - text_out("\n" .. desc) - end + for index, desc in __spell_desc[s] do + text_out("\n" .. desc) end end @@ -356,22 +326,6 @@ function book_spells_num(book) return size end -function spell_x(book, spl, s) - if book == 255 then - return spl - else - local i, x, val - - i, val = next(school_book[book], nil) - x = 0 - while x < s do - i, val = next(school_book[book], i) - x = x + 1 - end - return val - end -end - function spell_in_book(book, spell) local i, s diff --git a/lib/mods/theme/core/s_aux.lua b/lib/mods/theme/core/s_aux.lua index 97643626..6cdcbd82 100644 --- a/lib/mods/theme/core/s_aux.lua +++ b/lib/mods/theme/core/s_aux.lua @@ -300,42 +300,12 @@ function print_book(book, spl, obj) return y end --- Output the describtion when it is used as a spell -function print_spell_desc(s, y) - local index, desc, x - - x = 0 - - if type(__spell_desc[s]) == "string" then c_prt(TERM_L_BLUE, __spell_desc[s], y, x) - else - for index, desc in __spell_desc[s] do - c_prt(TERM_L_BLUE, desc, y, x) - y = y + 1 - end - end - if check_affect(s, "piety", FALSE) then - c_prt(TERM_L_WHITE, "It uses piety to cast.", y, x) - y = y + 1 - end - if not check_affect(s, "blind") then - c_prt(TERM_ORANGE, "It is castable even while blinded.", y, x) - y = y + 1 - end - if not check_affect(s, "confusion") then - c_prt(TERM_ORANGE, "It is castable even while confused.", y, x) - y = y + 1 - end -end - -- Output the desc when sued as a device function print_device_desc(s) local index, desc - if type(__spell_desc[s]) == "string" then text_out(__spell_desc[s]) - else - for index, desc in __spell_desc[s] do - text_out("\n" .. desc) - end + for index, desc in __spell_desc[s] do + text_out("\n" .. desc) end end @@ -356,22 +326,6 @@ function book_spells_num(book) return size end -function spell_x(book, spl, s) - if book == 255 then - return spl - else - local i, x, val - - i, val = next(school_book[book], nil) - x = 0 - while x < s do - i, val = next(school_book[book], i) - x = x + 1 - end - return val - end -end - function spell_in_book(book, spell) local i, s diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 18975f17..b286a477 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,7 @@ SET(SRCS object1.c object2.c randart.c squeltch.c traps.c monster1.c monster2.c monster3.c xtra1.c xtra2.c skills.c powers.c gods.c - spells1.c spells2.c spells3.c corrupt.c mimic.c + spells1.c spells2.c spells3.c spells4.c corrupt.c mimic.c status.c files.c notes.c loadsave.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c help.c @@ -17,6 +17,20 @@ 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); + } +} + /* Maximum number of tries for teleporting */ #define MAX_TRIES 300 @@ -2327,14 +2341,14 @@ 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); - exec_lua(format("print_spell_desc(spell_x(%d, %d, %d), %d)", sval, pval, i, where)); + print_spell_desc(spell_x(sval, pval, i), where); } else { s32b ok; /* Save the spell index */ - spell = exec_lua(format("return spell_x(%d, %d, %d)", sval, pval, i)); + spell = spell_x(sval, pval, i); /* Do we need to do some pre test */ call_lua(check_fct, "(d,O)", "d", spell, o_ptr, &ok); @@ -2479,7 +2493,7 @@ void browse_school_spell(int book, int pval, object_type *o_ptr) /* Display a list of spells */ call_lua("print_book", "(d,d,O)", "d", book, pval, o_ptr, &where); - exec_lua(format("print_spell_desc(spell_x(%d, %d, %d), %d)", book, pval, i, where)); + print_spell_desc(spell_x(book, pval, i), where); } diff --git a/src/externs.h b/src/externs.h index f19e2db8..0b7b2575 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1898,6 +1898,9 @@ char *varda_evenstar_info(); bool_ *varda_star_kindler_spell(); char *varda_star_kindler_info(); +/* spells4.c */ +void print_spell_desc(int s, int y); + /* randart.c */ extern int get_activation_power(void); extern void build_prob(cptr learn); diff --git a/src/lua_bind.c b/src/lua_bind.c index 67073061..409e005d 100644 --- a/src/lua_bind.c +++ b/src/lua_bind.c @@ -539,7 +539,9 @@ void lua_display_list(int y, int x, int h, int w, cptr title, list_type* list, i int get_lua_int(cptr name) { - return exec_lua(format("return %s", name)); + char buf[128]; + sprintf(buf, "return %s", name); + return exec_lua(buf); } void increase_mana(int delta) diff --git a/src/q_library.c b/src/q_library.c index 7ccbd9cf..0c4ad5e3 100644 --- a/src/q_library.c +++ b/src/q_library.c @@ -140,10 +140,6 @@ 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 int library_quest_print_spell_desc(int s, int y) { - return exec_lua(format("print_spell_desc(%d, %d)", s, y)); -} - static void quest_library_finalize_book() { int i = 0; @@ -270,7 +266,7 @@ static void library_quest_fill_book() } else if (ch == 'p') { current = current - height; } else if (ch == 'I') { - library_quest_print_spell_desc(spell_idx, 0); + print_spell_desc(spell_idx, 0); inkey(); } else if (dir == 2) { current = current + 1; diff --git a/src/spells4.c b/src/spells4.c new file mode 100644 index 00000000..7f59d186 --- /dev/null +++ b/src/spells4.c @@ -0,0 +1,62 @@ +#include "angband.h" + +#include <assert.h> + +static bool_ uses_piety_to_cast(int s) +{ + char buf[128]; + sprintf(buf, "return check_affect(%d, \"piety\", FALSE)", s); + return exec_lua(buf); +} + +static bool_ castable_while_blind(int s) +{ + char buf[128]; + sprintf(buf, "return not check_affect(%d, \"blind\")", s); + return exec_lua(buf); +} + +static bool_ castable_while_confused(int s) +{ + char buf[128]; + sprintf(buf, "return not check_affect(%d, \"confusion\")", s); + return exec_lua(buf); +} + +/* Output the describtion when it is used as a spell */ +void print_spell_desc(int s, int y) +{ + int i; + + for (i=0; ; i++) + { + char buf[128]; + cptr desc = NULL; + + sprintf(buf, "return __spell_desc[%d][%d]", s, i+1); + desc = string_exec_lua(buf); + if (!desc) + { + break; + } + + c_prt(TERM_L_BLUE, desc, y, 0); + y++; + } + + if (uses_piety_to_cast(s)) + { + c_prt(TERM_L_WHITE, "It uses piety to cast.", y, 0); + y++; + } + if (castable_while_blind(s)) + { + c_prt(TERM_ORANGE, "It is castable even while blinded.", y, 0); + y++; + } + if (castable_while_confused(s)) + { + c_prt(TERM_ORANGE, "It is castable even while confused.", y, 0); + y++; + } +} |