diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-19 18:42:11 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-19 19:17:05 +0200 |
commit | 1cd265d4f32d2c624387b1bafc45ed0d18b3d257 (patch) | |
tree | 70db0a73a4ecb08685ed40dd3fa715f8ca92e95b | |
parent | ca30fc5a6f92d75ee1c7eec2dd863776fe7afb5f (diff) |
Lua: Move "Mana" spell functions to C
-rw-r--r-- | lib/mods/theme/scpt/s_mana.lua | 59 | ||||
-rw-r--r-- | lib/scpt/s_mana.lua | 59 | ||||
-rw-r--r-- | src/externs.h | 14 | ||||
-rw-r--r-- | src/spells.pkg | 14 | ||||
-rw-r--r-- | src/spells3.c | 136 |
5 files changed, 180 insertions, 102 deletions
diff --git a/lib/mods/theme/scpt/s_mana.lua b/lib/mods/theme/scpt/s_mana.lua index 736b06b0..67126fb2 100644 --- a/lib/mods/theme/scpt/s_mana.lua +++ b/lib/mods/theme/scpt/s_mana.lua @@ -1,9 +1,5 @@ -- The mana school -function get_manathrust_dam() - return 3 + get_level(MANATHRUST, 50), 1 + get_level(MANATHRUST, 20) -end - MANATHRUST = add_spell { ["name"] = "Manathrust", @@ -22,19 +18,8 @@ MANATHRUST = add_spell ["max_level"] = { 15, 33 }, }, }, - ["spell"] = function() - local ret, dir - - ret, dir = get_aim_dir() - if ret == FALSE then return end - return fire_bolt(GF_MANA, dir, damroll(get_manathrust_dam())) - end, - ["info"] = function() - local x, y - - x, y = get_manathrust_dam() - return "dam "..x.."d"..y - end, + ["spell"] = function() return mana_manathrust() end, + ["info"] = function() return mana_manathrust_info() end, ["desc"] = { "Conjures up mana into a powerful bolt", "The damage is irresistible and will increase with level" @@ -60,17 +45,8 @@ DELCURSES = add_spell }, }, ["inertia"] = { 1, 10 }, - ["spell"] = function() - local done - - if get_level(DELCURSES, 50) >= 20 then done = remove_all_curse() - else done = remove_curse() end - if done == TRUE then msg_print("The curse is broken!") end - return done - end, - ["info"] = function() - return "" - end, + ["spell"] = function() return mana_remove_curses() end, + ["info"] = function() return mana_remove_curses_info() end, ["desc"] = { "Remove curses of worn objects", "At level 20 switches to *remove curses*" @@ -86,17 +62,8 @@ RESISTS = add_spell ["mana_max"] = 20, ["fail"] = 40, ["inertia"] = { 2, 25 }, - ["spell"] = function() - local obvious - if player.oppose_fire == 0 then obvious = set_oppose_fire(randint(10) + 15 + get_level(RESISTS, 50)) end - if player.oppose_cold == 0 then obvious = is_obvious(set_oppose_cold(randint(10) + 15 + get_level(RESISTS, 50)), obvious) end - if player.oppose_elec == 0 then obvious = is_obvious(set_oppose_elec(randint(10) + 15 + get_level(RESISTS, 50)), obvious) end - if player.oppose_acid == 0 then obvious = is_obvious(set_oppose_acid(randint(10) + 15 + get_level(RESISTS, 50)), obvious) end - return obvious - end, - ["info"] = function() - return "dur "..(15 + get_level(RESISTS, 50)).."+d10" - end, + ["spell"] = function() return mana_elemental_shield() end, + ["info"] = function() return mana_elemental_shield_info() end, ["desc"] = { "Provide resistances to the four basic elements", } @@ -111,18 +78,8 @@ MANASHIELD = add_spell ["mana_max"] = 50, ["fail"] = 90, ["inertia"] = { 9, 10}, - ["spell"] = function() - if get_level(MANASHIELD, 50) >= 5 then - if (player.invuln == 0) then - return set_invuln(randint(5) + 3 + get_level(MANASHIELD, 10)) - end - else - if (player.disrupt_shield == 0) then return set_disrupt_shield(randint(5) + 3 + get_level(MANASHIELD, 10)) end - end - end, - ["info"] = function() - return "dur "..(3 + get_level(MANASHIELD, 10)).."+d5" - end, + ["spell"] = function() return mana_disruption_shield() end, + ["info"] = function() return mana_disruption_shield_info() end, ["desc"] = { "Uses mana instead of hp to take damage", "At level 5 switches to Globe of Invulnerability.", diff --git a/lib/scpt/s_mana.lua b/lib/scpt/s_mana.lua index 736b06b0..67126fb2 100644 --- a/lib/scpt/s_mana.lua +++ b/lib/scpt/s_mana.lua @@ -1,9 +1,5 @@ -- The mana school -function get_manathrust_dam() - return 3 + get_level(MANATHRUST, 50), 1 + get_level(MANATHRUST, 20) -end - MANATHRUST = add_spell { ["name"] = "Manathrust", @@ -22,19 +18,8 @@ MANATHRUST = add_spell ["max_level"] = { 15, 33 }, }, }, - ["spell"] = function() - local ret, dir - - ret, dir = get_aim_dir() - if ret == FALSE then return end - return fire_bolt(GF_MANA, dir, damroll(get_manathrust_dam())) - end, - ["info"] = function() - local x, y - - x, y = get_manathrust_dam() - return "dam "..x.."d"..y - end, + ["spell"] = function() return mana_manathrust() end, + ["info"] = function() return mana_manathrust_info() end, ["desc"] = { "Conjures up mana into a powerful bolt", "The damage is irresistible and will increase with level" @@ -60,17 +45,8 @@ DELCURSES = add_spell }, }, ["inertia"] = { 1, 10 }, - ["spell"] = function() - local done - - if get_level(DELCURSES, 50) >= 20 then done = remove_all_curse() - else done = remove_curse() end - if done == TRUE then msg_print("The curse is broken!") end - return done - end, - ["info"] = function() - return "" - end, + ["spell"] = function() return mana_remove_curses() end, + ["info"] = function() return mana_remove_curses_info() end, ["desc"] = { "Remove curses of worn objects", "At level 20 switches to *remove curses*" @@ -86,17 +62,8 @@ RESISTS = add_spell ["mana_max"] = 20, ["fail"] = 40, ["inertia"] = { 2, 25 }, - ["spell"] = function() - local obvious - if player.oppose_fire == 0 then obvious = set_oppose_fire(randint(10) + 15 + get_level(RESISTS, 50)) end - if player.oppose_cold == 0 then obvious = is_obvious(set_oppose_cold(randint(10) + 15 + get_level(RESISTS, 50)), obvious) end - if player.oppose_elec == 0 then obvious = is_obvious(set_oppose_elec(randint(10) + 15 + get_level(RESISTS, 50)), obvious) end - if player.oppose_acid == 0 then obvious = is_obvious(set_oppose_acid(randint(10) + 15 + get_level(RESISTS, 50)), obvious) end - return obvious - end, - ["info"] = function() - return "dur "..(15 + get_level(RESISTS, 50)).."+d10" - end, + ["spell"] = function() return mana_elemental_shield() end, + ["info"] = function() return mana_elemental_shield_info() end, ["desc"] = { "Provide resistances to the four basic elements", } @@ -111,18 +78,8 @@ MANASHIELD = add_spell ["mana_max"] = 50, ["fail"] = 90, ["inertia"] = { 9, 10}, - ["spell"] = function() - if get_level(MANASHIELD, 50) >= 5 then - if (player.invuln == 0) then - return set_invuln(randint(5) + 3 + get_level(MANASHIELD, 10)) - end - else - if (player.disrupt_shield == 0) then return set_disrupt_shield(randint(5) + 3 + get_level(MANASHIELD, 10)) end - end - end, - ["info"] = function() - return "dur "..(3 + get_level(MANASHIELD, 10)).."+d5" - end, + ["spell"] = function() return mana_disruption_shield() end, + ["info"] = function() return mana_disruption_shield_info() end, ["desc"] = { "Uses mana instead of hp to take damage", "At level 5 switches to Globe of Invulnerability.", diff --git a/src/externs.h b/src/externs.h index 77d5613e..295b008e 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1564,6 +1564,20 @@ char *geomancy_grow_barrier_info(); bool_ *geomancy_elemental_minion(); char *geomancy_elemental_minion_info(); +extern s32b MANATHRUST; +extern s32b DELCURSES; +extern s32b RESISTS; +extern s32b MANASHIELD; + +bool_ *mana_manathrust(); +char *mana_manathrust_info(); +bool_ *mana_remove_curses(); +char *mana_remove_curses_info(); +bool_ *mana_elemental_shield(); +char *mana_elemental_shield_info(); +bool_ *mana_disruption_shield(); +char *mana_disruption_shield_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 adfd6f1d..458fdc49 100644 --- a/src/spells.pkg +++ b/src/spells.pkg @@ -2608,3 +2608,17 @@ bool_ *geomancy_grow_barrier(); char *geomancy_grow_barrier_info(); bool_ *geomancy_elemental_minion(); char *geomancy_elemental_minion_info(); + +extern s32b MANATHRUST; +extern s32b DELCURSES; +extern s32b RESISTS; +extern s32b MANASHIELD; + +bool_ *mana_manathrust(); +char *mana_manathrust_info(); +bool_ *mana_remove_curses(); +char *mana_remove_curses_info(); +bool_ *mana_elemental_shield(); +char *mana_elemental_shield_info(); +bool_ *mana_disruption_shield(); +char *mana_disruption_shield_info(); diff --git a/src/spells3.c b/src/spells3.c index c3ca27bc..d9b36410 100644 --- a/src/spells3.c +++ b/src/spells3.c @@ -57,6 +57,11 @@ s32b DRIPPING_TREAD; s32b GROW_BARRIER; s32b ELEMENTAL_MINION; +s32b MANATHRUST; +s32b DELCURSES; +s32b RESISTS; +s32b MANASHIELD; + /* 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). */ @@ -1687,3 +1692,134 @@ char *geomancy_elemental_minion_info() (10 + get_level_s(ELEMENTAL_MINION, 120))); return buf; } + +static void get_manathrust_dam(s16b *num, s16b *sides) +{ + *num = 3 + get_level_s(MANATHRUST, 50); + *sides = 1 + get_level_s(MANATHRUST, 20); +} + +bool_ *mana_manathrust() +{ + int dir; + s16b num = 0; + s16b sides = 0; + + if (!get_aim_dir(&dir)) + { + return NO_CAST; + } + + get_manathrust_dam(&num, &sides); + fire_bolt(GF_MANA, dir, damroll(num, sides)); + return CAST; +} + +char *mana_manathrust_info() +{ + s16b num = 0; + s16b sides = 0; + static char buf[128]; + + get_manathrust_dam(&num, &sides); + sprintf(buf, + "dam %dd%d", + num, + sides); + return buf; +} + +bool_ *mana_remove_curses() +{ + bool_ done = FALSE; + + if (get_level_s(DELCURSES, 50) >= 20) + { + done = remove_all_curse(); + } + else + { + done = remove_curse(); + } + + if (done) + { + msg_print("The curse is broken!"); + } + + return CAST; +} + +char *mana_remove_curses_info() +{ + return ""; +} + +bool_ *mana_elemental_shield() +{ + bool_ *res = NO_CAST; + + if (p_ptr->oppose_fire == 0) + { + set_oppose_fire(randint(10) + 15 + get_level_s(RESISTS, 50)); + res = CAST; + } + + if (p_ptr->oppose_cold == 0) + { + set_oppose_cold(randint(10) + 15 + get_level_s(RESISTS, 50)); + res = CAST; + } + + if (p_ptr->oppose_elec == 0) + { + set_oppose_elec(randint(10) + 15 + get_level_s(RESISTS, 50)); + res = CAST; + } + + if (p_ptr->oppose_acid == 0) + { + set_oppose_acid(randint(10) + 15 + get_level_s(RESISTS, 50)); + res = CAST; + } + + return res; +} + +char *mana_elemental_shield_info() +{ + static char buf[128]; + sprintf(buf, + "dur %d+d10", + (15 + get_level_s(RESISTS, 50))); + return buf; +} + +bool_ *mana_disruption_shield() +{ + if (get_level_s(MANASHIELD, 50) >= 5) + { + if (p_ptr->invuln == 0) + { + set_invuln(randint(5) + 3 + get_level_s(MANASHIELD, 10)); + return CAST; + } + } + else if (p_ptr->disrupt_shield == 0) + { + set_disrupt_shield(randint(5) + 3 + get_level_s(MANASHIELD, 10)); + return CAST; + } + + return NO_CAST; +} + +char *mana_disruption_shield_info() +{ + static char buf[128]; + sprintf(buf, + "dur %d+d5", + (3 + get_level_s(MANASHIELD, 10))); + return buf; +} + |