diff options
-rw-r--r-- | lib/core/s_aux.lua | 35 | ||||
-rw-r--r-- | lib/mods/theme/core/s_aux.lua | 35 | ||||
-rw-r--r-- | lib/mods/theme/scpt/s_stick.lua | 4 | ||||
-rw-r--r-- | lib/scpt/s_stick.lua | 4 | ||||
-rw-r--r-- | src/cmd6.c | 54 | ||||
-rw-r--r-- | src/externs.h | 2 | ||||
-rw-r--r-- | src/object1.c | 19 | ||||
-rw-r--r-- | src/spells.pkg | 1 | ||||
-rw-r--r-- | src/spells4.c | 28 | ||||
-rw-r--r-- | src/types.h | 1 |
10 files changed, 100 insertions, 83 deletions
diff --git a/lib/core/s_aux.lua b/lib/core/s_aux.lua index 76f01637..b0c500a6 100644 --- a/lib/core/s_aux.lua +++ b/lib/core/s_aux.lua @@ -72,14 +72,16 @@ function finish_spell(must_i) spell(i).skill_level = s.level __spell_spell[i] = s.spell __spell_info[i] = s.info - __spell_desc[i] = s.desc + local j,desc + for j,desc in s.desc do + spell_description_add_line(i, desc) + end return i end -- Creates the school books array __spell_spell = {} __spell_info = {} -__spell_desc = {} __spell_school = {} -- Find a spell by name @@ -234,15 +236,6 @@ function spell_school_name(s) return sch_str end --- Output the desc when sued as a device -function print_device_desc(s) - local index, desc - - for index, desc in __spell_desc[s] do - text_out("\n" .. desc) - end -end - function check_affect(s, name, default) local s_ptr = __tmp_spells[s] local a @@ -389,26 +382,6 @@ function get_stick_charges(spl) return __tmp_spells[spl].stick.charge[1] + randint(__tmp_spells[spl].stick.charge[2]); end --- Get activation desc -function get_activation_desc(spl) - local turns - if type(__tmp_spells[spl].activate) == 'number' then - turns = __tmp_spells[spl].activate - else - turns = __tmp_spells[spl].activate[1] .. '+d' .. __tmp_spells[spl].activate[2] - end - return __tmp_spells[spl].desc[1] .. ' every ' .. turns .. ' turns' -end - --- Compute the timeout of an activation -function get_activation_timeout(spl) - if type(__tmp_spells[spl].activate) == 'number' then - return __tmp_spells[spl].activate - else - return __tmp_spells[spl].activate[1] + randint(__tmp_spells[spl].activate[2]) - end -end - -- Fire off the spell function activate_activation(spl, item) __spell_spell[spl](item) diff --git a/lib/mods/theme/core/s_aux.lua b/lib/mods/theme/core/s_aux.lua index 76f01637..b0c500a6 100644 --- a/lib/mods/theme/core/s_aux.lua +++ b/lib/mods/theme/core/s_aux.lua @@ -72,14 +72,16 @@ function finish_spell(must_i) spell(i).skill_level = s.level __spell_spell[i] = s.spell __spell_info[i] = s.info - __spell_desc[i] = s.desc + local j,desc + for j,desc in s.desc do + spell_description_add_line(i, desc) + end return i end -- Creates the school books array __spell_spell = {} __spell_info = {} -__spell_desc = {} __spell_school = {} -- Find a spell by name @@ -234,15 +236,6 @@ function spell_school_name(s) return sch_str end --- Output the desc when sued as a device -function print_device_desc(s) - local index, desc - - for index, desc in __spell_desc[s] do - text_out("\n" .. desc) - end -end - function check_affect(s, name, default) local s_ptr = __tmp_spells[s] local a @@ -389,26 +382,6 @@ function get_stick_charges(spl) return __tmp_spells[spl].stick.charge[1] + randint(__tmp_spells[spl].stick.charge[2]); end --- Get activation desc -function get_activation_desc(spl) - local turns - if type(__tmp_spells[spl].activate) == 'number' then - turns = __tmp_spells[spl].activate - else - turns = __tmp_spells[spl].activate[1] .. '+d' .. __tmp_spells[spl].activate[2] - end - return __tmp_spells[spl].desc[1] .. ' every ' .. turns .. ' turns' -end - --- Compute the timeout of an activation -function get_activation_timeout(spl) - if type(__tmp_spells[spl].activate) == 'number' then - return __tmp_spells[spl].activate - else - return __tmp_spells[spl].activate[1] + randint(__tmp_spells[spl].activate[2]) - end -end - -- Fire off the spell function activate_activation(spl, item) __spell_spell[spl](item) diff --git a/lib/mods/theme/scpt/s_stick.lua b/lib/mods/theme/scpt/s_stick.lua index 20d70856..554ca045 100644 --- a/lib/mods/theme/scpt/s_stick.lua +++ b/lib/mods/theme/scpt/s_stick.lua @@ -264,7 +264,7 @@ DEVICE_RADAGAST = add_spell ["mana_max"] = 0, ["fail"] = 10, ["random"] = -1, - ["activate"] = 15000, + ["activate"] = { 15000, 0 }, ["spell"] = function() return device_radagast() end, ["info"] = function() return device_radagast_info() end, ["desc"] = { @@ -281,7 +281,7 @@ DEVICE_VALAROMA = add_spell ["mana_max"] = 0, ["fail"] = 25, ["random"] = -1, - ["activate"] = 250, + ["activate"] = { 250, 0 }, ["spell"] = function() return device_valaroma() end, ["info"] = function() return device_valaroma_info() end, ["desc"] = { diff --git a/lib/scpt/s_stick.lua b/lib/scpt/s_stick.lua index 28abc0db..8075db2f 100644 --- a/lib/scpt/s_stick.lua +++ b/lib/scpt/s_stick.lua @@ -171,7 +171,7 @@ DEVICE_LEBOHAUM = add_spell ["mana_max"] = 0, ["fail"] = 0, ["random"] = -1, - ["activate"] = 3, + ["activate"] = { 3, 0 }, ["spell"] = function() return device_lebohaum() end, ["info"] = function() return device_lebohaum_info() end, ["desc"] = { @@ -253,7 +253,7 @@ DEVICE_DURANDIL = add_spell ["mana_max"] = 0, ["fail"] = 0, ["random"] = -1, - ["activate"] = 3, + ["activate"] = { 3, 0 }, ["spell"] = function() return device_durandil() end, ["info"] = function() return device_durandil_info() end, ["desc"] = { @@ -4989,9 +4989,58 @@ void do_cmd_activate(void) } +static void get_activation_duration(int spl, int *base, int *sides) +{ + assert(base != NULL); + assert(sides != NULL); + + *base = get_lua_int(format("__tmp_spells[%d].activate[1]", spl)); + if (*base <= 0) + { + base = 0; + } + + *sides = get_lua_int(format("__tmp_spells[%d].activate[2]", spl)); + if (*sides <= 0) + { + sides = 0; + } +} + +static void get_activation_desc(char *buf, int spl) +{ + spell_type *spell = &school_spells[spl]; + char turns[32]; + int base, sides; + + get_activation_duration(spl, &base, &sides); + + sprintf(turns, "%d", base); + if (sides > 0) + { + char buf[32]; + sprintf(buf, "+d%d", sides); + strcat(turns, buf); + } + + assert(spell->description != NULL); + assert(spell->description->s != NULL); + sprintf(buf, "%s every %s turns", + spell->description->s, + turns); +} + +static int get_activation_timeout(int spl) +{ + int base, sides; + get_activation_duration(spl, &base, &sides); + return base + randint(sides); +} + const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { + static char buf[256]; int plev = get_skill(SKILL_DEVICE); int i = 0, ii = 0, ij = 0, k, dir, dummy = 0; @@ -5034,11 +5083,12 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (doit) { call_lua("activate_activation", "(d,d)", "", -spell, item); - o_ptr->timeout = exec_lua(format("return get_activation_timeout(%d)", -spell)); + o_ptr->timeout = get_activation_timeout(-spell); } else { - return string_exec_lua(format("return get_activation_desc(%d)", -spell)); + get_activation_desc(buf, -spell); + return buf; } } else diff --git a/src/externs.h b/src/externs.h index e48b99cd..644d30b9 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1918,6 +1918,8 @@ 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); +void spell_description_add_line(s32b spell_idx, cptr line); + /* randart.c */ extern int get_activation_power(void); extern void build_prob(cptr learn); diff --git a/src/object1.c b/src/object1.c index 2be0984c..dac3085e 100644 --- a/src/object1.c +++ b/src/object1.c @@ -2824,6 +2824,23 @@ void display_ammo_damage(object_type *o_ptr) } /* + * Describe the device spell + */ +static void print_device_desc(int s) +{ + string_list *sl; + struct sglib_string_list_iterator it; + + for (sl = sglib_string_list_it_init(&it, school_spells[s].description); + sl != NULL; + sl = sglib_string_list_it_next(&it)) + { + text_out("\n"); + text_out(sl->s); + } +} + +/* * Describe a magic stick powers */ void describe_device(object_type *o_ptr) @@ -2837,7 +2854,7 @@ void describe_device(object_type *o_ptr) set_stick_mode(o_ptr); text_out("\nSpell description:"); - exec_lua(format("print_device_desc(%d)", o_ptr->pval2)); + print_device_desc(o_ptr->pval2); text_out("\nSpell level: "); text_out_c(TERM_L_BLUE, string_exec_lua(format("return tostring(get_level(%d, 50, 0))", o_ptr->pval2))); diff --git a/src/spells.pkg b/src/spells.pkg index c259f672..482708bc 100644 --- a/src/spells.pkg +++ b/src/spells.pkg @@ -2883,3 +2883,4 @@ void init_school_books(); extern s32b SCHOOL_UDUN; extern s32b SCHOOL_MELKOR; void lua_cast_school_spell @ cast_school_spell(s32b spell_idx, bool no_cost = FALSE); +void spell_description_add_line(s32b spell_idx, cptr line); diff --git a/src/spells4.c b/src/spells4.c index aa62d827..40cca814 100644 --- a/src/spells4.c +++ b/src/spells4.c @@ -63,24 +63,17 @@ s32b get_power(s32b s) /* Output the describtion when it is used as a spell */ void print_spell_desc(int s, int y) { - int i; + string_list *sl; + struct sglib_string_list_iterator it; - for (i=0; ; i++) + for (sl = sglib_string_list_it_init(&it, school_spells[s].description); + sl != NULL; + sl = sglib_string_list_it_next(&it)) { - 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); + c_prt(TERM_L_BLUE, sl->s, y, 0); y++; } - + if (uses_piety_to_cast(s)) { c_prt(TERM_L_WHITE, "It uses piety to cast.", y, 0); @@ -603,3 +596,10 @@ void lua_cast_school_spell(s32b s, bool_ no_cost) p_ptr->redraw |= PR_MANA; p_ptr->window |= PW_PLAYER; } + +void spell_description_add_line(s32b spell_idx, cptr line) +{ + string_list *e = malloc(sizeof(string_list)); + string_list_init(e, line); + sglib_string_list_add(&school_spells[spell_idx].description, e); +} diff --git a/src/types.h b/src/types.h index 3a408ed1..06634be5 100644 --- a/src/types.h +++ b/src/types.h @@ -2475,6 +2475,7 @@ struct spell_type byte mana_max; /* Required mana at max lvl */ s16b fail; /* Minimum chance of failure */ s16b level; /* Spell level(0 = not learnt) */ + string_list *description; /* List of strings */ }; typedef struct school_type school_type; |