summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-05-12 18:30:39 +0200
committerBardur Arantsson <bardur@scientician.net>2012-05-13 08:01:24 +0200
commit6d8f14307f6e9ad22c7b34ad7a7058537cb6b738 (patch)
treef1e43c74f21dc3915a70b41e07c2e783cf713074
parentafbec09fcf9a57ecb401267f7a4e23b270853e2c (diff)
Lua: Move "Nature" spell functions to C
-rw-r--r--lib/mods/theme/scpt/s_nature.lua70
-rw-r--r--lib/scpt/s_nature.lua59
-rw-r--r--src/externs.h20
-rw-r--r--src/spells.pkg20
-rw-r--r--src/spells3.c153
5 files changed, 215 insertions, 107 deletions
diff --git a/lib/mods/theme/scpt/s_nature.lua b/lib/mods/theme/scpt/s_nature.lua
index 3d44c569..e41a6990 100644
--- a/lib/mods/theme/scpt/s_nature.lua
+++ b/lib/mods/theme/scpt/s_nature.lua
@@ -9,13 +9,8 @@ GROWTREE = add_spell
["mana_max"] = 30,
["fail"] = 35,
["inertia"] = { 5, 50 },
- ["spell"] = function()
- grow_trees(2 + get_level(GROWTREE, 7))
- return TRUE
- end,
- ["info"] = function()
- return "rad "..(2 + get_level(GROWTREE, 7))
- end,
+ ["spell"] = function() return nature_grow_trees() end,
+ ["info"] = function() return nature_grow_trees_info() end,
["desc"] = {
"Makes trees grow extremely quickly around you",
}
@@ -39,12 +34,8 @@ HEALING = add_spell
["max_level"] = { 20, 40 },
},
},
- ["spell"] = function()
- return hp_player(player.mhp * (15 + get_level(HEALING, 35)) / 100)
- end,
- ["info"] = function()
- return "heal "..(15 + get_level(HEALING, 35)).."% = "..(player.mhp * (15 + get_level(HEALING, 35)) / 100).."hp"
- end,
+ ["spell"] = function() return nature_healing() end,
+ ["info"] = function() return nature_healing_info() end,
["desc"] = {
"Heals a percent of hitpoints",
}
@@ -69,29 +60,8 @@ RECOVERY = add_spell
},
},
["inertia"] = { 2, 100 },
- ["spell"] = function()
- local obvious
- obvious = set_poisoned(player.poisoned / 2)
- if get_level(RECOVERY, 50) >= 5 then
- obvious = is_obvious(set_poisoned(0), obvious)
- obvious = is_obvious(set_cut(0), obvious)
- end
- if get_level(RECOVERY, 50) >= 10 then
- obvious = is_obvious(do_res_stat(A_STR, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_CON, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_DEX, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_WIS, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_INT, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_CHR, TRUE), obvious)
- end
- if get_level(RECOVERY, 50) >= 15 then
- obvious = is_obvious(restore_level(), obvious)
- end
- return obvious
- end,
- ["info"] = function()
- return ""
- end,
+ ["spell"] = function() return nature_recovery() end,
+ ["info"] = function() return nature_recovery_info() end,
["desc"] = {
"Reduces the length of time that you are poisoned",
"At level 5 it cures poison and cuts",
@@ -109,12 +79,8 @@ REGENERATION = add_spell
["mana_max"] = 55,
["fail"] = 70,
["inertia"] = { 4, 40 },
- ["spell"] = function()
- if player.tim_regen == 0 then return set_tim_regen(randint(10) + 5 + get_level(REGENERATION, 50), 300 + get_level(REGENERATION, 700)) end
- end,
- ["info"] = function()
- return "dur "..(5 + get_level(REGENERATION, 50)).."+d10 power "..(300 + get_level(REGENERATION, 700))
- end,
+ ["spell"] = function() return nature_regeneration() end,
+ ["info"] = function() return nature_regeneration_info() end,
["desc"] = {
"Increases your body's regeneration rate",
}
@@ -139,13 +105,8 @@ SUMMONANNIMAL = add_spell
["max_level"] = { 15, 45 },
},
},
- ["spell"] = function()
- summon_specific_level = 25 + get_level(SUMMONANNIMAL, 50)
- return summon_monster(player.py, player.px, dun_level, TRUE, SUMMON_ANIMAL)
- end,
- ["info"] = function()
- return "level "..(25 + get_level(SUMMONANNIMAL, 50))
- end,
+ ["spell"] = function() return nature_summon_animal() end,
+ ["info"] = function() return nature_summon_animal_info() end,
["desc"] = {
"Summons a leveled animal to your aid",
}
@@ -169,15 +130,8 @@ GROW_ATHELAS = add_spell {
["max_level"] = { 15, 45 },
},
},
- ["spell"] = function()
- if (player.black_breath == TRUE) then
- msg_print("The hold of the Black Breath on you is broken!")
- player.black_breath = FALSE
- end
- end,
- ["info"] = function()
- return ""
- end,
+ ["spell"] = function() return nature_grow_athelas() end,
+ ["info"] = function() return nature_grow_athelas_info() end,
["desc"] = {
"Cures the Black Breath",
}
diff --git a/lib/scpt/s_nature.lua b/lib/scpt/s_nature.lua
index e71a89bf..d47dbe8f 100644
--- a/lib/scpt/s_nature.lua
+++ b/lib/scpt/s_nature.lua
@@ -9,13 +9,8 @@ GROWTREE = add_spell
["mana_max"] = 30,
["fail"] = 35,
["inertia"] = { 5, 50 },
- ["spell"] = function()
- grow_trees(2 + get_level(GROWTREE, 7))
- return TRUE
- end,
- ["info"] = function()
- return "rad "..(2 + get_level(GROWTREE, 7))
- end,
+ ["spell"] = function() return nature_grow_trees() end,
+ ["info"] = function() return nature_grow_trees_info() end,
["desc"] = {
"Makes trees grow extremely quickly around you",
}
@@ -39,12 +34,8 @@ HEALING = add_spell
["max_level"] = { 20, 40 },
},
},
- ["spell"] = function()
- return hp_player(player.mhp * (15 + get_level(HEALING, 35)) / 100)
- end,
- ["info"] = function()
- return "heal "..(15 + get_level(HEALING, 35)).."% = "..(player.mhp * (15 + get_level(HEALING, 35)) / 100).."hp"
- end,
+ ["spell"] = function() return nature_healing() end,
+ ["info"] = function() return nature_healing_info() end,
["desc"] = {
"Heals a percent of hitpoints",
}
@@ -69,29 +60,8 @@ RECOVERY = add_spell
},
},
["inertia"] = { 2, 100 },
- ["spell"] = function()
- local obvious
- obvious = set_poisoned(player.poisoned / 2)
- if get_level(RECOVERY, 50) >= 5 then
- obvious = is_obvious(set_poisoned(0), obvious)
- obvious = is_obvious(set_cut(0), obvious)
- end
- if get_level(RECOVERY, 50) >= 10 then
- obvious = is_obvious(do_res_stat(A_STR, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_CON, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_DEX, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_WIS, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_INT, TRUE), obvious)
- obvious = is_obvious(do_res_stat(A_CHR, TRUE), obvious)
- end
- if get_level(RECOVERY, 50) >= 15 then
- obvious = is_obvious(restore_level(), obvious)
- end
- return obvious
- end,
- ["info"] = function()
- return ""
- end,
+ ["spell"] = function() return nature_recovery() end,
+ ["info"] = function() return nature_recovery_info() end,
["desc"] = {
"Reduces the length of time that you are poisoned",
"At level 5 it cures poison and cuts",
@@ -109,12 +79,8 @@ REGENERATION = add_spell
["mana_max"] = 55,
["fail"] = 70,
["inertia"] = { 4, 40 },
- ["spell"] = function()
- if player.tim_regen == 0 then return set_tim_regen(randint(10) + 5 + get_level(REGENERATION, 50), 300 + get_level(REGENERATION, 700)) end
- end,
- ["info"] = function()
- return "dur "..(5 + get_level(REGENERATION, 50)).."+d10 power "..(300 + get_level(REGENERATION, 700))
- end,
+ ["spell"] = function() return nature_regeneration() end,
+ ["info"] = function() return nature_regeneration_info() end,
["desc"] = {
"Increases your body's regeneration rate",
}
@@ -139,13 +105,8 @@ SUMMONANNIMAL = add_spell
["max_level"] = { 15, 45 },
},
},
- ["spell"] = function()
- summon_specific_level = 25 + get_level(SUMMONANNIMAL, 50)
- return summon_monster(player.py, player.px, dun_level, TRUE, SUMMON_ANIMAL)
- end,
- ["info"] = function()
- return "level "..(25 + get_level(SUMMONANNIMAL, 50))
- end,
+ ["spell"] = function() return nature_summon_animal() end,
+ ["info"] = function() return nature_summon_animal_info() end,
["desc"] = {
"Summons a leveled animal to your aid",
}
diff --git a/src/externs.h b/src/externs.h
index c19a83ed..914cea73 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -1716,6 +1716,26 @@ char *yavanna_water_bite_info();
bool_ *yavanna_uproot();
char *yavanna_uproot_info();
+extern s32b GROWTREE;
+extern s32b HEALING;
+extern s32b RECOVERY;
+extern s32b REGENERATION;
+extern s32b SUMMONANNIMAL;
+extern s32b GROW_ATHELAS;
+
+bool_ *nature_grow_trees();
+char *nature_grow_trees_info();
+bool_ *nature_healing();
+char *nature_healing_info();
+bool_ *nature_recovery();
+char *nature_recovery_info();
+bool_ *nature_regeneration();
+char *nature_regeneration_info();
+bool_ *nature_summon_animal();
+char *nature_summon_animal_info();
+bool_ *nature_grow_athelas();
+char *nature_grow_athelas_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 73539162..33459936 100644
--- a/src/spells.pkg
+++ b/src/spells.pkg
@@ -2719,3 +2719,23 @@ bool_ *yavanna_water_bite();
char *yavanna_water_bite_info();
bool_ *yavanna_uproot();
char *yavanna_uproot_info();
+
+extern s32b GROWTREE;
+extern s32b HEALING;
+extern s32b RECOVERY;
+extern s32b REGENERATION;
+extern s32b SUMMONANNIMAL;
+extern s32b GROW_ATHELAS;
+
+bool_ *nature_grow_trees();
+char *nature_grow_trees_info();
+bool_ *nature_healing();
+char *nature_healing_info();
+bool_ *nature_recovery();
+char *nature_recovery_info();
+bool_ *nature_regeneration();
+char *nature_regeneration_info();
+bool_ *nature_summon_animal();
+char *nature_summon_animal_info();
+bool_ *nature_grow_athelas();
+char *nature_grow_athelas_info();
diff --git a/src/spells3.c b/src/spells3.c
index c6702151..2bef9931 100644
--- a/src/spells3.c
+++ b/src/spells3.c
@@ -111,6 +111,13 @@ s32b YAVANNA_TREE_ROOTS;
s32b YAVANNA_WATER_BITE;
s32b YAVANNA_UPROOT;
+s32b GROWTREE;
+s32b HEALING;
+s32b RECOVERY;
+s32b REGENERATION;
+s32b SUMMONANNIMAL;
+s32b GROW_ATHELAS = -1;
+
/* 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
@@ -3374,3 +3381,149 @@ char *yavanna_uproot_info()
return buf;
}
+static int nature_grow_trees_radius()
+{
+ return 2 + get_level_s(GROWTREE, 7);
+}
+
+bool_ *nature_grow_trees()
+{
+ grow_trees(nature_grow_trees_radius());
+ return CAST;
+}
+
+char *nature_grow_trees_info()
+{
+ static char buf[128];
+ sprintf(buf,
+ "rad %d",
+ nature_grow_trees_radius());
+ return buf;
+}
+
+static int nature_healing_percentage()
+{
+ return 15 + get_level_s(HEALING, 35);
+}
+
+static int nature_healing_hp()
+{
+ return p_ptr->mhp * nature_healing_percentage() / 100;
+}
+
+bool_ *nature_healing()
+{
+ hp_player(nature_healing_hp());
+ return CAST;
+}
+
+char *nature_healing_info()
+{
+ static char buf[128];
+ sprintf(buf,
+ "heal %d%% = %dhp",
+ nature_healing_percentage(),
+ nature_healing_hp());
+ return buf;
+}
+
+bool_ *nature_recovery()
+{
+ set_poisoned(p_ptr->poisoned / 2);
+ if (get_level_s(RECOVERY, 50) >= 5)
+ {
+ set_poisoned(0);
+ set_cut(0);
+ }
+ if (get_level_s(RECOVERY, 50) >= 10)
+ {
+ do_res_stat(A_STR, TRUE);
+ do_res_stat(A_CON, TRUE);
+ do_res_stat(A_DEX, TRUE);
+ do_res_stat(A_WIS, TRUE);
+ do_res_stat(A_INT, TRUE);
+ do_res_stat(A_CHR, TRUE);
+ }
+ if (get_level_s(RECOVERY, 50) >= 15)
+ {
+ restore_level();
+ }
+ return CAST;
+}
+
+char *nature_recovery_info()
+{
+ return "";
+}
+
+static int regeneration_base_duration()
+{
+ return 5 + get_level_s(REGENERATION, 50);
+}
+
+static int regeneration_power()
+{
+ return 300 + get_level_s(REGENERATION, 700);
+}
+
+bool_ *nature_regeneration()
+{
+ if (p_ptr->tim_regen == 0)
+ {
+ set_tim_regen(randint(10) + regeneration_base_duration(),
+ regeneration_power());
+ return CAST;
+ }
+ return NO_CAST;
+}
+
+char *nature_regeneration_info()
+{
+ static char buf[128];
+ sprintf(buf,
+ "dur %d+d10 power %d",
+ regeneration_base_duration(),
+ regeneration_power());
+ return buf;
+}
+
+static int summon_animal_level()
+{
+ return 25 + get_level_s(SUMMONANNIMAL, 50);
+}
+
+bool_ *nature_summon_animal()
+{
+ summon_specific_level = summon_animal_level();
+ summon_specific_friendly(p_ptr->py,
+ p_ptr->px,
+ dun_level,
+ SUMMON_ANIMAL,
+ TRUE);
+ return CAST;
+}
+
+char *nature_summon_animal_info()
+{
+ static char buf[128];
+ sprintf(buf,
+ "level %d",
+ summon_animal_level());
+ return buf;
+}
+
+bool_ *nature_grow_athelas()
+{
+ if (p_ptr->black_breath)
+ {
+ msg_print("The hold of the Black Breath on you is broken!");
+ p_ptr->black_breath = FALSE;
+ }
+
+ return CAST;
+}
+
+char *nature_grow_athelas_info()
+{
+ return "";
+}