Crossfire Server, Trunk
|
#include "global.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "output_file.h"
#include "sproto.h"
#include "quest.h"
#include "assets.h"
Go to the source code of this file.
Data Structures | |
struct | dump |
struct | quest_player |
struct | quest_state |
Macros | |
#define | QC_CAN_RESTART -1 |
#define | TAG_END "[/color]" |
#define | TAG_START "[color=#aa55ff]" |
Variables | |
static quest_player * | player_states = NULL |
Quest-related low-level mechanisms.
You should only need to call the public functions, all that are not static.
Data is loaded on a need-only basis - when a player quest state is queried or modified, data is read. Also, free_quest() can be called to release memory without preventing quest operations after.
Write is done for each player whenever the state changes, to ensure data integrity.
Definition in file quest.cpp.
#define QC_CAN_RESTART -1 |
void command_quest | ( | object * | op, |
const char * | params | ||
) |
Command handler for 'quest'.
op | player asking for information, warning emitted if not a player. |
params | extra parameters for command. |
Definition at line 738 of file quest.cpp.
References quest_state::code, command_help(), draw_ext_info(), draw_ext_info_format(), find_player_partial_name(), FLAG_WIZ, get_quest(), get_quest_by_number(), i18n(), llevError, LOG(), MSG_TYPE_ADMIN_DM, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, MSG_TYPE_COMMAND_QUESTS, MSG_TYPE_COMMAND_SUCCESS, give::name, NDI_UNIQUE, quest_state::next, player::ob, give::op, roll-o-matic::params, item::q, QUERY_FLAG, quest_get_by_code(), quest_info(), quest_list(), quest_set_state(), quest_player::quests, dragon::state, and autojail::who.
Referenced by commands_init().
|
static |
Definition at line 316 of file quest.cpp.
References quest_step_definition::conditions, evaluate_quest_conditions(), altar_valkyrie::pl, quest_get_player_state(), quest_set_state(), and quest_step_definition::step.
Referenced by update_quests().
void dump_quests | ( | void | ) |
Dump all of the quests, then calls exit() - useful in terms of debugging to make sure that quests are set up and recognised correctly.
Definition at line 880 of file quest.cpp.
References dump::level, output_quests(), dump::parent, and quest_for_each().
|
static |
Checks whether the conditions for a given step are met.
conditions | the list of conditions to check. |
pl | the player to evaluate conditions for. |
Definition at line 297 of file quest.cpp.
References altar_valkyrie::pl, quest_get_player_state(), and quest_was_completed().
Referenced by do_update().
void free_quest | ( | void | ) |
Free all quest status structures. It is all right to call quest functions again after that.
Definition at line 891 of file quest.cpp.
References free_state(), free_string(), give::next, quest_player::next, quest_player::player_name, and player_states.
Referenced by cleanup(), command_purge_quest(), and free_server().
|
static |
Free quests structures.
pq | what to free. |
Definition at line 639 of file quest.cpp.
References quest_state::code, free_string(), give::next, quest_state::next, and quest_player::quests.
Referenced by free_quest().
|
static |
Return a new quest_state*, calling fatal() if memory shortage.
Definition at line 87 of file quest.cpp.
References fatal(), and OUT_OF_MEMORY.
Referenced by quest_read_player_data().
|
static |
Get quest status for a player, creating it if it doesn't exist yet. Calls fatal() if memory allocation error.
pl | player to get information of. |
Definition at line 272 of file quest.cpp.
References add_refcount(), fatal(), get_quest(), quest_player::next, OUT_OF_MEMORY, altar_valkyrie::pl, quest_player::player_name, player_states, and quest_read_player_data().
Referenced by get_quest_by_number(), quest_get_player_state(), quest_info(), quest_list(), quest_send_initial_states(), quest_set_state(), quest_start(), and quest_was_completed().
|
static |
Get the state of a quest for a player, creating it if not existing yet.
pq | player to get state for. |
name | quest to get state of. |
Definition at line 228 of file quest.cpp.
References add_refcount(), quest_state::code, fatal(), get_state(), give::name, quest_state::next, OUT_OF_MEMORY, and quest_player::quests.
Referenced by quest_set_state(), and quest_start().
|
static |
Get quest status for a player, not creating it if it doesn't exist.
pl | player to get information of. |
Definition at line 254 of file quest.cpp.
References quest_player::next, altar_valkyrie::pl, quest_player::player_name, and player_states.
Referenced by command_quest(), get_or_create_quest(), and quest_first_player_save().
|
static |
returns the quest state which corresponds to a certain number for the given player.
pl | player asking for details. |
number | quest number. |
Definition at line 539 of file quest.cpp.
References get_or_create_quest(), quest_definition::parent, altar_valkyrie::pl, QC_CAN_RESTART, quest_find_by_code(), quest_player::quests, and dragon::state.
Referenced by command_quest().
|
static |
Get the state of a quest for a player, not creating if not existing yet.
pq | player to get state for. |
name | quest to get state of. |
Definition at line 210 of file quest.cpp.
References quest_state::code, give::name, quest_state::next, and quest_player::quests.
Referenced by get_or_create_state(), quest_get_player_state(), and quest_was_completed().
|
static |
Dump one quest on the logfile, then its children. Will call itself through quest_for_each().
quest | quest to dump. |
user | pointer to a dump struct. |
Definition at line 856 of file quest.cpp.
References dump::level, logfile, MAX_BUF, dump::parent, castle_read::prefix, quest_for_each(), and ring_occidental_mages::r.
Referenced by dump_quests().
|
static |
Utility function to display a quest list. Will show a header before the list if not empty.
pl | player to display list of quests. |
pq | quests to display. |
showall | if 0, only shows quests in progress and a summary of completed quests, else shows all quests. |
name | either 'You' or the player's name, if pl is a DM asking about another player. |
Definition at line 446 of file quest.cpp.
References draw_ext_info_format(), i18n(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_QUESTS, give::name, NDI_UNIQUE, altar_valkyrie::pl, QC_CAN_RESTART, quest_find_by_code(), quest_player::quests, quests_count, and dragon::state.
Referenced by quest_list().
void quest_first_player_save | ( | player * | pl | ) |
Ensure the quest state is correctly saved for a player. This function should only be called once, when the player's save directory is created. All other quest functions save the state automatically, but save can only happen when the player directory exists.
pl | who to save quests for. |
Definition at line 967 of file quest.cpp.
References get_quest(), altar_valkyrie::pl, quest_write_player_data(), and quest_player::quests.
Referenced by save_player().
Get the quest state for a player.
pl | player. |
quest_code | internal quest code. |
Definition at line 660 of file quest.cpp.
References get_or_create_quest(), get_state(), altar_valkyrie::pl, item::q, QC_CAN_RESTART, quest_find_by_code(), and quest_state::state.
Referenced by cfapi_player_quest(), do_update(), and evaluate_quest_conditions().
|
static |
Get a step for the specified quest.
quest | quest to consider. |
step | step to find. |
Definition at line 73 of file quest.cpp.
References llevError, and LOG().
Referenced by quest_info(), quest_read_player_data(), quest_send_initial_states(), and quest_set_state().
|
static |
Give details about a quest.
pl | player to give quest details to. |
who | player to give quest details of. |
qs | quest_state to give details about |
level | The level of recursion for the quest info that's being provided |
Definition at line 574 of file quest.cpp.
References quest_state::code, draw_ext_info(), draw_ext_info_format(), FLAG_WIZ, get_or_create_quest(), i18n(), quest_state::is_complete, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_QUESTS, NDI_UNIQUE, quest_definition::parent, altar_valkyrie::pl, castle_read::prefix, QC_CAN_RESTART, QUERY_FLAG, quest_find_by_code(), quest_get_step(), quest_player::quests, quest_state::state, dragon::state, quest_step_definition::step_description, TAG_END, TAG_START, and autojail::who.
Referenced by command_quest().
Display current and completed player quests.
pl | player to display to. |
who | player to display information for. |
showall | - whether to show all of the quests in full, just summary information for the completed ones |
name | either 'You' or the player's name, if pl is a DM asking about another player. |
Definition at line 519 of file quest.cpp.
References draw_ext_info_format(), get_or_create_quest(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_QUESTS, give::name, NDI_UNIQUE, altar_valkyrie::pl, quest_display(), quest_player::quests, and autojail::who.
Referenced by command_quest().
|
static |
Read quest-data information for a player.
pq | player to read data for. |
Definition at line 98 of file quest.cpp.
References add_string(), quest_state::code, navar-midane_time::data, mad_mage_user::file, get_new_quest_state(), quest_state::is_complete, quest_step_definition::is_completion_step, llevDebug, llevError, Settings::localdir, LOG(), MAX_BUF, quest_state::next, quest_player::player_name, Settings::playerdir, quest_get_by_code(), quest_get_step(), quest_player::quests, settings, quest_state::state, dragon::state, and quest_state::was_completed.
Referenced by get_or_create_quest().
void quest_send_initial_states | ( | player * | pl | ) |
Send the current quest states for the specified player, if the client supports those notifications.
pl | who to send quests for. |
Definition at line 909 of file quest.cpp.
References esrv_send_face(), get_or_create_quest(), quest_step_definition::is_completion_step, NS_FACESENT_FACE, altar_valkyrie::pl, quest_get_by_code(), quest_get_step(), quest_player::quests, Send_With_Handling(), SockList_AddChar(), SockList_AddInt(), SockList_AddLen16Data(), SockList_AddShort(), SockList_AddString(), SockList_Avail(), SockList_Init(), SockList_Reset(), SockList_Term(), dragon::state, and quest_step_definition::step_description.
Referenced by check_login().
Set the state of a quest for a player.
pl | player to set the state for. |
quest_code | quest internal code. |
state | new state for the quest, must be greater than 0 else forced to 100 and a warning is emitted. |
Definition at line 716 of file quest.cpp.
References altar_valkyrie::pl, quest_set_state(), and dragon::state.
Referenced by cfapi_player_quest().
|
static |
Set the state of a quest for a player.
dm | if NULL then the player is actually playing, else a DM is changing the quest's state manually. |
pl | player to set the state for. |
quest_code | quest internal code. |
state | new state for the quest, must be greater than 0 else forced to 100 and a warning is emitted. |
started | if 1, quest must have been started first or a warning is emitted, else it doesn't matter. |
Definition at line 348 of file quest.cpp.
References draw_ext_info(), draw_ext_info_format(), esrv_send_face(), get_or_create_quest(), get_or_create_state(), quest_state::is_complete, quest_step_definition::is_completion_step, llevDebug, llevError, LOG(), MSG_TYPE_ADMIN_DM, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, MSG_TYPE_COMMAND_QUESTS, NDI_DELAYED, NDI_UNIQUE, NS_FACESENT_FACE, player::ob, altar_valkyrie::pl, player_get_delayed_buffer(), QC_CAN_RESTART, quest_find_by_code(), quest_get_step(), quest_write_player_data(), quest_state::sent_to_client, SockList_AddChar(), SockList_AddInt(), SockList_AddLen16Data(), SockList_AddString(), quest_state::state, dragon::state, quest_step_definition::step_description, update_quests(), and quest_state::was_completed.
Referenced by command_quest(), do_update(), quest_set_player_state(), and quest_start().
Start a quest for a player. Will notify the player.
pl | player. |
quest_code | internal quest code. |
state | initial quest state, must be greater than 0 else forced to 100 and warning emitted. |
Definition at line 680 of file quest.cpp.
References draw_ext_info_format(), get_or_create_quest(), get_or_create_state(), llevDebug, llevError, LOG(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_QUESTS, NDI_DELAYED, NDI_UNIQUE, altar_valkyrie::pl, item::q, quest_find_by_code(), quest_set_state(), and dragon::state.
Referenced by cfapi_player_quest().
Check if a quest was completed once for a player, without taking account the current state.
pl | who to check for. |
quest_code | quest internal code. |
Definition at line 726 of file quest.cpp.
References get_or_create_quest(), get_state(), altar_valkyrie::pl, and dragon::state.
Referenced by cfapi_player_quest(), and evaluate_quest_conditions().
|
static |
Write quest-data information for a player.
pq | player to write data for. |
Definition at line 173 of file quest.cpp.
References draw_ext_info(), mad_mage_user::file, Settings::localdir, MAX_BUF, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOADSAVE, NDI_ALL_DMS, NDI_UNIQUE, of_close(), of_open(), quest_player::player_name, Settings::playerdir, quest_player::quests, settings, and dragon::state.
Referenced by quest_first_player_save(), and quest_set_state().
|
static |
Look through all of the quests for the given player, and see if any need to be updated.
pl |
Definition at line 336 of file quest.cpp.
References do_update(), altar_valkyrie::pl, and quest_for_each().
Referenced by quest_set_state().
|
static |
Player quest state.
Definition at line 65 of file quest.cpp.
Referenced by free_quest(), get_or_create_quest(), and get_quest().