summaryrefslogtreecommitdiff
path: root/src
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 /src
parent8a0cd497bc0848adaefa56321321df7d0b19dd22 (diff)
Lua: Refactor HOOK_PROCESS_WORLD code from corrupt.lua to C
Diffstat (limited to 'src')
-rw-r--r--src/dungeon.c49
-rw-r--r--src/externs.h2
-rw-r--r--src/lua_bind.c7
3 files changed, 58 insertions, 0 deletions
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);
+}