summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-05 21:03:18 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-07 15:28:25 +0200
commit46498dfaab2cb0698822397b43039e3ecf605a1e (patch)
treeee758d0906ef96311bdaa4b5f392f9704553ab48
parentc92f7bf932d6e36c1aecd704a2a69d742ef7748d (diff)
Lua: Move geomancy spell effects to C
-rw-r--r--lib/core/dungeon.lua26
-rw-r--r--lib/mods/theme/core/dungeon.lua26
-rw-r--r--lib/mods/theme/scpt/s_geom.lua252
-rw-r--r--lib/scpt/s_geom.lua252
-rw-r--r--src/externs.h5
-rw-r--r--src/lua_bind.c5
-rw-r--r--src/spells.pkg7
-rw-r--r--src/spells1.c5
-rw-r--r--src/spells2.c347
9 files changed, 370 insertions, 555 deletions
diff --git a/lib/core/dungeon.lua b/lib/core/dungeon.lua
index d91d785b..ba4fd38a 100644
--- a/lib/core/dungeon.lua
+++ b/lib/core/dungeon.lua
@@ -20,32 +20,6 @@ function explode_dir(dir)
return ddy[dir + 1], ddx[dir + 1]
end
-function rotate_dir(dir, mov)
- if mov > 0 then
- if dir == 7 then dir = 8
- elseif dir == 8 then dir = 9
- elseif dir == 9 then dir = 6
- elseif dir == 6 then dir = 3
- elseif dir == 3 then dir = 2
- elseif dir == 2 then dir = 1
- elseif dir == 1 then dir = 4
- elseif dir == 4 then dir = 7
- end
- elseif mov < 0 then
- if dir == 7 then dir = 4
- elseif dir == 4 then dir = 1
- elseif dir == 1 then dir = 2
- elseif dir == 2 then dir = 3
- elseif dir == 3 then dir = 6
- elseif dir == 6 then dir = 9
- elseif dir == 9 then dir = 8
- elseif dir == 8 then dir = 7
- end
- end
-
- return dir
-end
-
-- Place a trap for a specific level
function place_trap(y, x, level)
local old_dun = dun_level
diff --git a/lib/mods/theme/core/dungeon.lua b/lib/mods/theme/core/dungeon.lua
index d91d785b..ba4fd38a 100644
--- a/lib/mods/theme/core/dungeon.lua
+++ b/lib/mods/theme/core/dungeon.lua
@@ -20,32 +20,6 @@ function explode_dir(dir)
return ddy[dir + 1], ddx[dir + 1]
end
-function rotate_dir(dir, mov)
- if mov > 0 then
- if dir == 7 then dir = 8
- elseif dir == 8 then dir = 9
- elseif dir == 9 then dir = 6
- elseif dir == 6 then dir = 3
- elseif dir == 3 then dir = 2
- elseif dir == 2 then dir = 1
- elseif dir == 1 then dir = 4
- elseif dir == 4 then dir = 7
- end
- elseif mov < 0 then
- if dir == 7 then dir = 4
- elseif dir == 4 then dir = 1
- elseif dir == 1 then dir = 2
- elseif dir == 2 then dir = 3
- elseif dir == 3 then dir = 6
- elseif dir == 6 then dir = 9
- elseif dir == 9 then dir = 8
- elseif dir == 8 then dir = 7
- end
- end
-
- return dir
-end
-
-- Place a trap for a specific level
function place_trap(y, x, level)
local old_dun = dun_level
diff --git a/lib/mods/theme/scpt/s_geom.lua b/lib/mods/theme/scpt/s_geom.lua
index 52ebd49a..d152bc25 100644
--- a/lib/mods/theme/scpt/s_geom.lua
+++ b/lib/mods/theme/scpt/s_geom.lua
@@ -1,75 +1,5 @@
-- Geomancy school
-function geomancy_random_wall(y, x)
- local c_ptr = cave(y, x)
-
- -- Do not destroy permanent things
- if cave_is(c_ptr, FF1_PERMANENT) ~= FALSE then return end
-
- local feat = nil
- local table =
- {
- [1] = { SKILL_FIRE, FEAT_SANDWALL, 1},
-
- [2] = { SKILL_WATER, FEAT_TREES, 1},
- [3] = { SKILL_WATER, FEAT_ICE_WALL, 12},
-
- [4] = { SKILL_EARTH, FEAT_WALL_EXTRA, 1},
- }
-
- while feat == nil do
- local t = table[randint(getn(table))]
-
- -- Do we meet the requirements ?
- -- And then select the features based on skill proportions
- if get_skill(t[1]) >= t[3] and magik(get_skill_scale(t[1], 100)) == TRUE then
- feat = t[2]
- end
- end
-
- cave_set_feat(y, x, feat)
-end
-
-
-function geomancy_random_floor(y, x, kill_wall)
- local c_ptr = cave(y, x)
-
- -- Do not destroy permanent things
- if cave_is(c_ptr, FF1_PERMANENT) ~= FALSE then return end
- if not kill_wall then
- if cave_is(c_ptr, FF1_FLOOR) ~= TRUE then return end
- end
-
- local feat = nil
- local table =
- {
- [1] = { SKILL_FIRE, FEAT_SAND, 1},
- [2] = { SKILL_FIRE, FEAT_SHAL_LAVA, 8},
- [3] = { SKILL_FIRE, FEAT_DEEP_LAVA, 18},
-
- [4] = { SKILL_WATER, FEAT_SHAL_WATER, 1},
- [5] = { SKILL_WATER, FEAT_DEEP_WATER, 8},
- [6] = { SKILL_WATER, FEAT_ICE, 18},
-
- [7] = { SKILL_EARTH, FEAT_GRASS, 1},
- [8] = { SKILL_EARTH, FEAT_FLOWER, 8},
- [9] = { SKILL_EARTH, FEAT_DARK_PIT, 18},
- }
-
- while feat == nil do
- local t = table[randint(getn(table))]
-
- -- Do we meet the requirements ?
- -- And then select the features based on skill proportions
- if get_skill(t[1]) >= t[3] and magik(get_skill_scale(t[1], 100)) == TRUE then
- feat = t[2]
- end
- end
-
- cave_set_feat(y, x, feat)
-end
-
-
CALL_THE_ELEMENTS = add_spell
{
["name"] = "Call the Elements",
@@ -103,114 +33,6 @@ CALL_THE_ELEMENTS = add_spell
}
}
--- Seperate function because an other spell needs it
-function channel_the_elements(y, x, level, silent)
- local t =
- {
- -- Earth stuff
- [FEAT_GRASS] = function()
- hp_player(player.mhp * (5 + get_skill_scale(SKILL_EARTH, 20)) / 100)
- end,
- [FEAT_FLOWER] = function()
- hp_player(player.mhp * (5 + get_skill_scale(SKILL_EARTH, 30)) / 100)
- end,
- [FEAT_DARK_PIT] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- local type = GF_DARK
- if get_skill(SKILL_EARTH) >= 18 then type = GF_NETHER end
- fire_bolt(type, dir, damroll(10, get_skill(SKILL_EARTH)))
- end,
-
- -- Water stuff
- [FEAT_SHAL_WATER] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- local type = GF_WATER
- if get_skill(SKILL_WATER) >= 18 then type = GF_WAVE end
-
- if get_skill(SKILL_WATER) >= 8 then
- fire_beam(type, dir, damroll(3, get_skill(SKILL_WATER)))
- else
- fire_bolt(type, dir, damroll(3, get_skill(SKILL_WATER)))
- end
- end,
- [FEAT_DEEP_WATER] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- local type = GF_WATER
- if get_skill(SKILL_WATER) >= 18 then type = GF_WAVE end
-
- if get_skill(SKILL_WATER) >= 8 then
- fire_beam(type, dir, damroll(5, get_skill(SKILL_WATER)))
- else
- fire_bolt(type, dir, damroll(5, get_skill(SKILL_WATER)))
- end
- end,
- [FEAT_ICE] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- if get_skill(SKILL_WATER) >= 12 then
- fire_ball(GF_ICE, dir, get_skill_scale(SKILL_WATER, 340), 3)
- else
- fire_bolt(GF_ICE, dir, damroll(3, get_skill(SKILL_WATER)))
- end
- end,
-
- -- Fire stuff
- [FEAT_SAND] = function()
- local type
- if (get_level(FIERYAURA, 50) >= 8) then
- type = SHIELD_GREAT_FIRE
- else
- type = SHIELD_FIRE
- end
- local dur = randint(20) + %level + get_skill(SKILL_AIR)
- set_shield(dur, 0, type, 5 + get_skill_scale(SKILL_FIRE, 20), 5 + get_skill_scale(SKILL_FIRE, 14))
- set_blind(dur)
- end,
- [FEAT_SHAL_LAVA] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- if get_skill(SKILL_FIRE) >= 15 then
- fire_bolt(GF_HELL_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15))
- else
- fire_bolt(GF_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15))
- end
- end,
- [FEAT_DEEP_LAVA] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- if get_skill(SKILL_FIRE) >= 15 then
- fire_ball(GF_HELL_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15), 3)
- else
- fire_ball(GF_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15), 3)
- end
- end,
- }
-
- if t[cave(y, x).feat] then
- t[cave(y, x).feat]()
-
- if magik(100 - level) == TRUE then
- if cave(y, x).feat == FEAT_FLOWER then
- cave_set_feat(y, x, FEAT_GRASS)
- else
- cave_set_feat(y, x, FEAT_FLOOR)
- end
- msg_print("The area is drained.")
- end
- elseif not silent then
- msg_print("You cannot channel this area.")
- end
-end
-
CHANNEL_ELEMENTS = add_spell
{
["name"] = "Channel Elements",
@@ -223,7 +45,7 @@ CHANNEL_ELEMENTS = add_spell
["blind"] = FALSE,
["random"] = 0,
["spell"] = function()
- channel_the_elements(player.py, player.px, get_level(CHANNEL_ELEMENTS), nil)
+ channel_the_elements(player.py, player.px, get_level(CHANNEL_ELEMENTS))
return TRUE
end,
["info"] = function()
@@ -364,76 +186,6 @@ VAPORIZE = add_spell
}
}
-geomancy_can_tunnel =
-{
- [FEAT_WALL_EXTRA] = TRUE,
- [FEAT_WALL_OUTER] = TRUE,
- [FEAT_WALL_INNER] = TRUE,
- [FEAT_WALL_SOLID] = TRUE,
-
- [FEAT_MAGMA] = TRUE,
- [FEAT_QUARTZ] = TRUE,
- [FEAT_MAGMA_H] = TRUE,
- [FEAT_QUARTZ_H] = TRUE,
- [FEAT_MAGMA_K] = TRUE,
- [FEAT_QUARTZ_K] = TRUE,
-
- [FEAT_TREES] = TRUE,
- [FEAT_DEAD_TREE] = TRUE,
-
- [FEAT_SANDWALL] = TRUE,
- [FEAT_SANDWALL_H] = TRUE,
- [FEAT_SANDWALL_K] = TRUE,
-
- [FEAT_ICE_WALL] = TRUE,
-}
-
--- Dig & sprew
-function geomancy_dig(oy, ox, dir, length)
- local dy, dx = explode_dir(dir)
- local y = dy + oy
- local x = dx + ox
-
- for i = 1, length do
- local c_ptr = cave(y, x)
- local ox = x - dx
- local oy = y - dy
-
- -- stop at the end of tunnelable things
- if not geomancy_can_tunnel[c_ptr.feat] then break end
-
- if geomancy_can_tunnel[cave(y - 1, x - 1).feat] then geomancy_random_wall(y - 1, x - 1) end
- if geomancy_can_tunnel[cave(y - 1, x).feat] then geomancy_random_wall(y - 1, x) end
- if geomancy_can_tunnel[cave(y - 1, x + 1).feat] then geomancy_random_wall(y - 1, x + 1) end
-
- if geomancy_can_tunnel[cave(y, x - 1).feat] then geomancy_random_wall(y, x - 1) end
- if geomancy_can_tunnel[cave(y, x + 1).feat] then geomancy_random_wall(y, x + 1) end
-
- if geomancy_can_tunnel[cave(y + 1, x - 1).feat] then geomancy_random_wall(y + 1, x - 1) end
- if geomancy_can_tunnel[cave(y + 1, x).feat] then geomancy_random_wall(y + 1, x) end
- if geomancy_can_tunnel[cave(y + 1, x + 1).feat] then geomancy_random_wall(y + 1, x + 1) end
-
- y = y + dy
- x = x + dx
- end
-
- y = y - dy
- x = x - dx
- while (y ~= oy) or (x ~= ox) do
- geomancy_random_floor(y, x, TRUE)
-
- -- Should we branch ?
- if magik(20) == TRUE then
- local rot = 1
- if magik(50) == TRUE then rot = -1 end
- geomancy_dig(y, x, rotate_dir(dir, rot), length / 3)
- end
-
- y = y - dy
- x = x - dx
- end
-end
-
GEOLYSIS = add_spell
{
["name"] = "Geolysis",
@@ -473,7 +225,7 @@ add_hooks
{
[HOOK_MOVED] = function(oy, ox)
if player.dripping_tread > 0 then
- geomancy_random_floor(oy, ox)
+ geomancy_random_floor(oy, ox, FALSE)
player.dripping_tread = player.dripping_tread - 1
if player.dripping_tread == 0 then
msg_print("You stop dripping raw elemental energies.")
diff --git a/lib/scpt/s_geom.lua b/lib/scpt/s_geom.lua
index 52ebd49a..d152bc25 100644
--- a/lib/scpt/s_geom.lua
+++ b/lib/scpt/s_geom.lua
@@ -1,75 +1,5 @@
-- Geomancy school
-function geomancy_random_wall(y, x)
- local c_ptr = cave(y, x)
-
- -- Do not destroy permanent things
- if cave_is(c_ptr, FF1_PERMANENT) ~= FALSE then return end
-
- local feat = nil
- local table =
- {
- [1] = { SKILL_FIRE, FEAT_SANDWALL, 1},
-
- [2] = { SKILL_WATER, FEAT_TREES, 1},
- [3] = { SKILL_WATER, FEAT_ICE_WALL, 12},
-
- [4] = { SKILL_EARTH, FEAT_WALL_EXTRA, 1},
- }
-
- while feat == nil do
- local t = table[randint(getn(table))]
-
- -- Do we meet the requirements ?
- -- And then select the features based on skill proportions
- if get_skill(t[1]) >= t[3] and magik(get_skill_scale(t[1], 100)) == TRUE then
- feat = t[2]
- end
- end
-
- cave_set_feat(y, x, feat)
-end
-
-
-function geomancy_random_floor(y, x, kill_wall)
- local c_ptr = cave(y, x)
-
- -- Do not destroy permanent things
- if cave_is(c_ptr, FF1_PERMANENT) ~= FALSE then return end
- if not kill_wall then
- if cave_is(c_ptr, FF1_FLOOR) ~= TRUE then return end
- end
-
- local feat = nil
- local table =
- {
- [1] = { SKILL_FIRE, FEAT_SAND, 1},
- [2] = { SKILL_FIRE, FEAT_SHAL_LAVA, 8},
- [3] = { SKILL_FIRE, FEAT_DEEP_LAVA, 18},
-
- [4] = { SKILL_WATER, FEAT_SHAL_WATER, 1},
- [5] = { SKILL_WATER, FEAT_DEEP_WATER, 8},
- [6] = { SKILL_WATER, FEAT_ICE, 18},
-
- [7] = { SKILL_EARTH, FEAT_GRASS, 1},
- [8] = { SKILL_EARTH, FEAT_FLOWER, 8},
- [9] = { SKILL_EARTH, FEAT_DARK_PIT, 18},
- }
-
- while feat == nil do
- local t = table[randint(getn(table))]
-
- -- Do we meet the requirements ?
- -- And then select the features based on skill proportions
- if get_skill(t[1]) >= t[3] and magik(get_skill_scale(t[1], 100)) == TRUE then
- feat = t[2]
- end
- end
-
- cave_set_feat(y, x, feat)
-end
-
-
CALL_THE_ELEMENTS = add_spell
{
["name"] = "Call the Elements",
@@ -103,114 +33,6 @@ CALL_THE_ELEMENTS = add_spell
}
}
--- Seperate function because an other spell needs it
-function channel_the_elements(y, x, level, silent)
- local t =
- {
- -- Earth stuff
- [FEAT_GRASS] = function()
- hp_player(player.mhp * (5 + get_skill_scale(SKILL_EARTH, 20)) / 100)
- end,
- [FEAT_FLOWER] = function()
- hp_player(player.mhp * (5 + get_skill_scale(SKILL_EARTH, 30)) / 100)
- end,
- [FEAT_DARK_PIT] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- local type = GF_DARK
- if get_skill(SKILL_EARTH) >= 18 then type = GF_NETHER end
- fire_bolt(type, dir, damroll(10, get_skill(SKILL_EARTH)))
- end,
-
- -- Water stuff
- [FEAT_SHAL_WATER] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- local type = GF_WATER
- if get_skill(SKILL_WATER) >= 18 then type = GF_WAVE end
-
- if get_skill(SKILL_WATER) >= 8 then
- fire_beam(type, dir, damroll(3, get_skill(SKILL_WATER)))
- else
- fire_bolt(type, dir, damroll(3, get_skill(SKILL_WATER)))
- end
- end,
- [FEAT_DEEP_WATER] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- local type = GF_WATER
- if get_skill(SKILL_WATER) >= 18 then type = GF_WAVE end
-
- if get_skill(SKILL_WATER) >= 8 then
- fire_beam(type, dir, damroll(5, get_skill(SKILL_WATER)))
- else
- fire_bolt(type, dir, damroll(5, get_skill(SKILL_WATER)))
- end
- end,
- [FEAT_ICE] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- if get_skill(SKILL_WATER) >= 12 then
- fire_ball(GF_ICE, dir, get_skill_scale(SKILL_WATER, 340), 3)
- else
- fire_bolt(GF_ICE, dir, damroll(3, get_skill(SKILL_WATER)))
- end
- end,
-
- -- Fire stuff
- [FEAT_SAND] = function()
- local type
- if (get_level(FIERYAURA, 50) >= 8) then
- type = SHIELD_GREAT_FIRE
- else
- type = SHIELD_FIRE
- end
- local dur = randint(20) + %level + get_skill(SKILL_AIR)
- set_shield(dur, 0, type, 5 + get_skill_scale(SKILL_FIRE, 20), 5 + get_skill_scale(SKILL_FIRE, 14))
- set_blind(dur)
- end,
- [FEAT_SHAL_LAVA] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- if get_skill(SKILL_FIRE) >= 15 then
- fire_bolt(GF_HELL_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15))
- else
- fire_bolt(GF_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15))
- end
- end,
- [FEAT_DEEP_LAVA] = function()
- local ret, dir = get_aim_dir()
- if ret == FALSE then return end
-
- if get_skill(SKILL_FIRE) >= 15 then
- fire_ball(GF_HELL_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15), 3)
- else
- fire_ball(GF_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15), 3)
- end
- end,
- }
-
- if t[cave(y, x).feat] then
- t[cave(y, x).feat]()
-
- if magik(100 - level) == TRUE then
- if cave(y, x).feat == FEAT_FLOWER then
- cave_set_feat(y, x, FEAT_GRASS)
- else
- cave_set_feat(y, x, FEAT_FLOOR)
- end
- msg_print("The area is drained.")
- end
- elseif not silent then
- msg_print("You cannot channel this area.")
- end
-end
-
CHANNEL_ELEMENTS = add_spell
{
["name"] = "Channel Elements",
@@ -223,7 +45,7 @@ CHANNEL_ELEMENTS = add_spell
["blind"] = FALSE,
["random"] = 0,
["spell"] = function()
- channel_the_elements(player.py, player.px, get_level(CHANNEL_ELEMENTS), nil)
+ channel_the_elements(player.py, player.px, get_level(CHANNEL_ELEMENTS))
return TRUE
end,
["info"] = function()
@@ -364,76 +186,6 @@ VAPORIZE = add_spell
}
}
-geomancy_can_tunnel =
-{
- [FEAT_WALL_EXTRA] = TRUE,
- [FEAT_WALL_OUTER] = TRUE,
- [FEAT_WALL_INNER] = TRUE,
- [FEAT_WALL_SOLID] = TRUE,
-
- [FEAT_MAGMA] = TRUE,
- [FEAT_QUARTZ] = TRUE,
- [FEAT_MAGMA_H] = TRUE,
- [FEAT_QUARTZ_H] = TRUE,
- [FEAT_MAGMA_K] = TRUE,
- [FEAT_QUARTZ_K] = TRUE,
-
- [FEAT_TREES] = TRUE,
- [FEAT_DEAD_TREE] = TRUE,
-
- [FEAT_SANDWALL] = TRUE,
- [FEAT_SANDWALL_H] = TRUE,
- [FEAT_SANDWALL_K] = TRUE,
-
- [FEAT_ICE_WALL] = TRUE,
-}
-
--- Dig & sprew
-function geomancy_dig(oy, ox, dir, length)
- local dy, dx = explode_dir(dir)
- local y = dy + oy
- local x = dx + ox
-
- for i = 1, length do
- local c_ptr = cave(y, x)
- local ox = x - dx
- local oy = y - dy
-
- -- stop at the end of tunnelable things
- if not geomancy_can_tunnel[c_ptr.feat] then break end
-
- if geomancy_can_tunnel[cave(y - 1, x - 1).feat] then geomancy_random_wall(y - 1, x - 1) end
- if geomancy_can_tunnel[cave(y - 1, x).feat] then geomancy_random_wall(y - 1, x) end
- if geomancy_can_tunnel[cave(y - 1, x + 1).feat] then geomancy_random_wall(y - 1, x + 1) end
-
- if geomancy_can_tunnel[cave(y, x - 1).feat] then geomancy_random_wall(y, x - 1) end
- if geomancy_can_tunnel[cave(y, x + 1).feat] then geomancy_random_wall(y, x + 1) end
-
- if geomancy_can_tunnel[cave(y + 1, x - 1).feat] then geomancy_random_wall(y + 1, x - 1) end
- if geomancy_can_tunnel[cave(y + 1, x).feat] then geomancy_random_wall(y + 1, x) end
- if geomancy_can_tunnel[cave(y + 1, x + 1).feat] then geomancy_random_wall(y + 1, x + 1) end
-
- y = y + dy
- x = x + dx
- end
-
- y = y - dy
- x = x - dx
- while (y ~= oy) or (x ~= ox) do
- geomancy_random_floor(y, x, TRUE)
-
- -- Should we branch ?
- if magik(20) == TRUE then
- local rot = 1
- if magik(50) == TRUE then rot = -1 end
- geomancy_dig(y, x, rotate_dir(dir, rot), length / 3)
- end
-
- y = y - dy
- x = x - dx
- end
-end
-
GEOLYSIS = add_spell
{
["name"] = "Geolysis",
@@ -473,7 +225,7 @@ add_hooks
{
[HOOK_MOVED] = function(oy, ox)
if player.dripping_tread > 0 then
- geomancy_random_floor(oy, ox)
+ geomancy_random_floor(oy, ox, FALSE)
player.dripping_tread = player.dripping_tread - 1
if player.dripping_tread == 0 then
msg_print("You stop dripping raw elemental energies.")
diff --git a/src/externs.h b/src/externs.h
index e232f69d..4f8def3a 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -1394,6 +1394,10 @@ extern void random_misc (object_type * o_ptr, bool_ is_scroll);
extern void random_plus(object_type * o_ptr, bool_ is_scroll);
extern bool_ reset_recall(bool_ no_trepas_max_depth);
extern void remove_dg_curse(void);
+extern void geomancy_random_wall(int y, int x);
+extern void geomancy_random_floor(int y, int x, bool_ kill_wall);
+extern void geomancy_dig(int oy, int ox, int dir, int length);
+extern void channel_the_elements(int y, int x, int level);
/* randart.c */
extern int get_activation_power(void);
@@ -1787,6 +1791,7 @@ extern void desc_quest(int q_idx, int d, char *desc);
extern s16b add_new_gods(char *name);
extern void desc_god(int g_idx, int d, char *desc);
+extern int get_lua_int(cptr name);
extern s16b get_god_AULE();
extern s16b get_god_VARDA();
extern s16b get_god_ULMO();
diff --git a/src/lua_bind.c b/src/lua_bind.c
index 00a0e25b..765b8072 100644
--- a/src/lua_bind.c
+++ b/src/lua_bind.c
@@ -608,6 +608,11 @@ void desc_god(int g_idx, int d, char *desc)
strncpy(deity_info[g_idx].desc[d], desc, 79);
}
+int get_lua_int(cptr name)
+{
+ return exec_lua(format("return %s", name));
+}
+
static int get_god_theme(cptr name)
{
if (game_module_idx == MODULE_THEME)
diff --git a/src/spells.pkg b/src/spells.pkg
index 5575d0f4..77a1794e 100644
--- a/src/spells.pkg
+++ b/src/spells.pkg
@@ -2465,3 +2465,10 @@ extern s16b last_teleportation_x;
* @note (see file spells1.c)
*/
extern void get_pos_player(int dis, int *ny=0, int *nx=0);
+
+/**
+ * Geomancy
+ */
+extern void geomancy_random_floor(int y, int x, bool kill_wall);
+extern void geomancy_dig(int y, int x, int dir, int length);
+extern void channel_the_elements(int y, int x, int level);
diff --git a/src/spells1.c b/src/spells1.c
index e99bbc23..8350a4ff 100644
--- a/src/spells1.c
+++ b/src/spells1.c
@@ -3834,15 +3834,14 @@ static bool_ project_f(int who, int r, int y, int x, int dam, int typ)
case GF_ELEMENTAL_WALL:
{
if ((p_ptr->py != y) || (p_ptr->px != x)) {
- exec_lua(format("geomancy_random_wall(%d,%d);", y, x));
+ geomancy_random_wall(y, x);
}
-
break;
}
case GF_ELEMENTAL_GROWTH:
{
- exec_lua(format("geomancy_random_floor(%d, %d)", y, x));
+ geomancy_random_floor(y, x, FALSE);
break;
}
}
diff --git a/src/spells2.c b/src/spells2.c
index 5467499c..6fb1b1b9 100644
--- a/src/spells2.c
+++ b/src/spells2.c
@@ -8074,3 +8074,350 @@ void create_between_gate(int dist, int y, int x)
cave[ij][ii].special = p_ptr->px + (p_ptr->py << 8);
}
}
+
+/**
+ * Geomancy
+ */
+typedef struct geomancy_entry {
+ int skill;
+ int feat;
+ int min_skill_level;
+} geomancy_entry;
+
+static int choose_geomancy_feature(int n, geomancy_entry *table)
+{
+ int feat = -1;
+ /* choose feature */
+ while (feat < 0) {
+ geomancy_entry *t = &table[rand_int(n)];
+
+ /* Do we meet the requirements ?
+ And then select the features based on skill proportions */
+ if ((get_skill(t->skill) >= t->min_skill_level) && magik(get_skill_scale(t->skill, 100)))
+ {
+ feat = t->feat;
+ }
+ }
+ /* return */
+ return feat;
+}
+
+static int rotate_dir(int dir, int mov)
+{
+ if (mov > 0)
+ {
+ switch (dir) {
+ case 7: return 8;
+ case 8: return 9;
+ case 9: return 6;
+ case 6: return 3;
+ case 3: return 2;
+ case 2: return 1;
+ case 1: return 4;
+ case 4: return 7;
+ }
+ }
+ else if (mov < 0)
+ {
+ switch (dir) {
+ case 7: return 4;
+ case 4: return 1;
+ case 1: return 2;
+ case 2: return 3;
+ case 3: return 6;
+ case 6: return 9;
+ case 9: return 8;
+ case 8: return 7;
+ }
+ }
+
+ return dir;
+}
+
+void geomancy_random_wall(int y, int x)
+{
+#define TABLE_SIZE 4
+ cave_type *c_ptr = &cave[y][x];
+ int feat = -1;
+ geomancy_entry table[TABLE_SIZE] = {
+ /* Fire element */
+ { SKILL_FIRE, FEAT_SANDWALL, 1},
+ /* Water element */
+ { SKILL_WATER, FEAT_TREES, 1},
+ { SKILL_WATER, FEAT_ICE_WALL, 12},
+ /* Earth element */
+ { SKILL_EARTH, FEAT_WALL_EXTRA, 1}
+ };
+
+ /* Do not destroy permanent things */
+ if (f_info[c_ptr->feat].flags1 & FF1_PERMANENT) {
+ return;
+ }
+
+ /* Choose feature */
+ feat = choose_geomancy_feature(TABLE_SIZE, table);
+ if (feat >= 0)
+ {
+ cave_set_feat(y, x, feat);
+ }
+#undef TABLE_SIZE
+}
+
+void geomancy_random_floor(int y, int x, bool_ kill_wall)
+{
+#define TABLE_SIZE 9
+ cave_type *c_ptr = &cave[y][x];
+ int feat = -1;
+ geomancy_entry table[TABLE_SIZE] = {
+ /* Fire element */
+ { SKILL_FIRE, FEAT_SAND, 1},
+ { SKILL_FIRE, FEAT_SHAL_LAVA, 8},
+ { SKILL_FIRE, FEAT_DEEP_LAVA, 18},
+ /* Water element */
+ { SKILL_WATER, FEAT_SHAL_WATER, 1},
+ { SKILL_WATER, FEAT_DEEP_WATER, 8},
+ { SKILL_WATER, FEAT_ICE, 18},
+ /* Earth element */
+ { SKILL_EARTH, FEAT_GRASS, 1},
+ { SKILL_EARTH, FEAT_FLOWER, 8},
+ { SKILL_EARTH, FEAT_DARK_PIT, 18}
+ };
+
+ /* Do not destroy permanent things */
+ if (f_info[c_ptr->feat].flags1 & FF1_PERMANENT) {
+ return;
+ }
+ if (!(kill_wall || (f_info[c_ptr->feat].flags1 & FF1_FLOOR))) {
+ return;
+ }
+
+ /* Choose feature */
+ feat = choose_geomancy_feature(TABLE_SIZE, table);
+ if (feat >= 0)
+ {
+ cave_set_feat(y, x, feat);
+ }
+#undef TABLE_SIZE
+}
+
+static bool_ geomancy_can_tunnel(int y, int x)
+{
+ switch (cave[y][x].feat)
+ {
+ case FEAT_WALL_EXTRA:
+ case FEAT_WALL_OUTER:
+ case FEAT_WALL_INNER:
+ case FEAT_WALL_SOLID:
+ case FEAT_MAGMA:
+ case FEAT_QUARTZ:
+ case FEAT_MAGMA_H:
+ case FEAT_QUARTZ_H:
+ case FEAT_MAGMA_K:
+ case FEAT_QUARTZ_K:
+ case FEAT_TREES:
+ case FEAT_DEAD_TREE:
+ case FEAT_SANDWALL:
+ case FEAT_SANDWALL_H:
+ case FEAT_SANDWALL_K:
+ case FEAT_ICE_WALL:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+void geomancy_dig(int oy, int ox, int dir, int length)
+{
+ int dy = ddy[dir];
+ int dx = ddx[dir];
+ int y = dy + oy;
+ int x = dx + ox;
+ int i;
+
+ for (i=0; i<length; i++)
+ {
+ /* stop at the end of tunnelable things */
+ if (!geomancy_can_tunnel(y, x)) {
+ break;
+ }
+
+ if (geomancy_can_tunnel(y - 1, x - 1)) { geomancy_random_wall(y - 1, x - 1); }
+ if (geomancy_can_tunnel(y - 1, x )) { geomancy_random_wall(y - 1, x ); }
+ if (geomancy_can_tunnel(y - 1, x + 1)) { geomancy_random_wall(y - 1, x + 1); }
+
+ if (geomancy_can_tunnel(y , x - 1)) { geomancy_random_wall(y , x - 1); }
+ if (geomancy_can_tunnel(y , x + 1)) { geomancy_random_wall(y , x + 1); }
+
+ if (geomancy_can_tunnel(y + 1, x - 1)) { geomancy_random_wall(y + 1, x - 1); }
+ if (geomancy_can_tunnel(y + 1, x )) { geomancy_random_wall(y + 1, x ); }
+ if (geomancy_can_tunnel(y + 1, x + 1)) { geomancy_random_wall(y + 1, x + 1); }
+
+ y = y + dy;
+ x = x + dx;
+ }
+
+ /* Step back towards origin */
+ y = y - dy;
+ x = x - dx;
+ while ((y != oy) || (x != ox))
+ {
+ geomancy_random_floor(y, x, TRUE);
+
+ /* Should we branch ? */
+ if (magik(20))
+ {
+ int rot = magik(50) ? -1 : 1;
+ geomancy_dig(y, x, rotate_dir(dir, rot), length / 3);
+ }
+
+ y = y - dy;
+ x = x - dx;
+ }
+}
+
+void channel_the_elements(int y, int x, int level)
+{
+ switch (cave[y][x].feat)
+ {
+ case FEAT_GRASS:
+ hp_player(p_ptr->mhp * (5 + get_skill_scale(SKILL_EARTH, 20)) / 100);
+ break;
+
+ case FEAT_FLOWER:
+ hp_player(p_ptr->mhp * (5 + get_skill_scale(SKILL_EARTH, 30)) / 100);
+ break;
+
+ case FEAT_DARK_PIT:
+ {
+ int dir, type;
+ if (!get_aim_dir(&dir)) break;
+
+ type = (get_skill(SKILL_EARTH) >= 18) ? GF_NETHER : GF_DARK;
+
+ fire_bolt(type, dir, damroll(10, get_skill(SKILL_EARTH)));
+
+ break;
+ }
+
+ case FEAT_SHAL_WATER:
+ {
+ int dir, type;
+ if (!get_aim_dir(&dir)) break;
+
+ type = (get_skill(SKILL_WATER) >= 18) ? GF_WAVE : GF_WATER;
+
+ if (get_skill(SKILL_WATER) >= 8)
+ {
+ fire_beam(type, dir, damroll(3, get_skill(SKILL_WATER)));
+ }
+ else
+ {
+ fire_bolt(type, dir, damroll(3, get_skill(SKILL_WATER)));
+ }
+
+ break;
+ }
+
+ case FEAT_DEEP_WATER:
+ {
+ int dir, type;
+ if (!get_aim_dir(&dir)) break;
+
+ type = (get_skill(SKILL_WATER) >= 18) ? GF_WAVE : GF_WATER;
+
+ if (get_skill(SKILL_WATER) >= 8)
+ {
+ fire_beam(type, dir, damroll(5, get_skill(SKILL_WATER)));
+ }
+ else
+ {
+ fire_bolt(type, dir, damroll(5, get_skill(SKILL_WATER)));
+ }
+
+ break;
+ }
+
+ case FEAT_ICE:
+ {
+ int dir;
+ if (!get_aim_dir(&dir)) break;
+
+ if (get_skill(SKILL_WATER) >= 12)
+ {
+ fire_ball(GF_ICE, dir, get_skill_scale(SKILL_WATER, 340), 3);
+ }
+ else
+ {
+ fire_bolt(GF_ICE, dir, damroll(3, get_skill(SKILL_WATER)));
+ }
+
+ break;
+ }
+
+ case FEAT_SAND:
+ {
+ int type, dur, FIERYAURA;
+
+ FIERYAURA = get_lua_int("FIERYAURA");
+ type = (get_level(FIERYAURA, 50, 1) >= 8) ? SHIELD_GREAT_FIRE : SHIELD_FIRE;
+
+ dur = randint(20) + level + get_skill(SKILL_AIR);
+ set_shield(dur, 0, type, 5 + get_skill_scale(SKILL_FIRE, 20), 5 + get_skill_scale(SKILL_FIRE, 14));
+ set_blind(dur);
+
+ break;
+ }
+
+ case FEAT_SHAL_LAVA:
+ {
+ int dir;
+ if (!get_aim_dir(&dir)) break;
+
+ if (get_skill(SKILL_FIRE) >= 15)
+ {
+ fire_bolt(GF_HELL_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15));
+ }
+ else
+ {
+ fire_bolt(GF_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15));
+ }
+
+ break;
+ }
+
+ case FEAT_DEEP_LAVA:
+ {
+ int dir;
+ if (!get_aim_dir(&dir)) break;
+
+ if (get_skill(SKILL_FIRE) >= 15)
+ {
+ fire_ball(GF_HELL_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15), 3);
+ }
+ else
+ {
+ fire_ball(GF_FIRE, dir, damroll(get_skill_scale(SKILL_FIRE, 30), 15), 3);
+ }
+
+ break;
+ }
+
+ default:
+ msg_print("You cannot channel this area.");
+ return;
+ }
+
+ /* Drain area? */
+ if (magik(100 - level))
+ {
+ if (cave[y][x].feat == FEAT_FLOWER)
+ {
+ cave_set_feat(y, x, FEAT_GRASS);
+ }
+ else
+ {
+ cave_set_feat(y, x, FEAT_FLOOR);
+ }
+ msg_print("The area is drained.");
+ }
+}