summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-11 19:44:49 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-11 19:51:07 +0200
commit571ab5e1b1e20c8dc87a48a518caeee6f4e8a825 (patch)
tree61e2879f2d76209084fa748d420efd0317052c65
parenteaeaf76609a894e52f12dbbd35597aebbabb113a (diff)
Lua: Move intros to C
-rw-r--r--lib/mods/theme/scpt/init.lua3
-rw-r--r--lib/mods/theme/scpt/intro.lua43
-rw-r--r--lib/scpt/init.lua3
-rw-r--r--lib/scpt/intro.lua39
-rw-r--r--src/defines.h1
-rw-r--r--src/dungeon.c3
-rw-r--r--src/externs.h5
-rw-r--r--src/lua_bind.c70
-rw-r--r--src/modules.c199
-rw-r--r--src/tables.c4
-rw-r--r--src/types.h2
-rw-r--r--src/util.pkg9
12 files changed, 209 insertions, 172 deletions
diff --git a/lib/mods/theme/scpt/init.lua b/lib/mods/theme/scpt/init.lua
index 300dc66b..cf291ab2 100644
--- a/lib/mods/theme/scpt/init.lua
+++ b/lib/mods/theme/scpt/init.lua
@@ -27,9 +27,6 @@ tome_dofile("joke.lua")
-- Some tests, if the file is not present, this is fine
tome_dofile_anywhere(ANGBAND_DIR_SCPT, "dg_test.lua", FALSE)
--- A nice custom intro :)
-tome_dofile("intro.lua")
-
-- Add monster interaction
tome_dofile("monsters.lua")
diff --git a/lib/mods/theme/scpt/intro.lua b/lib/mods/theme/scpt/intro.lua
deleted file mode 100644
index 3cdce225..00000000
--- a/lib/mods/theme/scpt/intro.lua
+++ /dev/null
@@ -1,43 +0,0 @@
-function tome_intro()
- screen_save()
- Term_clear()
-
- if (TRUE == drop_text_left(TERM_L_BLUE, "Three Rings for the Elven-kings under the sky,", 10, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_BLUE, "Seven for the Dwarf-lords in their halls of stone,", 11, -1)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_L_BLUE, "Nine for Mortal Men doomed to die,", 12, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_BLUE, "One for the Dark Lord on his dark throne", 13, -1)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_L_BLUE, "In the land of Mordor, where the Shadows lie.", 14, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_BLUE, "One Ring to rule them all, One Ring to find them,", 15, -1)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_L_BLUE, "One Ring to bring them all and in the darkness bind them", 16, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_BLUE, "In the land of Mordor, where the Shadows lie.", 17, -1)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_GREEN, "--J.R.R. Tolkien", 18, 0)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_WHITE, "[Press any key to continue]", 23, -1)) then screen_load() return end
-
- Term_putch(0, 0, TERM_DARK, 32)
- inkey_scan = FALSE
- inkey()
-
- Term_clear()
-
- if (TRUE == drop_text_left(TERM_L_BLUE, "furiosity", 8, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_WHITE, "in collaboration with", 9, -1)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_L_GREEN, "DarkGod and all the ToME contributors,", 10, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_GREEN, "module creators, t-o-m-e.net forum posters,", 11, -1)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_WHITE, "and", 12, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_GREEN, "by the grace of the Valar", 13, -1)) then screen_load() return end
-
- if (TRUE == drop_text_left(TERM_WHITE, "present", 15, 1)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_YELLOW, "Theme (a module for ToME)", 16, 0)) then screen_load() return end
-
- if (TRUE == drop_text_left(TERM_WHITE, "[Press any key to continue]", 23, -1)) then screen_load() return end
- Term_putch(0, 0, TERM_DARK, 32)
-
- inkey_scan = FALSE
-
- inkey()
-
- screen_load()
- return
-end
-
-add_hook_script(HOOK_INIT, "tome_intro", "lua_intro_init")
diff --git a/lib/scpt/init.lua b/lib/scpt/init.lua
index fa066d7f..5d8fb5e8 100644
--- a/lib/scpt/init.lua
+++ b/lib/scpt/init.lua
@@ -26,6 +26,3 @@ tome_dofile("joke.lua")
-- Some tests, if the file is not present, this is fine
tome_dofile_anywhere(ANGBAND_DIR_SCPT, "dg_test.lua", FALSE)
-
--- A nice custom intro :)
-tome_dofile("intro.lua")
diff --git a/lib/scpt/intro.lua b/lib/scpt/intro.lua
deleted file mode 100644
index ef6041a5..00000000
--- a/lib/scpt/intro.lua
+++ /dev/null
@@ -1,39 +0,0 @@
-function tome_intro()
- screen_save()
- Term_clear()
-
- if (TRUE == drop_text_left(TERM_L_BLUE, "Art thou an adventurer,", 10, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_BLUE, "One who passes through the waterfalls we call danger", 11, -1)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_L_BLUE, "to find the true nature of the legends beyond them?", 12, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_BLUE, "If this is so, then seeketh me.", 13, -1)) then screen_load() return end
-
- if (TRUE == drop_text_left(TERM_WHITE, "[Press any key to continue]", 23, -1)) then screen_load() return end
-
- Term_putch(0, 0, TERM_DARK, 32)
- inkey_scan = FALSE
- inkey()
-
- Term_clear()
-
- if (TRUE == drop_text_left(TERM_L_BLUE, "DarkGod", 8, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_WHITE, "in collaboration with", 9, -1)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_L_GREEN, "Eru Iluvatar,", 10, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_GREEN, "Manwe", 11, -1)) then screen_load() return end
- if (TRUE == drop_text_left(TERM_WHITE, "and", 12, 0)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_L_GREEN, "All the T.o.M.E. contributors(see credits.txt)", 13, -1)) then screen_load() return end
-
- if (TRUE == drop_text_left(TERM_WHITE, "present", 15, 1)) then screen_load() return end
- if (TRUE == drop_text_right(TERM_YELLOW, "T.o.M.E.", 16, 0)) then screen_load() return end
-
- if (TRUE == drop_text_left(TERM_WHITE, "[Press any key to continue]", 23, -1)) then screen_load() return end
- Term_putch(0, 0, TERM_DARK, 32)
-
- inkey_scan = FALSE
-
- inkey()
-
- screen_load()
- return
-end
-
-add_hook_script(HOOK_INIT, "tome_intro", "lua_intro_init")
diff --git a/src/defines.h b/src/defines.h
index 04920e63..439048e8 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -4504,7 +4504,6 @@
#define HOOK_MONSTER_AI 19
#define HOOK_PLAYER_LEVEL 20
#define HOOK_WIELD 21
-#define HOOK_INIT 22
#define HOOK_AIM 24
#define HOOK_USE 25
#define HOOK_ACTIVATE 26
diff --git a/src/dungeon.c b/src/dungeon.c
index 57aafb0b..ec2ab0e4 100644
--- a/src/dungeon.c
+++ b/src/dungeon.c
@@ -5567,7 +5567,8 @@ void play_game(bool_ new_game)
/* Roll new character */
if (new_game)
{
- process_hooks(HOOK_INIT, "()");
+ /* Show intro */
+ modules[game_module_idx].intro();
/* The dungeon is not ready */
character_dungeon = FALSE;
diff --git a/src/externs.h b/src/externs.h
index cfb07bbd..4dd5424f 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -1771,6 +1771,8 @@ extern void module_reset_dir(cptr dir, cptr new_path);
extern cptr force_module;
extern bool_ select_module(void);
extern bool_ module_savefile_loadable(cptr savefile_mod);
+extern void tome_intro();
+extern void theme_intro();
/* lua_bind.c */
@@ -1828,9 +1830,6 @@ extern void lua_delete_list(list_type *, int size);
extern void lua_add_to_list(list_type *, int idx, cptr str);
extern void lua_display_list(int y, int x, int h, int w, cptr title, list_type *list, int max, int begin, int sel, byte sel_color);
-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);
/* skills.c */
diff --git a/src/lua_bind.c b/src/lua_bind.c
index fd7d9cbb..a01b1fbc 100644
--- a/src/lua_bind.c
+++ b/src/lua_bind.c
@@ -542,76 +542,6 @@ int get_lua_int(cptr name)
return exec_lua(format("return %s", name));
}
-bool_ drop_text_left(byte c, cptr str, int y, int o)
-{
- int i = strlen(str);
- int x = 39 - (strlen(str) / 2) + o;
- while (i > 0)
- {
- int a = 0;
- int time = 0;
-
- if (str[i-1] != ' ')
- {
- while (a < x + i - 1)
- {
- Term_putch(a - 1, y, c, 32);
- Term_putch(a, y, c, str[i-1]);
- time = time + 1;
- if (time >= 4)
- {
- Term_xtra(TERM_XTRA_DELAY, 1);
- time = 0;
- }
- Term_redraw_section(a - 1, y, a, y);
- a = a + 1;
-
- inkey_scan = TRUE;
- if (inkey()) {
- return TRUE;
- }
- }
- }
-
- i = i - 1;
- }
- return FALSE;
-}
-
-bool_ drop_text_right(byte c, cptr str, int y, int o)
-{
- int x = 39 - (strlen(str) / 2) + o;
- int i = 1;
- while (i <= strlen(str))
- {
- int a = 79;
- int time = 0;
-
- if (str[i-1] != ' ') {
- while (a >= x + i - 1)
- {
- Term_putch(a + 1, y, c, 32);
- Term_putch(a, y, c, str[i-1]);
- time = time + 1;
- if (time >= 4) {
- Term_xtra(TERM_XTRA_DELAY, 1);
- time = 0;
- }
- Term_redraw_section(a, y, a + 1, y);
- a = a - 1;
-
- inkey_scan = TRUE;
- if (inkey()) {
- return TRUE;
- }
- }
- }
-
- i = i + 1;
- }
- return FALSE;
-}
-
void increase_mana(int delta)
{
char buf[256];
diff --git a/src/modules.c b/src/modules.c
index 5f582d92..8a4c5644 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -296,3 +296,202 @@ bool_ select_module()
/* Shouldnt happen */
return (FALSE);
}
+
+static bool_ dleft(byte c, cptr str, int y, int o)
+{
+ int i = strlen(str);
+ int x = 39 - (strlen(str) / 2) + o;
+ while (i > 0)
+ {
+ int a = 0;
+ int time = 0;
+
+ if (str[i-1] != ' ')
+ {
+ while (a < x + i - 1)
+ {
+ Term_putch(a - 1, y, c, 32);
+ Term_putch(a, y, c, str[i-1]);
+ time = time + 1;
+ if (time >= 4)
+ {
+ Term_xtra(TERM_XTRA_DELAY, 1);
+ time = 0;
+ }
+ Term_redraw_section(a - 1, y, a, y);
+ a = a + 1;
+
+ inkey_scan = TRUE;
+ if (inkey()) {
+ return TRUE;
+ }
+ }
+ }
+
+ i = i - 1;
+ }
+ return FALSE;
+}
+
+static bool_ dright(byte c, cptr str, int y, int o)
+{
+ int x = 39 - (strlen(str) / 2) + o;
+ int i = 1;
+ while (i <= strlen(str))
+ {
+ int a = 79;
+ int time = 0;
+
+ if (str[i-1] != ' ') {
+ while (a >= x + i - 1)
+ {
+ Term_putch(a + 1, y, c, 32);
+ Term_putch(a, y, c, str[i-1]);
+ time = time + 1;
+ if (time >= 4) {
+ Term_xtra(TERM_XTRA_DELAY, 1);
+ time = 0;
+ }
+ Term_redraw_section(a, y, a + 1, y);
+ a = a - 1;
+
+ inkey_scan = TRUE;
+ if (inkey()) {
+ return TRUE;
+ }
+ }
+ }
+
+ i = i + 1;
+ }
+ return FALSE;
+}
+
+typedef struct intro_text intro_text;
+struct intro_text
+{
+ bool_ (*drop_func)(byte, cptr, int, int);
+ byte color;
+ cptr text;
+ int y0;
+ int x0;
+};
+
+static bool_ show_intro(intro_text intro_texts[])
+{
+ int i = 0;
+
+ Term_clear();
+ for (i = 0; ; i++)
+ {
+ intro_text *it = &intro_texts[i];
+ if (it->drop_func == NULL)
+ {
+ break;
+ }
+ else if (it->drop_func(it->color, it->text, it->y0, it->x0))
+ {
+ /* Abort */
+ return TRUE;
+ }
+ }
+
+ /* Wait for key */
+ Term_putch(0, 0, TERM_DARK, 32);
+ inkey_scan = FALSE;
+ inkey();
+
+ /* Continue */
+ return FALSE;
+}
+
+void tome_intro()
+{
+ intro_text intro1[] =
+ {
+ { dleft , TERM_L_BLUE, "Art thou an adventurer,", 10, 0, },
+ { dright, TERM_L_BLUE, "One who passes through the waterfalls we call danger", 11, -1, },
+ { dleft , TERM_L_BLUE, "to find the true nature of the legends beyond them?", 12, 0, },
+ { dright, TERM_L_BLUE, "If this is so, then seeketh me.", 13, -1, },
+ { dleft , TERM_WHITE , "[Press any key to continue]", 23, -1, },
+ { NULL, }
+ };
+ intro_text intro2[] =
+ {
+ { dleft , TERM_L_BLUE , "DarkGod", 8, 0, },
+ { dright, TERM_WHITE , "in collaboration with", 9, -1, },
+ { dleft , TERM_L_GREEN, "Eru Iluvatar,", 10, 0, },
+ { dright, TERM_L_GREEN, "Manwe", 11, -1, },
+ { dleft , TERM_WHITE , "and", 12, 0, },
+ { dright, TERM_L_GREEN, "All the T.o.M.E. contributors(see credits.txt)", 13, -1, },
+ { dleft , TERM_WHITE , "present", 15, 1, },
+ { dright, TERM_YELLOW , "T.o.M.E.", 16, 0, },
+ { dleft , TERM_WHITE , "[Press any key to continue]", 23, -1, },
+ { NULL, }
+ };
+
+ screen_save();
+
+ /* Intro 1 */
+ if (show_intro(intro1))
+ {
+ goto exit;
+ }
+
+ /* Intro 2 */
+ if (show_intro(intro2))
+ {
+ goto exit;
+ }
+
+exit:
+ screen_load();
+}
+
+void theme_intro()
+{
+ struct intro_text intro1[] =
+ {
+ { dleft , TERM_L_BLUE , "Three Rings for the Elven-kings under the sky,", 10, 0, },
+ { dright, TERM_L_BLUE , "Seven for the Dwarf-lords in their halls of stone,", 11, -1, },
+ { dleft , TERM_L_BLUE , "Nine for Mortal Men doomed to die,", 12, 0, },
+ { dright, TERM_L_BLUE , "One for the Dark Lord on his dark throne", 13, -1, },
+ { dleft , TERM_L_BLUE , "In the land of Mordor, where the Shadows lie.", 14, 0, },
+ { dright, TERM_L_BLUE , "One Ring to rule them all, One Ring to find them,", 15, -1, },
+ { dleft , TERM_L_BLUE , "One Ring to bring them all and in the darkness bind them", 16, 0, },
+ { dright, TERM_L_BLUE , "In the land of Mordor, where the Shadows lie.", 17, -1, },
+ { dright, TERM_L_GREEN, "--J.R.R. Tolkien", 18, 0, },
+ { dleft , TERM_WHITE , "[Press any key to continue]", 23, -1, },
+ { NULL, },
+ };
+ struct intro_text intro2[] =
+ {
+ { dleft , TERM_L_BLUE , "furiosity", 8, 0, },
+ { dright, TERM_WHITE , "in collaboration with", 9, -1, },
+ { dleft , TERM_L_GREEN, "DarkGod and all the ToME contributors,", 10, 0, },
+ { dright, TERM_L_GREEN, "module creators, t-o-m-e.net forum posters,", 11, -1, },
+ { dleft , TERM_WHITE , "and", 12, 0, },
+ { dright, TERM_L_GREEN, "by the grace of the Valar", 13, -1, },
+ { dleft , TERM_WHITE , "present", 15, 1, },
+ { dright, TERM_YELLOW , "Theme (a module for ToME)", 16, 0, },
+ { dleft , TERM_WHITE , "[Press any key to continue]", 23, -1, },
+ { NULL, },
+ };
+
+ screen_save();
+
+ /* Intro 1 */
+ if (show_intro(intro1))
+ {
+ goto exit;
+ }
+
+ /* Intro 2 */
+ if (show_intro(intro2))
+ {
+ goto exit;
+ }
+
+exit:
+ screen_load();
+}
diff --git a/src/tables.c b/src/tables.c
index 281395e0..a06c0143 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -4924,6 +4924,8 @@ module_type modules[MAX_MODULES] =
50,
/* Skills: */
{ 6, 4, },
+ /* Intro function */
+ tome_intro,
},
{
@@ -4942,6 +4944,8 @@ module_type modules[MAX_MODULES] =
50,
/* Skill overage: */
{ 6, 5, },
+ /* Intro function */
+ theme_intro,
}
};
diff --git a/src/types.h b/src/types.h
index efefc93a..ea8213a3 100644
--- a/src/types.h
+++ b/src/types.h
@@ -2580,6 +2580,8 @@ struct module_type
s32b max_skill_overage;
} skills;
+ /* Function to show introduction to module */
+ void (*intro)();
};
/**
diff --git a/src/util.pkg b/src/util.pkg
index 12a28a71..a730ee9a 100644
--- a/src/util.pkg
+++ b/src/util.pkg
@@ -355,12 +355,6 @@ typedef unsigned int u32b;
*/
#define HOOK_WIELD 21
-/** @def HOOK_INIT
- * @brief Game initialised.
- * @note (see file dungeon.c)
- */
-#define HOOK_INIT 22
-
/** @def HOOK_AIM */
#define HOOK_AIM 24
@@ -2436,9 +2430,6 @@ extern void calc_bonuses(bool silent);
extern void note_spot(int y, int x);
extern void lite_spot(int y, int x);
-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);
-
/**
* Mimicry
*/