summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mods/theme/scpt/s_udun.lua83
-rw-r--r--lib/scpt/s_udun.lua83
-rw-r--r--src/cmd2.c4
-rw-r--r--src/externs.h16
-rw-r--r--src/spells.pkg14
-rw-r--r--src/spells3.c152
6 files changed, 201 insertions, 151 deletions
diff --git a/lib/mods/theme/scpt/s_udun.lua b/lib/mods/theme/scpt/s_udun.lua
index c4266239..3ddfeb14 100644
--- a/lib/mods/theme/scpt/s_udun.lua
+++ b/lib/mods/theme/scpt/s_udun.lua
@@ -8,49 +8,8 @@ DRAIN = add_spell
["mana"] = 0,
["mana_max"] = 0,
["fail"] = 20,
- ["spell"] = function()
- local ret, item, obj, o_name, add
-
- -- Ask for an item
- ret, item = get_item("What item to drain?", "You have nothing you can drain", USE_INVEN,
- function (obj)
- if (obj.tval == TV_WAND) or (obj.tval == TV_ROD_MAIN) or (obj.tval == TV_STAFF) then
- return TRUE
- end
- return FALSE
- end
- )
-
- if ret == TRUE then
- -- get the item
- obj = get_object(item)
-
- add = 0
- if (obj.tval == TV_STAFF) or (obj.tval == TV_WAND) then
- local kind = get_kind(obj)
-
- add = kind.level * obj.pval * obj.number
-
- -- Destroy it!
- inven_item_increase(item, -99)
- inven_item_describe(item)
- inven_item_optimize(item)
- end
- if obj.tval == TV_ROD_MAIN then
- add = obj.timeout
- obj.timeout = 0;
-
- --Combine / Reorder the pack (later)
- player.notice = bor(player.notice, PN_COMBINE, PN_REORDER)
- player.window = bor(player.window, PW_INVEN, PW_EQUIP, PW_PLAYER)
- end
- increase_mana(add)
- end
- return TRUE
- end,
- ["info"] = function()
- return ""
- end,
+ ["spell"] = function() return udun_drain() end,
+ ["info"] = function() return udun_drain_info() end,
["desc"] = {
"Drains the mana contained in wands, staves and rods to increase yours",
}
@@ -74,26 +33,8 @@ GENOCIDE = add_spell
["max_level"] = { 5, 15 },
},
},
- ["spell"] = function()
- local type
-
- type = 0
- if get_level(GENOCIDE) >= 10 then type = 1 end
- if type == 0 then
- genocide(TRUE)
- return TRUE
- else
- if get_check("Genocide all monsters near you? ") == TRUE then
- mass_genocide(TRUE)
- else
- genocide(TRUE)
- end
- return TRUE
- end
- end,
- ["info"] = function()
- return ""
- end,
+ ["spell"] = function() return udun_genocide() end,
+ ["info"] = function() return udun_genocide_info() end,
["desc"] = {
"Genocides all monsters of a race on the level",
"At level 10 it can genocide all monsters near you"
@@ -109,12 +50,8 @@ WRAITHFORM = add_spell
["mana_max"] = 40,
["fail"] = 95,
["inertia"] = { 4, 30 },
- ["spell"] = function()
- return set_shadow(randint(30) + 20 + get_level(WRAITHFORM, 40))
- end,
- ["info"] = function()
- return "dur "..(20 + get_level(WRAITHFORM, 40)).."+d30"
- end,
+ ["spell"] = function() return udun_wraithform() end,
+ ["info"] = function() return udun_wraithform_info() end,
["desc"] = {
"Turns you into an immaterial being",
}
@@ -129,12 +66,8 @@ FLAMEOFUDUN = add_spell
["mana_max"] = 100,
["fail"] = 95,
["inertia"] = { 7, 15 },
- ["spell"] = function()
- return set_mimic(randint(15) + 5 + get_level(FLAMEOFUDUN, 30), resolve_mimic_name("Balrog"), get_level(FLAMEOFUDUN))
- end,
- ["info"] = function()
- return "dur "..(5 + get_level(FLAMEOFUDUN, 30)).."+d15"
- end,
+ ["spell"] = function() return udun_flame_of_udun() end,
+ ["info"] = function() return udun_flame_of_udun_info() end,
["desc"] = {
"Turns you into a powerful Balrog",
}
diff --git a/lib/scpt/s_udun.lua b/lib/scpt/s_udun.lua
index c4266239..3ddfeb14 100644
--- a/lib/scpt/s_udun.lua
+++ b/lib/scpt/s_udun.lua
@@ -8,49 +8,8 @@ DRAIN = add_spell
["mana"] = 0,
["mana_max"] = 0,
["fail"] = 20,
- ["spell"] = function()
- local ret, item, obj, o_name, add
-
- -- Ask for an item
- ret, item = get_item("What item to drain?", "You have nothing you can drain", USE_INVEN,
- function (obj)
- if (obj.tval == TV_WAND) or (obj.tval == TV_ROD_MAIN) or (obj.tval == TV_STAFF) then
- return TRUE
- end
- return FALSE
- end
- )
-
- if ret == TRUE then
- -- get the item
- obj = get_object(item)
-
- add = 0
- if (obj.tval == TV_STAFF) or (obj.tval == TV_WAND) then
- local kind = get_kind(obj)
-
- add = kind.level * obj.pval * obj.number
-
- -- Destroy it!
- inven_item_increase(item, -99)
- inven_item_describe(item)
- inven_item_optimize(item)
- end
- if obj.tval == TV_ROD_MAIN then
- add = obj.timeout
- obj.timeout = 0;
-
- --Combine / Reorder the pack (later)
- player.notice = bor(player.notice, PN_COMBINE, PN_REORDER)
- player.window = bor(player.window, PW_INVEN, PW_EQUIP, PW_PLAYER)
- end
- increase_mana(add)
- end
- return TRUE
- end,
- ["info"] = function()
- return ""
- end,
+ ["spell"] = function() return udun_drain() end,
+ ["info"] = function() return udun_drain_info() end,
["desc"] = {
"Drains the mana contained in wands, staves and rods to increase yours",
}
@@ -74,26 +33,8 @@ GENOCIDE = add_spell
["max_level"] = { 5, 15 },
},
},
- ["spell"] = function()
- local type
-
- type = 0
- if get_level(GENOCIDE) >= 10 then type = 1 end
- if type == 0 then
- genocide(TRUE)
- return TRUE
- else
- if get_check("Genocide all monsters near you? ") == TRUE then
- mass_genocide(TRUE)
- else
- genocide(TRUE)
- end
- return TRUE
- end
- end,
- ["info"] = function()
- return ""
- end,
+ ["spell"] = function() return udun_genocide() end,
+ ["info"] = function() return udun_genocide_info() end,
["desc"] = {
"Genocides all monsters of a race on the level",
"At level 10 it can genocide all monsters near you"
@@ -109,12 +50,8 @@ WRAITHFORM = add_spell
["mana_max"] = 40,
["fail"] = 95,
["inertia"] = { 4, 30 },
- ["spell"] = function()
- return set_shadow(randint(30) + 20 + get_level(WRAITHFORM, 40))
- end,
- ["info"] = function()
- return "dur "..(20 + get_level(WRAITHFORM, 40)).."+d30"
- end,
+ ["spell"] = function() return udun_wraithform() end,
+ ["info"] = function() return udun_wraithform_info() end,
["desc"] = {
"Turns you into an immaterial being",
}
@@ -129,12 +66,8 @@ FLAMEOFUDUN = add_spell
["mana_max"] = 100,
["fail"] = 95,
["inertia"] = { 7, 15 },
- ["spell"] = function()
- return set_mimic(randint(15) + 5 + get_level(FLAMEOFUDUN, 30), resolve_mimic_name("Balrog"), get_level(FLAMEOFUDUN))
- end,
- ["info"] = function()
- return "dur "..(5 + get_level(FLAMEOFUDUN, 30)).."+d15"
- end,
+ ["spell"] = function() return udun_flame_of_udun() end,
+ ["info"] = function() return udun_flame_of_udun_info() end,
["desc"] = {
"Turns you into a powerful Balrog",
}
diff --git a/src/cmd2.c b/src/cmd2.c
index 8c602db3..828cbc35 100644
--- a/src/cmd2.c
+++ b/src/cmd2.c
@@ -4565,8 +4565,10 @@ static bool_ item_tester_hook_sacrifiable(object_type *o_ptr)
return (TRUE);
/* Books without any udun spells */
- if ((o_ptr->tval == TV_BOOK) && (exec_lua(format("return udun_in_book(%d, %d)", o_ptr->sval, o_ptr->pval)) == 0))
+ if ((o_ptr->tval == TV_BOOK) && udun_in_book(o_ptr->sval, o_ptr->pval) <= 0)
+ {
return TRUE;
+ }
}
/* Assume not */
diff --git a/src/externs.h b/src/externs.h
index dd83e876..4395848e 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -1666,6 +1666,22 @@ char *tulkas_wave_of_power_info();
bool_ *tulkas_whirlwind();
char *tulkas_whirlwind_info();
+extern s32b DRAIN;
+extern s32b GENOCIDE;
+extern s32b WRAITHFORM;
+extern s32b FLAMEOFUDUN;
+
+int udun_in_book(s32b sval, s32b pval);
+
+bool_ *udun_drain();
+char *udun_drain_info();
+bool_ *udun_genocide();
+char *udun_genocide_info();
+bool_ *udun_wraithform();
+char *udun_wraithform_info();
+bool_ *udun_flame_of_udun();
+char *udun_flame_of_udun_info();
+
/* randart.c */
extern int get_activation_power(void);
extern void build_prob(cptr learn);
diff --git a/src/spells.pkg b/src/spells.pkg
index 3b7ce060..034f2cd4 100644
--- a/src/spells.pkg
+++ b/src/spells.pkg
@@ -2671,3 +2671,17 @@ bool_ *tulkas_wave_of_power();
char *tulkas_wave_of_power_info();
bool_ *tulkas_whirlwind();
char *tulkas_whirlwind_info();
+
+extern s32b DRAIN;
+extern s32b GENOCIDE;
+extern s32b WRAITHFORM;
+extern s32b FLAMEOFUDUN;
+
+bool_ *udun_drain();
+char *udun_drain_info();
+bool_ *udun_genocide();
+char *udun_genocide_info();
+bool_ *udun_wraithform();
+char *udun_wraithform_info();
+bool_ *udun_flame_of_udun();
+char *udun_flame_of_udun_info();
diff --git a/src/spells3.c b/src/spells3.c
index 6220cd25..39517b5e 100644
--- a/src/spells3.c
+++ b/src/spells3.c
@@ -94,6 +94,11 @@ s32b TULKAS_AIM;
s32b TULKAS_WAVE;
s32b TULKAS_SPIN;
+s32b DRAIN;
+s32b GENOCIDE;
+s32b WRAITHFORM;
+s32b FLAMEOFUDUN;
+
/* FIXME: Hackish workaround while we're still tied to Lua. This lets
us return Lua's "nil" and a non-nil value (which is all the s_aux.lua
@@ -2835,3 +2840,150 @@ char *tulkas_whirlwind_info()
{
return "";
}
+
+/* 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);
+}
+
+static bool_ udun_object_is_drainable(object_type *o_ptr)
+{
+ return ((o_ptr->tval == TV_WAND) ||
+ (o_ptr->tval == TV_ROD_MAIN) ||
+ (o_ptr->tval == TV_STAFF));
+}
+
+bool_ *udun_drain()
+{
+ int item;
+ object_type *o_ptr = NULL;
+
+ /* Ask for an item */
+ item_tester_hook = udun_object_is_drainable;
+ if (!get_item(&item,
+ "What item to drain?",
+ "You have nothing you can drain",
+ USE_INVEN))
+ {
+ return NO_CAST;
+ }
+
+ /* Drain */
+
+ /* get the item */
+ o_ptr = get_object(item);
+
+ switch (o_ptr->tval)
+ {
+ case TV_STAFF:
+ case TV_WAND:
+ {
+ object_kind *k_ptr = &k_info[o_ptr->k_idx];
+
+ /* Generate mana */
+ increase_mana(o_ptr->pval * k_ptr->level * o_ptr->number);
+
+ /* Destroy it */
+ inc_stack_size(item, -99);
+
+ break;
+ }
+
+ case TV_ROD_MAIN:
+ {
+ /* Generate mana */
+ increase_mana(o_ptr->timeout);
+
+ /* Drain it */
+ o_ptr->timeout = 0;
+
+ /* Combine / Reorder the pack (later) */
+ p_ptr->notice |= PN_COMBINE | PN_REORDER;
+ p_ptr->window |= PW_INVEN | PW_EQUIP | PW_PLAYER;
+ break;
+ }
+
+ default:
+ assert(FALSE);
+ }
+
+ return CAST;
+}
+
+char *udun_drain_info()
+{
+ return "";
+}
+
+bool_ *udun_genocide()
+{
+ if (get_level_s(GENOCIDE, 50) < 10)
+ {
+ genocide(TRUE);
+ }
+ else
+ {
+ if (get_check("Genocide all monsters near you? "))
+ {
+ mass_genocide(TRUE);
+ }
+ else
+ {
+ genocide(TRUE);
+ }
+ }
+
+ return CAST;
+}
+
+char *udun_genocide_info()
+{
+ return "";
+}
+
+static int udun_wraithform_base_duration()
+{
+ return 20 + get_level_s(WRAITHFORM, 40);
+}
+
+bool_ *udun_wraithform()
+{
+ set_shadow(randint(30) + udun_wraithform_base_duration());
+ return CAST;
+}
+
+char *udun_wraithform_info()
+{
+ static char buf[128];
+ sprintf(buf,
+ "dur %d+d30",
+ udun_wraithform_base_duration());
+ return buf;
+}
+
+static int udun_flame_of_udun_base_duration()
+{
+ return 5 + get_level_s(FLAMEOFUDUN, 30);
+}
+
+bool_ *udun_flame_of_udun()
+{
+ set_mimic(randint(15) + udun_flame_of_udun_base_duration(),
+ resolve_mimic_name("Balrog"),
+ get_level_s(FLAMEOFUDUN, 50));
+ return CAST;
+}
+
+char *udun_flame_of_udun_info()
+{
+ static char buf[128];
+ sprintf(buf,
+ "dur %d+d15",
+ udun_flame_of_udun_base_duration());
+ return buf;
+}
+