Go to the documentation of this file.
41 #define TAG_START "[color=#aa55ff]"
42 #define TAG_END "[/color]"
45 #define QC_CAN_RESTART -1
77 if (qsd->
step == step)
106 int warned = 0,
state;
111 file = fopen(
final,
"r");
117 while (fgets(read,
sizeof(read),
file) != NULL) {
118 if (sscanf(read,
"quest %s\n",
data)) {
127 LOG(
llevError,
"quest: invalid file format for %s\n",
final);
132 if (sscanf(read,
"state %d\n", &
state)) {
144 if (strcmp(read,
"end_quest\n") == 0) {
159 if (sscanf(read,
"completed %d\n", &
state)) {
164 LOG(
llevError,
"quest: invalid line in %s: %s\n",
final, read);
168 LOG(
llevError,
"quest: missing end_quest in %s\n",
final);
194 fprintf(
file,
"quest %s\n",
state->code);
195 fprintf(
file,
"state %d\n",
state->state);
196 fprintf(
file,
"completed %d\n",
state->was_completed);
197 fprintf(
file,
"end_quest\n");
315 if (current_step < cond->minstep || current_step > cond->
maxstep)
331 new_step=new_step<step->
step?step->
step:new_step;
337 if (new_step > current_step) {
369 LOG(
llevError,
"quest: asking for set_state of unknown quest %s!\n", quest_code);
374 if (!dm &&
state <= 0) {
375 LOG(
llevDebug,
"quest_set_player_state: warning: called with invalid state %d for quest %s, player %s\n",
state,
pl->
ob->
name, quest_code);
379 if (started && qs->
state == 0) {
381 LOG(
llevDebug,
"quest_set_player_state: warning: called for player %s not having started quest %s\n",
pl->
ob->
name, quest_code);
396 LOG(
llevError,
"quest_set_player_state: couldn't find state definition %d for quest %s, player %s\n",
state, quest_code,
pl->
ob->
name);
406 if (
quest->quest_restart)
436 assert(step != NULL);
461 int completed_count = 0, restart_count = 0, total_count = 0, current_count = 0;
466 if (
quest->parent == NULL) {
472 }
else if(
state->is_complete) {
478 if (completed_count > 0) {
480 if (restart_count > 0)
482 "%s completed %d out of %d quests, of which %d may be restarted.",
name, completed_count,
quests_count(
false), restart_count);
485 "%s completed %d quests",
name, completed_count);
486 current_count = completed_count;
489 "%s completed the following quests:",
name);
493 if (
quest->parent == NULL) {
498 "(%3d) %s%s", ++current_count,
quest->quest_title, restart);
505 if (total_count > completed_count) {
507 "%s started the following quests:",
name);
511 if (
quest->parent == NULL) {
515 "(%3d) %s", ++current_count,
quest->quest_title);
555 if (number <= 0 || !pq) {
563 if (++questnum == number)
return state;
571 if (++questnum == number)
return state;
606 for (step =
quest->steps; step != NULL; step = step->
next) {
614 const char *restart =
"";
615 if (
quest->quest_restart)
616 restart =
i18n(
pl->
ob,
" (can be replayed)");
632 prefix =
"Current Status";
699 LOG(
llevError,
"quest_start: requested unknown quest %s\n", quest_code);
712 LOG(
llevDebug,
"quest_start: warning: player %s has already started quest %s\n",
pl->
ob->
name, quest_code);
756 LOG(
llevError,
"command_quest called for a non player!\n");
766 char* dup = strdup(
params);
767 char* space = strchr(dup,
' ');
791 if (strcmp(
params,
"list all") == 0) {
796 if (strcmp(
params,
"list") == 0) {
801 if (strncmp(
params,
"info ", 5) == 0) {
802 int number = atoi(
params+5);
811 if (strncmp(
params,
"info_c ", 7) == 0) {
812 int number = atoi(
params+7);
817 if (
q &&
q->client_code == (uint32_t)number) {
831 char *dup = strdup(
params + 4);
832 char *space = strrchr(dup,
' ');
848 state = atoi(space + 1);
875 for (
int i = 0; i < d->
level; i++) {
887 fprintf(
logfile,
"%s%s - %s - %d steps (%srestartable)\n",
prefix,
quest->quest_code,
quest->quest_title, stepcount,
quest->quest_restart ?
"" :
"not ");
946 if (
state->state == -1)
951 size = 2 + (2 + strlen(
quest->quest_title)) + 4 + 1 + (2 + (step != NULL ? strlen(step->
step_description) : 0));
972 state->sent_to_client = 1;
988 if (qp != NULL && qp->
quests != NULL) {
static quest_state * get_quest_by_number(player *pl, int number)
void SockList_AddInt(SockList *sl, uint32_t data)
sstring add_refcount(sstring str)
sstring add_string(const char *str)
static void free_state(quest_player *pq)
#define MSG_TYPE_COMMAND_SUCCESS
static void quest_set_state(player *dm, player *pl, sstring quest_code, int state, int started)
void quest_for_each(quest_op op, void *user)
static void do_update(const quest_definition *quest, void *user)
#define QUERY_FLAG(xyz, p)
static void quest_display(player *pl, quest_player *pq, int showall, const char *name)
void SockList_AddString(SockList *sl, const char *data)
static int dump(const std::set< std::string > &items, const char *name)
int quest_was_completed(player *pl, sstring quest_code)
static void quest_info(player *pl, player *who, quest_state *qs, int level)
#define MSG_TYPE_COMMAND_QUESTS
const quest_definition * parent
void SockList_AddLen16Data(SockList *sl, const void *data, size_t len)
struct quest_player * next
void SockList_Reset(SockList *sl)
static quest_player * player_states
struct quest_state quest_state
static quest_player * get_or_create_quest(player *pl)
size_t SockList_Avail(const SockList *sl)
#define MSG_TYPE_ADMIN_DM
void free_string(sstring str)
struct quest_step_definition * next
void esrv_send_face(socket_struct *ns, const Face *face, int nocache)
int of_close(OutputFile *of)
struct quest_state * quests
void fatal(enum fatal_error err)
void SockList_AddShort(SockList *sl, uint16_t data)
void SockList_AddChar(SockList *sl, unsigned char c)
struct quest_definition * parent
static quest_state * get_state(quest_player *pq, sstring name)
void command_help(object *op, const char *params)
static quest_state * get_or_create_state(quest_player *pq, sstring name)
const typedef char * sstring
static void quest_read_player_data(quest_player *pq)
quest_definition * quest_get_by_code(sstring code)
void SockList_Init(SockList *sl)
#define MSG_TYPE_ADMIN_LOADSAVE
void SockList_Term(SockList *sl)
#define MSG_TYPE_COMMAND_FAILURE
static quest_player * get_quest(player *pl)
quest_definition * quest_find_by_code(sstring code)
void quest_first_player_save(player *pl)
struct quest_state * next
struct quest_player quest_player
static void quest_list(player *pl, player *who, int showall, const char *name)
quest_condition * conditions
void LOG(LogLevel logLevel, const char *format,...)
static quest_state * get_new_quest_state(void)
FILE * of_open(OutputFile *of, const char *fname)
void quest_send_initial_states(player *pl)
static void output_quests(const quest_definition *quest, void *user)
player * find_player_partial_name(const char *plname)
void quest_set_player_state(player *pl, sstring quest_code, int state)
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
const char * i18n(const object *who, const char *code)
void command_quest(object *op, const char *params)
SockList * player_get_delayed_buffer(player *pl)
static void quest_write_player_data(const quest_player *pq)
struct quest_condition * next
static quest_step_definition * quest_get_step(quest_definition *quest, int step)
int quest_get_player_state(player *pl, sstring quest_code)
void Send_With_Handling(socket_struct *ns, SockList *sl)
void quest_start(player *pl, sstring quest_code, int state)
static int evaluate_quest_conditions(const quest_condition *condition, player *pl)
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
static void update_quests(player *pl)