From 58c866837fda7ba06e465f45fbf68eafe921db86 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 19 Apr 2012 23:18:15 +0200 Subject: Lua: Move 'Manwe' spell functions to C --- lib/mods/theme/scpt/s_manwe.lua | 76 +++------------------- lib/scpt/s_manwe.lua | 76 +++------------------- src/externs.h | 14 ++++ src/spells.pkg | 14 ++++ src/spells3.c | 138 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+), 136 deletions(-) diff --git a/lib/mods/theme/scpt/s_manwe.lua b/lib/mods/theme/scpt/s_manwe.lua index 6f0f9661..189f50ff 100644 --- a/lib/mods/theme/scpt/s_manwe.lua +++ b/lib/mods/theme/scpt/s_manwe.lua @@ -12,33 +12,8 @@ MANWE_SHIELD = add_spell ["piety"] = TRUE, ["stat"] = A_WIS, ["random"] = SKILL_SPIRITUALITY, - ["spell"] = function() - local dur = get_level(MANWE_SHIELD, 50) + 10 + randint(20) - local obvious - - obvious = set_protevil(dur) - if get_level(MANWE_SHIELD) >= 10 then - local type - - type = 0 - if get_level(MANWE_SHIELD) >= 20 then - type = SHIELD_COUNTER - end - obvious = is_obvious(set_shield(dur, get_level(MANWE_SHIELD, 30), type, 1 + get_level(MANWE_SHIELD, 2), 1 + get_level(MANWE_SHIELD, 6)), obvious) - end - return obvious - end, - ["info"] = function() - local desc = "dur "..(get_level(MANWE_SHIELD, 50) + 10).."+d20" - - if get_level(MANWE_SHIELD) >= 10 then - desc = desc.." AC "..(get_level(MANWE_SHIELD, 30)) - end - if get_level(MANWE_SHIELD) >= 20 then - desc = desc.." dam "..(1 + get_level(MANWE_SHIELD, 2)).."d"..(1 + get_level(MANWE_SHIELD, 6)) - end - return desc - end, + ["spell"] = function() return manwe_wind_shield() end, + ["info"] = function() return manwe_wind_shield_info() end, ["desc"] = { "It surrounds you with a shield of wind that deflects blows from evil monsters", "At level 10 it increases your armour rating", @@ -58,12 +33,8 @@ MANWE_AVATAR = add_spell ["piety"] = TRUE, ["stat"] = A_WIS, ["random"] = SKILL_SPIRITUALITY, - ["spell"] = function() - return set_mimic(get_level(MANWE_AVATAR, 20) + randint(10), resolve_mimic_name("Maia"), player.lev) - end, - ["info"] = function() - return "dur "..(get_level(MANWE_AVATAR, 20)).."+d10" - end, + ["spell"] = function() return manwe_avatar() end, + ["info"] = function() return manwe_avatar_info() end, ["desc"] = { "It turns you into a full grown Maia", } @@ -81,27 +52,8 @@ MANWE_BLESS = add_spell ["piety"] = TRUE, ["stat"] = A_WIS, ["random"] = SKILL_SPIRITUALITY, - ["spell"] = function() - local dur = get_level(MANWE_BLESS, 70) + 30 + randint(40) - local obvious - - obvious = set_blessed(dur) - obvious = is_obvious(set_afraid(0), obvious) - obvious = is_obvious(set_lite(0), obvious) - if get_level(MANWE_BLESS) >= 10 then - obvious = is_obvious(set_hero(dur), obvious) - end - if get_level(MANWE_BLESS) >= 20 then - obvious = is_obvious(set_shero(dur), obvious) - end - if get_level(MANWE_BLESS) >= 30 then - obvious = is_obvious(set_holy(dur), obvious) - end - return obvious - end, - ["info"] = function() - return "dur "..(get_level(MANWE_BLESS, 70) + 30).."+d40" - end, + ["spell"] = function() return manwe_blessing() end, + ["info"] = function() return manwe_blessing_info() end, ["desc"] = { "Manwe's Blessing removes your fears, blesses you and surrounds you with", "holy light", @@ -123,20 +75,8 @@ MANWE_CALL = add_spell ["piety"] = TRUE, ["stat"] = A_WIS, ["random"] = SKILL_SPIRITUALITY, - ["spell"] = function() - local y, x, m_idx - - y, x = find_position(player.py, player.px) - m_idx = place_monster_one(y, x, test_monster_name("Great eagle"), 0, FALSE, MSTATUS_FRIEND) - - if m_idx ~= 0 then - monster_set_level(m_idx, 20 + get_level(MANWE_CALL, 70, 0)) - return TRUE - end - end, - ["info"] = function() - return "level "..(get_level(MANWE_CALL, 70) + 20) - end, + ["spell"] = function() return manwe_call() end, + ["info"] = function() return manwe_call_info() end, ["desc"] = { "Manwe's Call summons a Great Eagle to help you battle the forces", "of Morgoth" diff --git a/lib/scpt/s_manwe.lua b/lib/scpt/s_manwe.lua index 6f0f9661..189f50ff 100644 --- a/lib/scpt/s_manwe.lua +++ b/lib/scpt/s_manwe.lua @@ -12,33 +12,8 @@ MANWE_SHIELD = add_spell ["piety"] = TRUE, ["stat"] = A_WIS, ["random"] = SKILL_SPIRITUALITY, - ["spell"] = function() - local dur = get_level(MANWE_SHIELD, 50) + 10 + randint(20) - local obvious - - obvious = set_protevil(dur) - if get_level(MANWE_SHIELD) >= 10 then - local type - - type = 0 - if get_level(MANWE_SHIELD) >= 20 then - type = SHIELD_COUNTER - end - obvious = is_obvious(set_shield(dur, get_level(MANWE_SHIELD, 30), type, 1 + get_level(MANWE_SHIELD, 2), 1 + get_level(MANWE_SHIELD, 6)), obvious) - end - return obvious - end, - ["info"] = function() - local desc = "dur "..(get_level(MANWE_SHIELD, 50) + 10).."+d20" - - if get_level(MANWE_SHIELD) >= 10 then - desc = desc.." AC "..(get_level(MANWE_SHIELD, 30)) - end - if get_level(MANWE_SHIELD) >= 20 then - desc = desc.." dam "..(1 + get_level(MANWE_SHIELD, 2)).."d"..(1 + get_level(MANWE_SHIELD, 6)) - end - return desc - end, + ["spell"] = function() return manwe_wind_shield() end, + ["info"] = function() return manwe_wind_shield_info() end, ["desc"] = { "It surrounds you with a shield of wind that deflects blows from evil monsters", "At level 10 it increases your armour rating", @@ -58,12 +33,8 @@ MANWE_AVATAR = add_spell ["piety"] = TRUE, ["stat"] = A_WIS, ["random"] = SKILL_SPIRITUALITY, - ["spell"] = function() - return set_mimic(get_level(MANWE_AVATAR, 20) + randint(10), resolve_mimic_name("Maia"), player.lev) - end, - ["info"] = function() - return "dur "..(get_level(MANWE_AVATAR, 20)).."+d10" - end, + ["spell"] = function() return manwe_avatar() end, + ["info"] = function() return manwe_avatar_info() end, ["desc"] = { "It turns you into a full grown Maia", } @@ -81,27 +52,8 @@ MANWE_BLESS = add_spell ["piety"] = TRUE, ["stat"] = A_WIS, ["random"] = SKILL_SPIRITUALITY, - ["spell"] = function() - local dur = get_level(MANWE_BLESS, 70) + 30 + randint(40) - local obvious - - obvious = set_blessed(dur) - obvious = is_obvious(set_afraid(0), obvious) - obvious = is_obvious(set_lite(0), obvious) - if get_level(MANWE_BLESS) >= 10 then - obvious = is_obvious(set_hero(dur), obvious) - end - if get_level(MANWE_BLESS) >= 20 then - obvious = is_obvious(set_shero(dur), obvious) - end - if get_level(MANWE_BLESS) >= 30 then - obvious = is_obvious(set_holy(dur), obvious) - end - return obvious - end, - ["info"] = function() - return "dur "..(get_level(MANWE_BLESS, 70) + 30).."+d40" - end, + ["spell"] = function() return manwe_blessing() end, + ["info"] = function() return manwe_blessing_info() end, ["desc"] = { "Manwe's Blessing removes your fears, blesses you and surrounds you with", "holy light", @@ -123,20 +75,8 @@ MANWE_CALL = add_spell ["piety"] = TRUE, ["stat"] = A_WIS, ["random"] = SKILL_SPIRITUALITY, - ["spell"] = function() - local y, x, m_idx - - y, x = find_position(player.py, player.px) - m_idx = place_monster_one(y, x, test_monster_name("Great eagle"), 0, FALSE, MSTATUS_FRIEND) - - if m_idx ~= 0 then - monster_set_level(m_idx, 20 + get_level(MANWE_CALL, 70, 0)) - return TRUE - end - end, - ["info"] = function() - return "level "..(get_level(MANWE_CALL, 70) + 20) - end, + ["spell"] = function() return manwe_call() end, + ["info"] = function() return manwe_call_info() end, ["desc"] = { "Manwe's Call summons a Great Eagle to help you battle the forces", "of Morgoth" diff --git a/src/externs.h b/src/externs.h index 295b008e..e46e864f 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1578,6 +1578,20 @@ char *mana_elemental_shield_info(); bool_ *mana_disruption_shield(); char *mana_disruption_shield_info(); +extern s32b MANWE_SHIELD; +extern s32b MANWE_AVATAR; +extern s32b MANWE_BLESS; +extern s32b MANWE_CALL; + +bool_ *manwe_wind_shield(); +char *manwe_wind_shield_info(); +bool_ *manwe_avatar(); +char *manwe_avatar_info(); +bool_ *manwe_blessing(); +char *manwe_blessing_info(); +bool_ *manwe_call(); +char *manwe_call_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 458fdc49..0d9d5613 100644 --- a/src/spells.pkg +++ b/src/spells.pkg @@ -2622,3 +2622,17 @@ bool_ *mana_elemental_shield(); char *mana_elemental_shield_info(); bool_ *mana_disruption_shield(); char *mana_disruption_shield_info(); + +extern s32b MANWE_SHIELD; +extern s32b MANWE_AVATAR; +extern s32b MANWE_BLESS; +extern s32b MANWE_CALL; + +bool_ *manwe_wind_shield(); +char *manwe_wind_shield_info(); +bool_ *manwe_avatar(); +char *manwe_avatar_info(); +bool_ *manwe_blessing(); +char *manwe_blessing_info(); +bool_ *manwe_call(); +char *manwe_call_info(); diff --git a/src/spells3.c b/src/spells3.c index d9b36410..db183ee0 100644 --- a/src/spells3.c +++ b/src/spells3.c @@ -1,5 +1,7 @@ #include "angband.h" +#include + s32b NOXIOUSCLOUD = -1; /* Identifier */ s32b AIRWINGS = -1; /* Identifier */ s32b INVISIBILITY; @@ -62,6 +64,11 @@ s32b DELCURSES; s32b RESISTS; s32b MANASHIELD; +s32b MANWE_SHIELD; +s32b MANWE_AVATAR; +s32b MANWE_BLESS; +s32b MANWE_CALL; + /* 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 cares about). */ @@ -1823,3 +1830,134 @@ char *mana_disruption_shield_info() return buf; } +bool_ *manwe_wind_shield() +{ + s32b dur = get_level_s(MANWE_SHIELD, 50) + 10 + randint(20); + + set_protevil(dur); + if (get_level_s(MANWE_SHIELD, 50) >= 10) + { + int type = 0; + if (get_level_s(MANWE_SHIELD, 50) >= 20) + { + type = SHIELD_COUNTER; + } + + set_shield(dur, + get_level_s(MANWE_SHIELD, 30), + type, + 1 + get_level_s(MANWE_SHIELD, 2), + 1 + get_level_s(MANWE_SHIELD, 6)); + } + + return CAST; +} + +char *manwe_wind_shield_info() +{ + static char buf[128]; + + sprintf(buf, + "dur %d+d20", + (get_level_s(MANWE_SHIELD, 50) + 10)); + + if (get_level_s(MANWE_SHIELD, 50) >= 10) + { + char tmp[128]; + sprintf(tmp, " AC %d", get_level_s(MANWE_SHIELD, 30)); + strcat(buf, tmp); + } + + if (get_level_s(MANWE_SHIELD, 50) >= 20) + { + char tmp[128]; + sprintf(tmp, " dam %dd%d", + (1 + get_level_s(MANWE_SHIELD, 2)), + (1 + get_level_s(MANWE_SHIELD, 6))); + strcat(buf, tmp); + } + + return buf; +} + +bool_ *manwe_avatar() +{ + s16b mimic_idx = resolve_mimic_name("Maia"); + assert(mimic_idx >= 0); + + set_mimic(get_level_s(MANWE_AVATAR, 20) + randint(10), + mimic_idx, + p_ptr->lev); + return CAST; +} + +char *manwe_avatar_info() +{ + static char buf[128]; + sprintf(buf, + "dur %d+d10", + get_level_s(MANWE_AVATAR, 20)); + return buf; +} + +bool_ *manwe_blessing() +{ + s32b dur = get_level_s(MANWE_BLESS, 70) + 30 + randint(40); + + set_blessed(dur); + set_afraid(0); + set_lite(0); + + if (get_level_s(MANWE_BLESS, 50) >= 10) + { + set_hero(dur); + } + if (get_level_s(MANWE_BLESS, 50) >= 20) + { + set_shero(dur); + } + if (get_level_s(MANWE_BLESS, 50) >= 30) + { + set_holy(dur); + } + + return CAST; +} + +char *manwe_blessing_info() +{ + static char buf[128]; + sprintf(buf, + "dur %d+d40", + get_level_s(MANWE_BLESS, 70) + 30); + return buf; +} + +bool_ *manwe_call() +{ + int y = 0, x = 0, m_idx = -1, r_idx = -1; + + find_position(p_ptr->py, p_ptr->px, &y, &x); + + r_idx = test_monster_name("Great eagle"); + assert(r_idx >= 1); + + m_idx = place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_FRIEND); + + if (m_idx > 0) + { + monster_set_level(m_idx, 20 + get_level(MANWE_CALL, 70, 0)); + return CAST; + } + + return NO_CAST; +} + +char *manwe_call_info() +{ + static char buf[128]; + sprintf(buf, + "level %d", + get_level_s(MANWE_CALL, 70) + 20); + return buf; +} -- cgit v1.2.3