summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-06 15:11:18 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-07 15:28:26 +0200
commite620b7e9e0b6a70f4c350c84a7c18ea2b523eab4 (patch)
tree3a2cd292bbc33923219289a23e75eebf69536ce6
parent8a0cd497bc0848adaefa56321321df7d0b19dd22 (diff)
Lua: Refactor HOOK_PROCESS_WORLD code from corrupt.lua to C
-rw-r--r--lib/mods/theme/scpt/corrupt.lua32
-rw-r--r--lib/scpt/corrupt.lua32
-rw-r--r--src/dungeon.c49
-rw-r--r--src/externs.h2
-rw-r--r--src/lua_bind.c7
5 files changed, 58 insertions, 64 deletions
diff --git a/lib/mods/theme/scpt/corrupt.lua b/lib/mods/theme/scpt/corrupt.lua
index dc750f0f..2f3d30ce 100644
--- a/lib/mods/theme/scpt/corrupt.lua
+++ b/lib/mods/theme/scpt/corrupt.lua
@@ -137,22 +137,6 @@ CORRUPT_RANDOM_TELEPORT = add_corruption
" Randomly teleports you around",
},
-- No oppose field, it will be automatically set when we declare the anti-telep corruption to oppose us
- ["hooks"] =
- {
- [HOOK_PROCESS_WORLD] = function()
- if rand_int(300) == 1 then
- if magik(70) == TRUE then
- if get_check("Teleport?") == TRUE then
- teleport_player(50)
- end
- else
- disturb(0, 0)
- msg_print("Your corruption takes over you, you teleport!")
- teleport_player(50)
- end
- end
- end,
- },
}
-- Anti-teleportation corruption, can be stopped with this power
@@ -170,22 +154,6 @@ CORRUPT_ANTI_TELEPORT = add_corruption
{
[CORRUPT_RANDOM_TELEPORT] = TRUE
},
- ["hooks"] =
- {
- [HOOK_PROCESS_WORLD] = function()
- if player.corrupt_anti_teleport_stopped == TRUE then
- local amt = player.msp + player.csp
- amt = amt / 100
- if (amt < 1) then amt = 1 end
- increase_mana(-amt)
- if player.csp == 0 then
- player.corrupt_anti_teleport_stopped = FALSE
- msg_print("You stop controlling your corruption.")
- player.update = bor(player.update, PU_BONUS)
- end
- end
- end,
- },
}
diff --git a/lib/scpt/corrupt.lua b/lib/scpt/corrupt.lua
index b9cae0b1..81690879 100644
--- a/lib/scpt/corrupt.lua
+++ b/lib/scpt/corrupt.lua
@@ -136,22 +136,6 @@ CORRUPT_RANDOM_TELEPORT = add_corruption
" Randomly teleports you around",
},
-- No oppose field, it will be automatically set when we declare the anti-telep corruption to oppose us
- ["hooks"] =
- {
- [HOOK_PROCESS_WORLD] = function()
- if rand_int(300) == 1 then
- if magik(70) == TRUE then
- if get_check("Teleport?") == TRUE then
- teleport_player(50)
- end
- else
- disturb(0, 0)
- msg_print("Your corruption takes over you, you teleport!")
- teleport_player(50)
- end
- end
- end,
- },
}
-- Anti-teleportation corruption, can be stopped with this power
@@ -169,22 +153,6 @@ CORRUPT_ANTI_TELEPORT = add_corruption
{
[CORRUPT_RANDOM_TELEPORT] = TRUE
},
- ["hooks"] =
- {
- [HOOK_PROCESS_WORLD] = function()
- if player.corrupt_anti_teleport_stopped == TRUE then
- local amt = player.msp + player.csp
- amt = amt / 100
- if (amt < 1) then amt = 1 end
- increase_mana(-amt)
- if player.csp == 0 then
- player.corrupt_anti_teleport_stopped = FALSE
- msg_print("You stop controlling your corruption.")
- player.update = bor(player.update, PU_BONUS)
- end
- end
- end,
- },
}
diff --git a/src/dungeon.c b/src/dungeon.c
index 9b384dce..bcd727ca 100644
--- a/src/dungeon.c
+++ b/src/dungeon.c
@@ -1016,6 +1016,52 @@ bool_ is_recall = FALSE;
/*
+ * Hook for corruptions
+ */
+static void process_world_corruptions()
+{
+ if (player_has_corruption(CORRUPT_RANDOM_TELEPORT))
+ {
+ if (rand_int(300) == 1)
+ {
+ if (magik(70))
+ {
+ if (get_check("Teleport?"))
+ {
+ teleport_player(50);
+ }
+ else
+ {
+ disturb(0, 0);
+ msg_print("Your corruption takes over you, you teleport!");
+ teleport_player(50);
+ }
+ }
+ }
+ }
+
+ if (player_has_corruption(CORRUPT_ANTI_TELEPORT))
+ {
+ if (p_ptr->corrupt_anti_teleport_stopped)
+ {
+ int amt = p_ptr->msp + p_ptr->csp;
+ amt = amt / 100;
+ if (amt < 1) {
+ amt = 1;
+ }
+ increase_mana(-amt);
+ if (p_ptr->csp == 0)
+ {
+ p_ptr->corrupt_anti_teleport_stopped = FALSE;
+ msg_print("You stop controlling your corruption.");
+ p_ptr->update = p_ptr->update | PU_BONUS;
+ }
+ }
+ }
+}
+
+
+/*
* Handle certain things once every 10 game turns
*
* Note that a single movement in the overhead wilderness mode
@@ -1061,6 +1107,9 @@ static void process_world(void)
/* Let the script live! */
process_hooks(HOOK_PROCESS_WORLD, "()");
+ /* Handle corruptions */
+ process_world_corruptions();
+
/* Handle the player song */
check_music();
}
diff --git a/src/externs.h b/src/externs.h
index 3a0d8191..28386ef7 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -1880,6 +1880,8 @@ extern cptr approximate_distance(int y, int x, int y2, int x2);
extern bool_ drop_text_left(byte c, cptr s, int y, int o);
extern bool_ drop_text_right(byte c, cptr s, int y, int o);
+extern void increase_mana(int delta);
+
/* q_library.c */
extern void library_quest_fill_book();
extern int library_quest_book_slots_left();
diff --git a/src/lua_bind.c b/src/lua_bind.c
index e9eb95a0..b83fc190 100644
--- a/src/lua_bind.c
+++ b/src/lua_bind.c
@@ -854,3 +854,10 @@ bool_ drop_text_right(byte c, cptr str, int y, int o)
}
return FALSE;
}
+
+void increase_mana(int delta)
+{
+ char buf[256];
+ sprintf(buf, "increase_mana(%d)", delta);
+ exec_lua(buf);
+}