Crossfire Server, Trunk
QuestWriter.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2021 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "QuestWriter.h"
14 
15 #define W(x, n) { if (quest->x) { stringbuffer_append_printf(buf, n "\n", quest->x); } }
16 
18  W(quest_code, "quest %s");
19  W(quest_title, "title %s");
20  if (quest->face) {
21  stringbuffer_append_printf(buf, "face %s\n", quest->face->name);
22  }
23  stringbuffer_append_multiline_block(buf, "description", quest->quest_description, NULL);
24  if (quest->parent) {
25  stringbuffer_append_printf(buf, "parent %s\n", quest->parent->quest_code);
26  }
27  W(quest_restart, "restart %d");
28  W(quest_is_system, "is_system %d");
29  stringbuffer_append_multiline_block(buf, "comment", quest->quest_comment, NULL);
30  auto step = quest->steps;
31  while (step) {
32  stringbuffer_append_printf(buf, "step %d\n", step->step);
33  if (step->is_completion_step) {
34  stringbuffer_append_string(buf, "finishes_quest\n");
35  }
36  stringbuffer_append_multiline_block(buf, "description", step->step_description, NULL);
37  if (step->conditions) {
38  stringbuffer_append_string(buf, "setwhen\n");
39  char when[500];
40  auto cond = step->conditions;
41  while (cond) {
42  quest_write_condition(when, sizeof(when), cond);
43  stringbuffer_append_printf(buf, "%s\n", when);
44  cond = cond->next;
45  }
46  stringbuffer_append_string(buf, "end_setwhen\n");
47  }
48  stringbuffer_append_string(buf, "end_step\n");
49  step = step->next;
50  }
51  stringbuffer_append_string(buf, "end_quest\n");
52  /*
53 
54  foreach(QuestStep* step, quest->steps())
55  {
56  if (step->setWhen().size() > 0)
57  {
58  stream << "setwhen\n";
59  foreach(QString when, step->setWhen())
60  {
61  stream << when << "\n";
62  }
63  stream << "end_setwhen\n";
64  }
65  stream << "end_step\n";
66 
67  }
68 
69  stream << "end_quest\n\n";*/
70 }
W
#define W(x, n)
Definition: QuestWriter.cpp:15
quest_write_condition
void quest_write_condition(char *buf, size_t len, const quest_condition *cond)
Definition: Quests.cpp:134
QuestWriter.h
quest
Definition: quest.py:1
stringbuffer_append_string
void stringbuffer_append_string(StringBuffer *sb, const char *str)
Definition: stringbuffer.c:95
StringBuffer
Definition: stringbuffer.c:25
stringbuffer_append_multiline_block
void stringbuffer_append_multiline_block(StringBuffer *sb, const char *start, const char *content, const char *end)
Definition: stringbuffer.c:196
QuestWriter::write
virtual void write(const quest_definition *quest, StringBuffer *buf)
Definition: QuestWriter.cpp:17
quest_definition
Definition: quest.h:42
buf
StringBuffer * buf
Definition: readable.c:1610
stringbuffer_append_printf
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Definition: stringbuffer.c:138