Crossfire Server  1.75.0
FormulaeWriter.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020 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 "FormulaeWriter.h"
14 #include "Utils.h"
15 
16 #define DO(v, s) { if (recipe->v) { stringbuffer_append_printf(buf, s "\n", recipe->v); } }
17 
18 static void writeRecipe(const recipe *recipe, StringBuffer *buf) {
19  if (!recipe) {
20  return;
21  }
22 
23  stringbuffer_append_printf(buf, "Object %s\n", recipe->title);
24  if (recipe->arch_names) {
25  stringbuffer_append_string(buf, "arch");
26  Utils::writeStringArray(recipe->arch_name, recipe->arch_names, buf);
27  stringbuffer_append_string(buf, "\n");
28  }
29  DO(keycode, "keycode %s");
30  DO(transmute, "trans %d");
31  DO(yield, "yield %d");
32  DO(chance, "chance %d");
33  DO(exp, "exp %d");
34  DO(diff, "diff %d");
35  stringbuffer_append_string(buf, "ingred");
36  Utils::writeLinkedChar(recipe->ingred, buf);
37  stringbuffer_append_string(buf, "\n");
38  DO(skill, "skill %s");
39  DO(cauldron, "cauldron %s");
40  DO(failure_arch, "failure_arch %s");
41  DO(failure_message, "failure_message %s");
42  DO(min_level, "min_level %d");
43  DO(is_combination, "combination %d");
44  if (recipe->tool_size) {
45  stringbuffer_append_string(buf, "tool");
46  Utils::writeStringArray(recipe->tool, recipe->tool_size, buf);
47  stringbuffer_append_string(buf, "\n");
48  }
49  writeRecipe(recipe->next, buf);
50 }
51 
53  writeRecipe(list->items, buf);
54 }
static void writeRecipe(const recipe *recipe, StringBuffer *buf)
virtual void write(const recipelist *list, StringBuffer *buf)
Write the specified asset to the StringBuffer.
sstring title
Distinguishing name of product.
Definition: recipe.h:11
linked_char * ingred
List of ingredients.
Definition: recipe.h:22
recipe * items
Pointer to first recipe in this list.
Definition: recipe.h:40
bool chance(int a, int b)
Return true with a probability of a/b.
Definition: treasure.cpp:890
#define DO(v, s)
One alchemy recipe.
Definition: recipe.h:10
size_t arch_names
Size of the arch_name[] array.
Definition: recipe.h:12
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Append a formatted string to a string buffer instance.
size_t tool_size
Length of tool.
Definition: recipe.h:33
void stringbuffer_append_string(StringBuffer *sb, const char *str)
Append a string to a string buffer instance.
List of recipes with a certain number of ingredients.
Definition: recipe.h:37
char ** tool
Tool(s) for item transformation.
Definition: recipe.h:32
static void writeStringArray(char **items, size_t count, StringBuffer *buf)
Write a list of strings as &#39; a,b,c&#39; (leading space).
Definition: Utils.cpp:36
recipe * next
Next recipe with the same number of ingredients.
Definition: recipe.h:24
char ** arch_name
Possible archetypes of the final product made.
Definition: recipe.h:13
StringBuffer * buf
Definition: readable.cpp:1563
A buffer that will be expanded as content is added to it.
static void writeLinkedChar(const linked_char *list, StringBuffer *buf)
Write a list of strings as &#39; a,b,c&#39; (leading space).
Definition: Utils.cpp:22