summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-06-10 06:47:09 +0200
committerBardur Arantsson <bardur@scientician.net>2012-06-10 08:27:15 +0200
commit01382b9ad17cf77a7f2867b8efce4ceb619392f7 (patch)
tree07798caa798bf61780e10dde198fb8659a9d0b3d /src
parent6f98f68a44ce9a24efe3ff2722d63ad327772f1b (diff)
Lua: Move Theme's stair handling to C
Diffstat (limited to 'src')
-rw-r--r--src/bldg.c8
-rw-r--r--src/cmd2.c34
-rw-r--r--src/defines.h1
-rw-r--r--src/modules.c89
-rw-r--r--src/types.h12
5 files changed, 142 insertions, 2 deletions
diff --git a/src/bldg.c b/src/bldg.c
index e35cc023..6b785d2a 100644
--- a/src/bldg.c
+++ b/src/bldg.c
@@ -2054,6 +2054,14 @@ bool_ bldg_process_command(store_type *s_ptr, int i)
break;
}
+ case BACT_EREBOR_KEY:
+ {
+ msg_print("You will need Thorin's Key and Thrain's Map"
+ " to get anywhere in Erebor. One may be found"
+ " in the Barrow-Downs. The other, in Mirkwood.");
+ break;
+ }
+
default:
{
if (process_hooks_ret(HOOK_BUILDING_ACTION, "dd", "(d)", bact))
diff --git a/src/cmd2.c b/src/cmd2.c
index 7689f46a..9149e76b 100644
--- a/src/cmd2.c
+++ b/src/cmd2.c
@@ -74,6 +74,30 @@ static bool_ do_cmd_bash_fountain(int y, int x)
return (more);
}
+/*
+ * Stair hooks
+ */
+static bool_ stair_hooks(stairs_direction direction)
+{
+ cptr direction_s = (direction == STAIRS_UP) ? "up" : "down";
+
+ /* Old-style hooks */
+ if (process_hooks(HOOK_STAIR, "(s)", direction_s))
+ {
+ return TRUE; /* Prevent movement */
+ }
+
+ /* New-style hooks */
+ {
+ hook_stair_in in = { direction };
+ hook_stair_out out = { TRUE }; /* Allow by default */
+
+ process_hooks_new(HOOK_STAIR, &in, &out);
+
+ return (!out.allow);
+ }
+}
+
/*
* Go up one level
@@ -93,7 +117,10 @@ void do_cmd_go_up(void)
c_ptr = &cave[p_ptr->py][p_ptr->px];
/* Can we ? */
- if (process_hooks(HOOK_STAIR, "(s)", "up")) return;
+ if (stair_hooks(STAIRS_UP))
+ {
+ return;
+ }
/* Normal up stairs */
if ((c_ptr->feat == FEAT_LESS) || (c_ptr->feat == FEAT_WAY_LESS))
@@ -318,7 +345,10 @@ void do_cmd_go_down(void)
}
/* Can we ? */
- if (process_hooks(HOOK_STAIR, "(s)", "down")) return;
+ if (stair_hooks(STAIRS_DOWN))
+ {
+ return;
+ }
/* Normal up stairs */
if (c_ptr->feat == FEAT_SHAFT_DOWN)
diff --git a/src/defines.h b/src/defines.h
index 2907d2a2..aad4614e 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -4053,6 +4053,7 @@
#define BACT_GET_ITEM 55
#define BACT_FIREPROOF_QUEST 56
#define BACT_LIBRARY_QUEST 61
+#define BACT_EREBOR_KEY 66
/* If one adds new BACT_ do NOT forget to increase max_bact in variables.c */
diff --git a/src/modules.c b/src/modules.c
index 72274003..d9c599d1 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -620,6 +620,85 @@ static bool_ food_vessel(void *data, void *in_, void *out)
return FALSE;
}
+/*
+ * Player must have appropriate keys to enter Erebor.
+ */
+static bool_ erebor_stair(void *data, void *in_, void *out_)
+{
+ hook_stair_in *in = (hook_stair_in *) in_;
+ hook_stair_out *out = (hook_stair_out *) out_;
+
+ if ((dungeon_type == 20) &&
+ (dun_level == 60) &&
+ (in->direction == STAIRS_DOWN))
+ {
+ int i, keys;
+
+ keys = 0;
+ for (i = 0; i < INVEN_TOTAL - 1; i++)
+ {
+ if ((p_ptr->inventory[i].name1 == 209) ||
+ (p_ptr->inventory[i].name1 == 210))
+ {
+ keys += 1;
+ }
+ }
+
+ if (keys >= 2)
+ {
+ msg_print("The moon-letters on the map show you "
+ "the keyhole! You use the key to enter.");
+ out->allow = TRUE;
+ }
+ else
+ {
+ msg_print("You have found a door, but you cannot "
+ "find a way to enter. Ask in Dale, perhaps?");
+ out->allow = FALSE;
+ }
+ }
+
+ return FALSE;
+}
+
+/*
+ * Orthanc requires a key.
+ */
+static bool_ orthanc_stair(void *data, void *in_, void *out_)
+{
+ hook_stair_in *in = (hook_stair_in *) in_;
+ hook_stair_out *out = (hook_stair_out *) out_;
+
+ if ((dungeon_type == 36) &&
+ (dun_level == 39) &&
+ (in->direction == STAIRS_DOWN))
+ {
+ int i, keys;
+
+ keys = 0;
+ for (i = 0; i < INVEN_TOTAL - 1; i++)
+ {
+ if (p_ptr->inventory[i].name1 == 15)
+ {
+ keys += 1;
+ }
+ }
+
+ if (keys >= 1)
+ {
+ msg_print("#BYou have the key to the tower of Orthanc! You may proceed.#w");
+ out->allow = TRUE;
+ }
+ else
+ {
+ msg_print("#yYou may not enter Orthanc without the key to the gates!#w Rumours say the key was lost in the Mines of Moria...");
+ out->allow = FALSE;
+ }
+ }
+
+ return FALSE;
+}
+
void init_hooks_module()
{
/*
@@ -667,6 +746,16 @@ void init_hooks_module()
"food_vessel",
NULL);
+ add_hook_new(HOOK_STAIR,
+ erebor_stair,
+ "erebor_stair",
+ NULL);
+
+ add_hook_new(HOOK_STAIR,
+ orthanc_stair,
+ "orthanc_stair",
+ NULL);
+
break;
}
diff --git a/src/types.h b/src/types.h
index f7dd6d40..ea383ff7 100644
--- a/src/types.h
+++ b/src/types.h
@@ -2303,6 +2303,18 @@ struct hook_eat_out {
bool_ ident;
};
+typedef enum { STAIRS_UP, STAIRS_DOWN } stairs_direction;
+
+typedef struct hook_stair_in hook_stair_in;
+struct hook_stair_in {
+ stairs_direction direction;
+};
+
+typedef struct hook_stair_out hook_stair_out;
+struct hook_stair_out {
+ bool_ allow;
+};
+
/*
* Structure for the "quests"
*/