Crossfire Server  1.75.0
TreasureWriter.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 "TreasureWriter.h"
14 
15 #define W(x, n) { if (item->x) { stringbuffer_append_printf(buf, "%s" n "\n", indentItems.c_str(), item->x); } }
16 
17 static void writeItem(const treasure *item, const std::string &indent, StringBuffer *buf) {
18  std::string indentItems(indent);
19  indentItems += "\t";
20  if (item->item) {
21  stringbuffer_append_printf(buf, "%sarch %s\n", indentItems.c_str(), item->item->name);
22  }
23  W(artifact, "artifact %s");
24  W(name, "list %s");
25  W(list_magic_value, "list_magic_value %d");
26  W(list_magic_adjustment, "list_magic_adjustment %d");
27  indentItems += "\t";
28  W(change_arch.name, "change_name %s");
29  W(change_arch.title, "change_title %s");
30  W(change_arch.slaying, "change_slaying %s");
31  if (item->chance != 100) {
32  stringbuffer_append_printf(buf, "%schance %d\n", indentItems.c_str(), item->chance);
33  }
34  W(nrof, "nrof %d");
35  W(magic, "magic %d");
36  if (item->next_yes) {
37  stringbuffer_append_printf(buf, "%syes\n", indentItems.c_str());
38  writeItem(item->next_yes, indentItems + "\t", buf);
39  }
40  if (item->next_no) {
41  stringbuffer_append_printf(buf, "%sno\n", indentItems.c_str());
42  writeItem(item->next_no, indentItems + "\t", buf);
43  }
44  if (item->next) {
45  stringbuffer_append_string(buf, "more\n");
46  writeItem(item->next, indent, buf);
47  } else {
48  stringbuffer_append_printf(buf, "%send\n", indent.c_str());
49  }
50 }
51 
53  if (list->total_chance == 0) {
54  stringbuffer_append_string(buf, "treasure ");
55  } else {
56  stringbuffer_append_string(buf, "treasureone ");
57  }
58  stringbuffer_append_string(buf, list->name);
59  stringbuffer_append_string(buf, "\n");
60  writeItem(list->items, std::string(), buf);
61 }
static void writeItem(const treasure *item, const std::string &indent, StringBuffer *buf)
virtual void write(const treasurelist *list, StringBuffer *buf)
Write the specified asset to the StringBuffer.
#define W(x, n)
sstring name
More definite name, like "generate_kobold".
Definition: object.h:484
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Append a formatted string to a string buffer instance.
void stringbuffer_append_string(StringBuffer *sb, const char *str)
Append a string to a string buffer instance.
uint8_t chance
Percent chance for this item.
Definition: treasure.h:73
int16_t total_chance
If non-zero, only 1 item on this list should be generated.
Definition: treasure.h:87
treasure * next_no
If this item was not generated, then continue here.
Definition: treasure.h:71
treasurelist represents one logical group of items to be generated together.
Definition: treasure.h:85
treasure * next_yes
If this item was generated, use this link instead of ->next.
Definition: treasure.h:70
treasure * next
Next treasure-item in a linked list.
Definition: treasure.h:69
sstring name
Usually monster-name/combination.
Definition: treasure.h:86
treasure * items
Items in this list, linked.
Definition: treasure.h:92
treasure is one element in a linked list, which together consist of a complete treasure-list.
Definition: treasure.h:63
StringBuffer * buf
Definition: readable.cpp:1563
struct archetype * item
Which item this link can be.
Definition: treasure.h:64
A buffer that will be expanded as content is added to it.
This is one artifact, ie one special item.
Definition: artifact.h:14