summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-05-18 15:41:45 +0200
committerBardur Arantsson <bardur@scientician.net>2012-05-24 16:46:35 +0200
commit0b4fe745accdb743bc998e42282efb08c5b4ccd1 (patch)
treec7949a1b11a9535655b94eee4ed43105b37de535 /src
parentf7e4d1b4d9da8c42f02f79c0328477dd787fecd2 (diff)
Lua: Move handling of spell descriptions to C
Diffstat (limited to 'src')
-rw-r--r--src/cmd6.c54
-rw-r--r--src/externs.h2
-rw-r--r--src/object1.c19
-rw-r--r--src/spells.pkg1
-rw-r--r--src/spells4.c28
-rw-r--r--src/types.h1
6 files changed, 88 insertions, 17 deletions
diff --git a/src/cmd6.c b/src/cmd6.c
index 15790ca4..39483bbd 100644
--- a/src/cmd6.c
+++ b/src/cmd6.c
@@ -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;