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]" |
Typedefs | |
typedef struct quest_player | quest_player |
typedef struct quest_state | quest_state |
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.c.
#define QC_CAN_RESTART -1 |
typedef struct quest_player quest_player |
Information about a player.
typedef struct quest_state quest_state |
Information about a quest for a player.
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 750 of file quest.c.
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, pl::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, quest::state, and autojail::who.
Referenced by commands_init().
|
static |
Definition at line 323 of file quest.c.
References quest_step_definition::conditions, evaluate_quest_conditions(), quest_step_definition::next, 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 899 of file quest.c.
References dump::level, output_quests(), dump::parent, and quest_for_each().
|
static |
Checks whether the conditions for a given step are met.
condition | the linked list of conditions to check. |
pl | the player to evaluate conditions for. |
Definition at line 301 of file quest.c.
References quest_condition::maxstep, quest_condition::minstep, quest_condition::next, quest_condition::quest_code, 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 910 of file quest.c.
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 651 of file quest.c.
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 91 of file quest.c.
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 276 of file quest.c.
References add_refcount(), fatal(), get_quest(), obj::name, quest_player::next, pl::ob, OUT_OF_MEMORY, 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 232 of file quest.c.
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 258 of file quest.c.
References obj::name, quest_player::next, pl::ob, 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 550 of file quest.c.
References get_or_create_quest(), quest_definition::parent, QC_CAN_RESTART, quest_find_by_code(), quest_player::quests, and quest::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 214 of file quest.c.
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 868 of file quest.c.
References dump::level, logfile, MAX_BUF, quest_step_definition::next, 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 457 of file quest.c.
References draw_ext_info_format(), i18n(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_QUESTS, give::name, NDI_UNIQUE, pl::ob, QC_CAN_RESTART, quest_find_by_code(), quest_player::quests, quests_count, and quest::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 986 of file quest.c.
References get_quest(), 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 672 of file quest.c.
References get_or_create_quest(), get_state(), 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.c.
References llevError, LOG(), quest_step_definition::next, and quest_step_definition::step.
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 585 of file quest.c.
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_step_definition::next, pl::ob, quest_definition::parent, castle_read::prefix, QC_CAN_RESTART, QUERY_FLAG, quest_find_by_code(), quest_get_step(), quest_player::quests, quest::state, quest_state::state, quest_step_definition::step, 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 530 of file quest.c.
References draw_ext_info_format(), get_or_create_quest(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_QUESTS, give::name, NDI_UNIQUE, pl::ob, 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 102 of file quest.c.
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, quest_state::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 928 of file quest.c.
References esrv_send_face(), socket_struct::faces_sent, get_or_create_quest(), quest_step_definition::is_completion_step, socket_struct::notifications, NS_FACESENT_FACE, quest_get_by_code(), quest_get_step(), quest_player::quests, Send_With_Handling(), pl::socket, SockList_AddChar(), SockList_AddInt(), SockList_AddLen16Data(), SockList_AddShort(), SockList_AddString(), SockList_Avail(), SockList_Init(), SockList_Reset(), SockList_Term(), quest::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 728 of file quest.c.
References quest_set_state(), and quest::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 359 of file quest.c.
References draw_ext_info(), draw_ext_info_format(), esrv_send_face(), socket_struct::faces_sent, get_or_create_quest(), get_or_create_state(), pl::has_directory, 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, obj::name, NDI_DELAYED, NDI_UNIQUE, socket_struct::notifications, NS_FACESENT_FACE, pl::ob, player_get_delayed_buffer(), QC_CAN_RESTART, quest_find_by_code(), quest_get_step(), quest_write_player_data(), quest_state::sent_to_client, pl::socket, SockList_AddChar(), SockList_AddInt(), SockList_AddLen16Data(), SockList_AddString(), quest::state, quest_state::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 692 of file quest.c.
References draw_ext_info_format(), get_or_create_quest(), get_or_create_state(), llevDebug, llevError, LOG(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_QUESTS, obj::name, NDI_DELAYED, NDI_UNIQUE, pl::ob, item::q, quest_find_by_code(), quest_set_state(), and quest::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 738 of file quest.c.
References get_or_create_quest(), get_state(), and quest::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 177 of file quest.c.
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 quest::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 347 of file quest.c.
References do_update(), and quest_for_each().
Referenced by quest_set_state().
|
static |
Player quest state.
Definition at line 65 of file quest.c.
Referenced by free_quest(), get_or_create_quest(), and get_quest().