diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-12 07:39:30 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-12 07:57:26 +0200 |
commit | 9de9180942450aea8ded755c94510cf6d2542a5a (patch) | |
tree | 71a4d86d8f3c204e1c3b9ec34d598c8754f3e644 | |
parent | d97af20d1ac71ba79e6bcfd46b1753dc6737d266 (diff) |
Lua: Move "Conveyance" spell functions to C
-rw-r--r-- | lib/mods/theme/scpt/s_convey.lua | 108 | ||||
-rw-r--r-- | lib/scpt/s_convey.lua | 108 | ||||
-rw-r--r-- | src/externs.h | 20 | ||||
-rw-r--r-- | src/spells.pkg | 23 | ||||
-rw-r--r-- | src/spells3.c | 192 |
5 files changed, 259 insertions, 192 deletions
diff --git a/lib/mods/theme/scpt/s_convey.lua b/lib/mods/theme/scpt/s_convey.lua index 1105a850..265218fa 100644 --- a/lib/mods/theme/scpt/s_convey.lua +++ b/lib/mods/theme/scpt/s_convey.lua @@ -9,21 +9,8 @@ BLINK = add_spell ["mana_max"] = 3, ["fail"] = 10, ["inertia"] = { 1, 5 }, - ["spell"] = function() - if get_level(BLINK, 50) >= 30 then - local oy, ox = player.py, player.px - - teleport_player(10 + get_level(BLINK, 8)) - create_between_gate(0, oy, ox) - return TRUE - else - teleport_player(10 + get_level(BLINK, 8)) - return TRUE - end - end, - ["info"] = function() - return "distance "..(10 + get_level(BLINK, 8)) - end, + ["spell"] = function() return convey_blink() end, + ["info"] = function() return convey_blink_info() end, ["desc"] = { "Teleports you on a small scale range", "At level 30 it creates void jumpgates", @@ -48,15 +35,8 @@ DISARM = add_spell ["max_level"] = { 10, 50 }, }, }, - ["spell"] = function() - local obvious - obvious = destroy_doors_touch() - if get_level(DISARM, 50) >= 10 then obvious = is_obvious(destroy_traps_touch(), obvious) end - return obvious - end, - ["info"] = function() - return "" - end, + ["spell"] = function() return convey_disarm() end, + ["info"] = function() return convey_disarm_info() end, ["desc"] = { "Destroys doors and disarms traps", "At level 10 it unlocks doors and disarms traps", @@ -82,14 +62,8 @@ TELEPORT = add_spell }, }, ["inertia"] = { 1, 10 }, - ["spell"] = function() - player.energy = player.energy - (25 - get_level(TELEPORT, 50)) - teleport_player(100 + get_level(TELEPORT, 100)) - return TRUE - end, - ["info"] = function() - return "distance "..(100 + get_level(TELEPORT, 100)) - end, + ["spell"] = function() return convey_teleport() end, + ["info"] = function() return convey_teleport_info() end, ["desc"] = { "Teleports you around the level. The casting time decreases with level", } @@ -113,24 +87,8 @@ TELEAWAY = add_spell ["max_level"] = { 20, 50 }, }, }, - ["spell"] = function() - local ret, dir - - if get_level(TELEAWAY, 50) >= 20 then - return project_los(GF_AWAY_ALL, 100) - elseif get_level(TELEAWAY, 50) >= 10 then - ret, dir = get_aim_dir() - if ret == FALSE then return end - return fire_ball(GF_AWAY_ALL, dir, 100, 3 + get_level(TELEAWAY, 4)) - else - ret, dir = get_aim_dir() - if ret == FALSE then return end - return teleport_monster(dir) - end - end, - ["info"] = function() - return "" - end, + ["spell"] = function() return convey_teleport_away() end, + ["info"] = function() return convey_teleport_away_info() end, ["desc"] = { "Teleports a line of monsters away", "At level 10 it turns into a ball", @@ -146,46 +104,8 @@ RECALL = add_spell ["mana"] = 25, ["mana_max"] = 25, ["fail"] = 60, - ["spell"] = function() - local ret, x, y, c_ptr - ret, x, y = tgt_pt() - if ret == FALSE then return end - c_ptr = cave(y, x) - if (y == player.py) and (x == player.px) then - local d = 21 - get_level(RECALL, 15) - if d < 0 then - d = 0 - end - local f = 15 - get_level(RECALL, 10) - if f < 1 then - f = 1 - end - recall_player(d, f) - return TRUE - elseif c_ptr.m_idx > 0 then - swap_position(y, x) - return TRUE - elseif c_ptr.o_idx > 0 then - set_target(y, x) - if get_level(RECALL, 50) >= 15 then - fetch(5, 10 + get_level(RECALL, 150), FALSE) - else - fetch(5, 10 + get_level(RECALL, 150), TRUE) - end - return TRUE - end - end, - ["info"] = function() - local d = 21 - get_level(RECALL, 15) - if d < 0 then - d = 0 - end - local f = 15 - get_level(RECALL, 10) - if f < 1 then - f = 1 - end - return "dur "..f.."+d"..d.." weight "..(1 + get_level(RECALL, 15)).."lb" - end, + ["spell"] = function() return convey_recall() end, + ["info"] = function() return convey_recall_info() end, ["desc"] = { "Cast on yourself it will recall you to the surface/dungeon.", "Cast at a monster you will swap positions with the monster.", @@ -212,12 +132,8 @@ PROBABILITY_TRAVEL = add_spell }, }, ["inertia"] = { 6, 40 }, - ["spell"] = function() - return set_prob_travel(randint(20) + get_level(PROBABILITY_TRAVEL, 60)) - end, - ["info"] = function() - return "dur "..get_level(PROBABILITY_TRAVEL, 60).."+d20" - end, + ["spell"] = function() return convey_probability_travel() end, + ["info"] = function() return convey_probability_travel_info() end, ["desc"] = { "Renders you immaterial, when you hit a wall you travel through it and", "instantly appear on the other side of it. You can also float up and down", diff --git a/lib/scpt/s_convey.lua b/lib/scpt/s_convey.lua index e7856c43..d81af28b 100644 --- a/lib/scpt/s_convey.lua +++ b/lib/scpt/s_convey.lua @@ -9,21 +9,8 @@ BLINK = add_spell ["mana_max"] = 3, ["fail"] = 10, ["inertia"] = { 1, 5 }, - ["spell"] = function() - if get_level(BLINK, 50) >= 30 then - local oy, ox = player.py, player.px - - teleport_player(10 + get_level(BLINK, 8)) - create_between_gate(0, oy, ox) - return TRUE - else - teleport_player(10 + get_level(BLINK, 8)) - return TRUE - end - end, - ["info"] = function() - return "distance "..(10 + get_level(BLINK, 8)) - end, + ["spell"] = function() return convey_blink() end, + ["info"] = function() return convey_blink_info() end, ["desc"] = { "Teleports you on a small scale range", "At level 30 it creates void jumpgates", @@ -48,15 +35,8 @@ DISARM = add_spell ["max_level"] = { 10, 50 }, }, }, - ["spell"] = function() - local obvious - obvious = destroy_doors_touch() - if get_level(DISARM, 50) >= 10 then obvious = is_obvious(destroy_traps_touch(), obvious) end - return obvious - end, - ["info"] = function() - return "" - end, + ["spell"] = function() return convey_disarm() end, + ["info"] = function() return convey_disarm_info() end, ["desc"] = { "Destroys doors and traps", "At level 10 it destroys doors and traps, then reveals and unlocks any secret", @@ -83,14 +63,8 @@ TELEPORT = add_spell }, }, ["inertia"] = { 1, 10 }, - ["spell"] = function() - player.energy = player.energy - (25 - get_level(TELEPORT, 50)) - teleport_player(100 + get_level(TELEPORT, 100)) - return TRUE - end, - ["info"] = function() - return "distance "..(100 + get_level(TELEPORT, 100)) - end, + ["spell"] = function() return convey_teleport() end, + ["info"] = function() return convey_teleport_info() end, ["desc"] = { "Teleports you around the level. The casting time decreases with level", } @@ -114,24 +88,8 @@ TELEAWAY = add_spell ["max_level"] = { 20, 50 }, }, }, - ["spell"] = function() - local ret, dir - - if get_level(TELEAWAY, 50) >= 20 then - return project_los(GF_AWAY_ALL, 100) - elseif get_level(TELEAWAY, 50) >= 10 then - ret, dir = get_aim_dir() - if ret == FALSE then return end - return fire_ball(GF_AWAY_ALL, dir, 100, 3 + get_level(TELEAWAY, 4)) - else - ret, dir = get_aim_dir() - if ret == FALSE then return end - return teleport_monster(dir) - end - end, - ["info"] = function() - return "" - end, + ["spell"] = function() return convey_teleport_away() end, + ["info"] = function() return convey_teleport_away_info() end, ["desc"] = { "Teleports a line of monsters away", "At level 10 it turns into a ball", @@ -147,46 +105,8 @@ RECALL = add_spell ["mana"] = 25, ["mana_max"] = 25, ["fail"] = 60, - ["spell"] = function() - local ret, x, y, c_ptr - ret, x, y = tgt_pt() - if ret == FALSE then return end - c_ptr = cave(y, x) - if (y == player.py) and (x == player.px) then - local d = 21 - get_level(RECALL, 15) - if d < 0 then - d = 0 - end - local f = 15 - get_level(RECALL, 10) - if f < 1 then - f = 1 - end - recall_player(d, f) - return TRUE - elseif c_ptr.m_idx > 0 then - swap_position(y, x) - return TRUE - elseif c_ptr.o_idx > 0 then - set_target(y, x) - if get_level(RECALL, 50) >= 15 then - fetch(5, 10 + get_level(RECALL, 150), FALSE) - else - fetch(5, 10 + get_level(RECALL, 150), TRUE) - end - return TRUE - end - end, - ["info"] = function() - local d = 21 - get_level(RECALL, 15) - if d < 0 then - d = 0 - end - local f = 15 - get_level(RECALL, 10) - if f < 1 then - f = 1 - end - return "dur "..f.."+d"..d.." weight "..(1 + get_level(RECALL, 15)).."lb" - end, + ["spell"] = function() return convey_recall() end, + ["info"] = function() return convey_recall_info() end, ["desc"] = { "Cast on yourself it will recall you to the surface/dungeon.", "Cast at a monster you will swap positions with the monster.", @@ -213,12 +133,8 @@ PROBABILITY_TRAVEL = add_spell }, }, ["inertia"] = { 6, 40 }, - ["spell"] = function() - return set_prob_travel(randint(20) + get_level(PROBABILITY_TRAVEL, 60)) - end, - ["info"] = function() - return "dur "..get_level(PROBABILITY_TRAVEL, 60).."+d20" - end, + ["spell"] = function() return convey_probability_travel() end, + ["info"] = function() return convey_probability_travel_info() end, ["desc"] = { "Renders you immaterial, when you hit a wall you travel through it and", "instantly appear on the other side of it. You can also float up and down", diff --git a/src/externs.h b/src/externs.h index 4fa71a2f..6a3bdb07 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1421,6 +1421,26 @@ char *air_thunderstorm_info(); bool_ *air_sterilize(); char *air_sterilize_info(); +extern s32b BLINK; +extern s32b DISARM; +extern s32b TELEPORT; +extern s32b TELEAWAY; +extern s32b RECALL; +extern s32b PROBABILITY_TRAVEL; + +bool_ *convey_blink(); +char *convey_blink_info(); +bool_ *convey_disarm(); +char *convey_disarm_info(); +bool_ *convey_teleport(); +char *convey_teleport_info(); +bool_ *convey_teleport_away(); +char *convey_teleport_away_info(); +bool_ *convey_recall(); +char *convey_recall_info(); +bool_ *convey_probability_travel(); +char *convey_probability_travel_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 de5d55bc..f1a83a23 100644 --- a/src/spells.pkg +++ b/src/spells.pkg @@ -2444,3 +2444,26 @@ bool_ *air_thunderstorm(); char *air_thunderstorm_info(); bool_ *air_sterilize(); char *air_sterilize_info(); + +/* + * Conveyance + */ +extern s32b BLINK; +extern s32b DISARM; +extern s32b TELEPORT; +extern s32b TELEAWAY; +extern s32b RECALL; +extern s32b PROBABILITY_TRAVEL; + +bool_ *convey_blink(); +char *convey_blink_info(); +bool_ *convey_disarm(); +char *convey_disarm_info(); +bool_ *convey_teleport(); +char *convey_teleport_info(); +bool_ *convey_teleport_away(); +char *convey_teleport_away_info(); +bool_ *convey_recall(); +char *convey_recall_info(); +bool_ *convey_probability_travel(); +char *convey_probability_travel_info(); diff --git a/src/spells3.c b/src/spells3.c index 0b5d5443..dd75aac0 100644 --- a/src/spells3.c +++ b/src/spells3.c @@ -7,6 +7,13 @@ s32b POISONBLOOD; s32b THUNDERSTORM; s32b STERILIZE; +s32b BLINK; +s32b DISARM; +s32b TELEPORT; +s32b TELEAWAY; +s32b RECALL; +s32b PROBABILITY_TRAVEL; + /* 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). */ @@ -162,3 +169,188 @@ char *air_sterilize_info() (20 + get_level_s(STERILIZE, 70))); return buf; } + +bool_ *convey_blink() +{ + if (get_level_s(BLINK, 50) >= 30) + { + int oy = p_ptr->py; + int ox = p_ptr->px; + + teleport_player(10 + get_level_s(BLINK, 8)); + create_between_gate(0, oy, ox); + return CAST; + } + else + { + teleport_player(10 + get_level_s(BLINK, 8)); + return CAST; + } +} + +char *convey_blink_info() +{ + static char buf[128]; + sprintf(buf, + "distance %d", + (10 + get_level_s(BLINK, 8))); + return buf; +} + +bool_ *convey_disarm() +{ + destroy_doors_touch(); + if (get_level_s(DISARM, 50) >= 10) + { + destroy_traps_touch(); + } + + return CAST; +} + +char *convey_disarm_info() +{ + return ""; +} + +bool_ *convey_teleport() +{ + p_ptr->energy -= (25 - get_level_s(TELEPORT, 50)); + teleport_player(100 + get_level_s(TELEPORT, 100)); + return CAST; +} + +char *convey_teleport_info() +{ + static char buf[128]; + sprintf(buf, + "distance %d", + (100 + get_level_s(TELEPORT, 100))); + return buf; +} + +bool_ *convey_teleport_away() +{ + if (get_level_s(TELEAWAY, 50) >= 20) + { + project_hack(GF_AWAY_ALL, 100); + return CAST; + } + else if (get_level_s(TELEAWAY, 50) >= 10) + { + int dir; + if (!get_aim_dir(&dir)) + { + return NO_CAST; + } + + fire_ball(GF_AWAY_ALL, dir, 100, 3 + get_level_s(TELEAWAY, 4)); + return CAST; + } + else + { + int dir; + if (!get_aim_dir(&dir)) + { + return NO_CAST; + } + teleport_monster(dir); + return CAST; + } +} + +char *convey_teleport_away_info() +{ + return ""; +} + +static int recall_get_d() +{ + int d = 21 - get_level_s(RECALL, 15); + if (d < 0) + { + d = 0; + } + return d; +} + +static int recall_get_f() +{ + int f = 15 - get_level_s(RECALL, 10); + if (f < 1) + { + f = 1; + } + return f; +} + +bool_ *convey_recall() +{ + int x,y; + cave_type *c_ptr; + + if (!tgt_pt(&x, &y)) + { + return NO_CAST; + } + + c_ptr = &cave[y][x]; + + if ((y == p_ptr->py) && + (x == p_ptr->px)) + { + int d = recall_get_d(); + int f = recall_get_f(); + recall_player(d, f); + return CAST; + } + else if (c_ptr->m_idx > 0) + { + swap_position(y, x); + return CAST; + } + else if (c_ptr->o_idx > 0) + { + set_target(y, x); + if (get_level_s(RECALL, 50) >= 15) + { + fetch(5, 10 + get_level_s(RECALL, 150), FALSE); + } + else + { + fetch(5, 10 + get_level_s(RECALL, 150), TRUE); + } + return CAST; + } + else + { + return NO_CAST; + } +} + +char *convey_recall_info() +{ + static char buf[128]; + int d = recall_get_d(); + int f = recall_get_f(); + + sprintf(buf, + "dur %d+d%d weight %dlb", + f, d, (1 + get_level_s(RECALL, 15))); + return buf; +} + +bool_ *convey_probability_travel() +{ + set_prob_travel(randint(20) + get_level_s(PROBABILITY_TRAVEL, 60)); + return CAST; +} + +char *convey_probability_travel_info() +{ + static char buf[128]; + sprintf(buf, + "dur %d+d20", + get_level_s(PROBABILITY_TRAVEL, 60)); + return buf; +} |