summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-09 15:41:46 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-09 16:14:37 +0200
commit93e3dd939f24965125641ca4a08135a6e723c1a3 (patch)
treeca5d28be0937901011ea814db8e0e5d6e55ce2fe
parentb92fe01dfebbfed138d0cec1ac23c608be881dfc (diff)
Lua: Remove quests.lua and remove unnecessary dynamism for quests
-rw-r--r--lib/core/init.lua1
-rw-r--r--lib/core/quests.lua57
-rw-r--r--lib/mods/theme/core/init.lua1
-rw-r--r--lib/mods/theme/core/quests.lua57
-rw-r--r--src/birth.c2
-rw-r--r--src/cmd4.c10
-rw-r--r--src/defines.h2
-rw-r--r--src/externs.h6
-rw-r--r--src/files.c2
-rw-r--r--src/init1.c4
-rw-r--r--src/init2.c26
-rw-r--r--src/loadsave.c10
-rw-r--r--src/lua_bind.c15
-rw-r--r--src/plots.c2
-rw-r--r--src/quest.pkg34
-rw-r--r--src/tables.c2
-rw-r--r--src/variable.c3
-rw-r--r--src/wild.c8
-rw-r--r--src/wizard2.c2
19 files changed, 27 insertions, 217 deletions
diff --git a/lib/core/init.lua b/lib/core/init.lua
index 9d0c01a3..d294adb4 100644
--- a/lib/core/init.lua
+++ b/lib/core/init.lua
@@ -17,7 +17,6 @@ tome_dofile_anywhere(ANGBAND_DIR_CORE, "monsters.lua")
tome_dofile_anywhere(ANGBAND_DIR_CORE, "building.lua")
tome_dofile_anywhere(ANGBAND_DIR_CORE, "dungeon.lua")
tome_dofile_anywhere(ANGBAND_DIR_CORE, "s_aux.lua")
-tome_dofile_anywhere(ANGBAND_DIR_CORE, "quests.lua")
tome_dofile_anywhere(ANGBAND_DIR_CORE, "gods.lua")
-- Load the ingame contextual help
diff --git a/lib/core/quests.lua b/lib/core/quests.lua
deleted file mode 100644
index dfe9db51..00000000
--- a/lib/core/quests.lua
+++ /dev/null
@@ -1,57 +0,0 @@
--- Quest helper files
-
--- Quest structs
-
-__quest_hook = {}
-__quest_callbacks = {}
-__quest_callbacks_max = 0
-__quest_dynamic_desc = {}
-
-function add_quest(q)
- local i, index, d, z, qq
-
- assert(q.global, "No quest global name")
- assert(q.name, "No quest name")
- assert(q.desc, "No quest desc")
- assert(q.level, "No quest level")
- assert(q.hooks, "No quest hooks")
-
- i = new_quest(q.name);
- setglobal(q.global, i)
-
- -- Make it save & load
- add_loadsave("quest("..q.global..").status", QUEST_STATUS_UNTAKEN)
-
- if type(q.desc) == "table" then
- z = 0
- for index, d in q.desc do
- quest_desc(i, z, d);
- z = z + 1
- end
- else
- __quest_dynamic_desc[i] = q.desc
- quest(i).dynamic_desc = TRUE
- end
- quest(i).level = q.level
- if not q.silent then
- quest(i).silent = FALSE
- else
- quest(i).silent = q.silent
- end
- __quest_hook[i] = q.hooks
- for index, d in q.hooks do
- add_hook_script(index, "__lua__quest_callback"..__quest_callbacks_max, "__lua__quest_callback"..__quest_callbacks_max)
- setglobal("__lua__quest_callback"..__quest_callbacks_max, d)
- __quest_callbacks_max = __quest_callbacks_max + 1
- end
- if q.data then
- for index, d in q.data do
- -- Besure it exists
- setglobal(index, d)
-
- -- Make it save & load
- add_loadsave(index, d)
- end
- end
- return i
-end
diff --git a/lib/mods/theme/core/init.lua b/lib/mods/theme/core/init.lua
index 9d0c01a3..d294adb4 100644
--- a/lib/mods/theme/core/init.lua
+++ b/lib/mods/theme/core/init.lua
@@ -17,7 +17,6 @@ tome_dofile_anywhere(ANGBAND_DIR_CORE, "monsters.lua")
tome_dofile_anywhere(ANGBAND_DIR_CORE, "building.lua")
tome_dofile_anywhere(ANGBAND_DIR_CORE, "dungeon.lua")
tome_dofile_anywhere(ANGBAND_DIR_CORE, "s_aux.lua")
-tome_dofile_anywhere(ANGBAND_DIR_CORE, "quests.lua")
tome_dofile_anywhere(ANGBAND_DIR_CORE, "gods.lua")
-- Load the ingame contextual help
diff --git a/lib/mods/theme/core/quests.lua b/lib/mods/theme/core/quests.lua
deleted file mode 100644
index dfe9db51..00000000
--- a/lib/mods/theme/core/quests.lua
+++ /dev/null
@@ -1,57 +0,0 @@
--- Quest helper files
-
--- Quest structs
-
-__quest_hook = {}
-__quest_callbacks = {}
-__quest_callbacks_max = 0
-__quest_dynamic_desc = {}
-
-function add_quest(q)
- local i, index, d, z, qq
-
- assert(q.global, "No quest global name")
- assert(q.name, "No quest name")
- assert(q.desc, "No quest desc")
- assert(q.level, "No quest level")
- assert(q.hooks, "No quest hooks")
-
- i = new_quest(q.name);
- setglobal(q.global, i)
-
- -- Make it save & load
- add_loadsave("quest("..q.global..").status", QUEST_STATUS_UNTAKEN)
-
- if type(q.desc) == "table" then
- z = 0
- for index, d in q.desc do
- quest_desc(i, z, d);
- z = z + 1
- end
- else
- __quest_dynamic_desc[i] = q.desc
- quest(i).dynamic_desc = TRUE
- end
- quest(i).level = q.level
- if not q.silent then
- quest(i).silent = FALSE
- else
- quest(i).silent = q.silent
- end
- __quest_hook[i] = q.hooks
- for index, d in q.hooks do
- add_hook_script(index, "__lua__quest_callback"..__quest_callbacks_max, "__lua__quest_callback"..__quest_callbacks_max)
- setglobal("__lua__quest_callback"..__quest_callbacks_max, d)
- __quest_callbacks_max = __quest_callbacks_max + 1
- end
- if q.data then
- for index, d in q.data do
- -- Besure it exists
- setglobal(index, d)
-
- -- Make it save & load
- add_loadsave(index, d)
- end
- end
- return i
-end
diff --git a/src/birth.c b/src/birth.c
index 75ff1ed2..243f080e 100644
--- a/src/birth.c
+++ b/src/birth.c
@@ -858,7 +858,7 @@ static void player_wipe(void)
}
/* Wipe the quests */
- for (i = 0; i < MAX_Q_IDX_INIT; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
quest[i].status = QUEST_STATUS_UNTAKEN;
for (j = 0; j < sizeof(quest[i].data)/sizeof(quest[i].data[0]); j++)
diff --git a/src/cmd4.c b/src/cmd4.c
index 29d01c73..af98b0ed 100644
--- a/src/cmd4.c
+++ b/src/cmd4.c
@@ -4127,7 +4127,7 @@ static void do_cmd_knowledge_quests(void)
char file_name[1024];
- int *order;
+ int order[MAX_Q_IDX] = { };
int num = 0;
@@ -4140,14 +4140,12 @@ static void do_cmd_knowledge_quests(void)
/* Open a new file */
fff = my_fopen(file_name, "w");
- C_MAKE(order, max_q_idx, int);
-
- for (i = 0; i < max_q_idx; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
insert_sort_quest(order, &num, i);
}
- for (z = 0; z < max_q_idx; z++)
+ for (z = 0; z < MAX_Q_IDX; z++)
{
i = order[z];
@@ -4194,8 +4192,6 @@ static void do_cmd_knowledge_quests(void)
}
}
- C_FREE(order, max_q_idx, int);
-
/* Close the file */
my_fclose(fff);
diff --git a/src/defines.h b/src/defines.h
index abdd4a90..93b6e9a6 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -4422,7 +4422,7 @@
#define QUEST_FIREPROOF 27
#define QUEST_LIBRARY 28
#define QUEST_GOD 29
-#define MAX_Q_IDX_INIT 30
+#define MAX_Q_IDX 30
#define PLOT_MAIN 0
#define PLOT_BREE 1
diff --git a/src/externs.h b/src/externs.h
index 4ab14bfd..bb92e921 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -85,7 +85,6 @@ extern inscription_info_type inscription_info[MAX_INSCRIPTIONS];
extern cptr sense_desc[];
extern flags_group flags_groups[MAX_FLAG_GROUP];
extern power_type powers_type[POWER_MAX];
-extern quest_type quest_info[MAX_Q_IDX_INIT];
extern cptr artifact_names_list;
extern monster_power monster_powers[96];
extern tval_desc tval_descs[];
@@ -94,7 +93,7 @@ extern int month_day[9];
extern cptr month_name[9];
extern cli_comm *cli_info;
extern int cli_total;
-extern quest_type quest_init_tome[MAX_Q_IDX_INIT];
+extern quest_type quest[MAX_Q_IDX];
extern int max_body_part[BODY_MAX];
extern gf_name_type gf_names[];
extern module_type modules[MAX_MODULES];
@@ -565,8 +564,6 @@ extern birther previous_char;
extern hist_type *bg;
extern int max_bg_idx;
extern s32b extra_savefile_parts;
-extern s16b max_q_idx;
-extern quest_type *quest;
extern bool_ player_char_health;
extern s16b max_spells;
extern spell_type *school_spells;
@@ -1798,7 +1795,6 @@ extern void find_position(int y, int x, int *yy, int *xx);
extern bool_ summon_lua_okay(int r_idx);
extern bool_ lua_summon_monster(int y, int x, int lev, bool_ ffriend, char *fct);
-extern s16b add_new_quest(char *name);
extern void desc_quest(int q_idx, int d, char *desc);
extern s16b add_new_gods(char *name);
diff --git a/src/files.c b/src/files.c
index c52beef9..f860e809 100644
--- a/src/files.c
+++ b/src/files.c
@@ -4329,7 +4329,7 @@ long total_points(void)
temp += p_ptr->au / 5;
/* Completing quest increase score */
- for (i = 0; i < max_q_idx; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
if (quest[i].status >= QUEST_STATUS_COMPLETED)
{
diff --git a/src/init1.c b/src/init1.c
index 4c7e7035..43d9690f 100644
--- a/src/init1.c
+++ b/src/init1.c
@@ -10812,7 +10812,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst
i = strlen(zz[8]) - 1;
if (zz[8][i] == '"') zz[8][i] = '\0';
letter[index].special = 0;
- for (i = 0; i < max_q_idx; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
if (!strcmp(&zz[8][1], quest[i].name))
{
@@ -11659,7 +11659,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp)
for (i = 0; (c[i] != '"') && (c[i] != '\0'); i++);
if (c[i] == '"') c[i] = '\0';
strcpy(pref_tmp_value, "-1");
- for (i = 0; i < max_q_idx; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
if (streq(c, quest[i].name))
{
diff --git a/src/init2.c b/src/init2.c
index 8a20cfb3..1f6e66e6 100644
--- a/src/init2.c
+++ b/src/init2.c
@@ -1959,13 +1959,6 @@ static errr init_misc(void)
/* Hack -- No messages yet */
message__tail = MESSAGE_BUF;
- /* Prepare quests */
- quest = NULL;
- max_q_idx = MAX_Q_IDX_INIT;
- reinit_quests(max_q_idx);
-
- C_COPY(quest, quest_init_tome, MAX_Q_IDX_INIT, quest_type);
-
/* Prepare gods */
deity_info = NULL;
max_gods = MAX_GODS_INIT;
@@ -2073,25 +2066,6 @@ static errr init_wilderness(void)
return 0;
}
-void reinit_quests(s16b new_size)
-{
- quest_type *new_quest;
-
- C_MAKE(new_quest, new_size, quest_type);
-
- /* Reallocate the extra memory */
- if (quest)
- {
- C_COPY(new_quest, quest, max_q_idx, quest_type);
-
- C_FREE(quest, max_q_idx, quest_type);
- }
-
- quest = new_quest;
-
- max_q_idx = new_size;
-}
-
void reinit_gods(s16b new_size)
{
deity_type *new_deity;
diff --git a/src/loadsave.c b/src/loadsave.c
index fe89a451..1787670b 100644
--- a/src/loadsave.c
+++ b/src/loadsave.c
@@ -2689,18 +2689,18 @@ static bool_ do_savefile_aux(int flag)
do_s16b(&(d_info[i].t_num), flag);
}
- if (flag == LS_SAVE) max_quests_ldsv = MAX_Q_IDX_INIT;
- /* Number of quests */
+ /* Sanity check number of quests */
+ if (flag == LS_SAVE) max_quests_ldsv = MAX_Q_IDX;
do_u16b(&max_quests_ldsv, flag);
/* Incompatible save files */
- if ((flag == LS_LOAD) && (max_quests_ldsv > MAX_Q_IDX_INIT))
+ if ((flag == LS_LOAD) && (max_quests_ldsv != MAX_Q_IDX))
{
- note(format("Too many (%u) quests!", max_quests_ldsv));
+ note(format("Invalid number of quests (%u)!", max_quests_ldsv));
return (FALSE);
}
- for (i = 0; i < max_quests_ldsv; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
do_s16b(&quest[i].status, flag);
for (j = 0; j < sizeof(quest[i].data)/sizeof(quest[i].data[0]); j++)
diff --git a/src/lua_bind.c b/src/lua_bind.c
index a9e1b476..ce49a06e 100644
--- a/src/lua_bind.c
+++ b/src/lua_bind.c
@@ -154,21 +154,6 @@ bool_ lua_summon_monster(int y, int x, int lev, bool_ friend_, char *fct)
/*
* Quests
*/
-s16b add_new_quest(char *name)
-{
- int i;
-
- /* Increase the size */
- reinit_quests(max_q_idx + 1);
- quest[max_q_idx - 1].type = HOOK_TYPE_LUA;
- strncpy(quest[max_q_idx - 1].name, name, 39);
-
- for (i = 0; i < 10; i++)
- strncpy(quest[max_q_idx - 1].desc[i], "", 39);
-
- return (max_q_idx - 1);
-}
-
void desc_quest(int q_idx, int d, char *desc)
{
if (d >= 0 && d < 10)
diff --git a/src/plots.c b/src/plots.c
index 08d0ea90..e16cbe2a 100644
--- a/src/plots.c
+++ b/src/plots.c
@@ -40,7 +40,7 @@ void init_hooks()
{
int i;
- for (i = 0; i < MAX_Q_IDX_INIT; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
if ((quest[i].type == HOOK_TYPE_C) && (quest[i].init != NULL)) quest[i].init(i);
}
diff --git a/src/quest.pkg b/src/quest.pkg
index 487c62af..f9b3fe7e 100644
--- a/src/quest.pkg
+++ b/src/quest.pkg
@@ -76,6 +76,8 @@ typedef unsigned int u32b;
#define QUEST_STATUS_FAILED_DONE 6
/** @} */
+#define MAX_Q_IDX 30
+
/** @struct quest_type
* @brief Quest
*/
@@ -112,17 +114,11 @@ struct quest_type
byte type;
};
-/** @var max_q_idx
- * @brief Number
- * @note Maximum number of quests in quest list
- */
-extern s16b max_q_idx;
-
/** @var quest_aux;
* @brief quest_type
* @note Array of quests
*/
-extern quest_type quest[max_q_idx] @ quest_aux;
+extern quest_type quest[MAX_Q_IDX] @ quest_aux;
$static quest_type *lua_get_quest(int q_idx){return &quest[q_idx];}
@@ -135,27 +131,3 @@ $static quest_type *lua_get_quest(int q_idx){return &quest[q_idx];}
*/
static quest_type *lua_get_quest @ quest(int q_idx);
-/** @fn new_quest(char *name);
- * @dgonly
- * @brief Add a new quest to the end of the quest array.\n
- * @param *name String \n the name of the new quest.
- * @brief Quest name
- * @return Number \n The index of the new quest in the quest array.
- * @note (see file lua_bind.c)
- */
-extern s16b add_new_quest @ new_quest(char *name);
-
-/** @fn quest_desc(int q_idx, int d, char *desc);
- * @dgonly
- * @brief Return the description of a quest.\n
- * @param q_idx Number \n the index of a quest in the quest array.
- * @brief Quest index
- * @param d Number \n the index of a line in the quest description.
- * @brief Description line
- * @param *desc String
- * @brief Description
- * @return *desc String \n Line "d" of the description of quest with index
- * "q_idx" in the quest array.
- * @note (see file lua_bind.c)
- */
-extern void desc_quest @ quest_desc(int q_idx, int d, char *desc);
diff --git a/src/tables.c b/src/tables.c
index 594c4f16..9b77d07b 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -3597,7 +3597,7 @@ power_type powers_type[POWER_MAX] =
/*
* The Quests
*/
-quest_type quest_init_tome[MAX_Q_IDX_INIT] =
+quest_type quest[MAX_Q_IDX] =
{
{
FALSE,
diff --git a/src/variable.c b/src/variable.c
index c3530df8..c09d9720 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -1487,8 +1487,7 @@ s32b extra_savefile_parts = 0;
/*
* Quests
*/
-s16b max_q_idx = MAX_Q_IDX_INIT;
-quest_type *quest;
+quest_type quest[MAX_Q_IDX];
/*
* Display the player as a special symbol when in bad health ?
diff --git a/src/wild.c b/src/wild.c
index 7a9d1c51..279b79d9 100644
--- a/src/wild.c
+++ b/src/wild.c
@@ -525,10 +525,12 @@ void wilderness_gen(int refresh)
}
/* Set rewarded quests to finished */
- for (i = 0; i < max_q_idx; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
if (quest[i].status == QUEST_STATUS_REWARDED)
+ {
quest[i].status = QUEST_STATUS_FINISHED;
+ }
}
process_hooks(HOOK_WILD_GEN, "(d)", FALSE);
@@ -591,10 +593,12 @@ void wilderness_gen_small()
p_ptr->py = p_ptr->wilderness_y;
/* Set rewarded quests to finished */
- for (i = 0; i < max_q_idx; i++)
+ for (i = 0; i < MAX_Q_IDX; i++)
{
if (quest[i].status == QUEST_STATUS_REWARDED)
+ {
quest[i].status = QUEST_STATUS_FINISHED;
+ }
}
process_hooks(HOOK_WILD_GEN, "(d)", TRUE);
diff --git a/src/wizard2.c b/src/wizard2.c
index 5e1e38d1..6f691171 100644
--- a/src/wizard2.c
+++ b/src/wizard2.c
@@ -1795,7 +1795,7 @@ void do_cmd_debug(void)
case 'q':
{
/* if (quest[command_arg].status == QUEST_STATUS_UNTAKEN)*/
- if ((command_arg >= 1) && (command_arg < MAX_Q_IDX_INIT) && (command_arg != QUEST_RANDOM))
+ if ((command_arg >= 1) && (command_arg < MAX_Q_IDX) && (command_arg != QUEST_RANDOM))
{
quest[command_arg].status = QUEST_STATUS_TAKEN;
*(quest[command_arg].plot) = command_arg;