Crossfire Server  1.75.0
ArtifactWriter.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020-2022 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 "ArtifactWriter.h"
14 
15 #include "string.h"
16 #include "Utils.h"
17 
19  stringbuffer_append_string(buf, "Allowed");
20  if (item->allowed.empty()) {
21  stringbuffer_append_string(buf, " all");
22  } else {
23  char sep = ' ';
24  for (const auto allowed : item->allowed) {
25  stringbuffer_append_printf(buf, "%c%s", sep, allowed);
26  sep = ',';
27  }
28  }
29  stringbuffer_append_string(buf, "\n");
30 
31  if (item->chance) {
32  stringbuffer_append_printf(buf, "chance %d\n", item->chance);
33  }
34  if (item->difficulty) {
35  stringbuffer_append_printf(buf, "difficulty %d\n", item->difficulty);
36  }
37  if (item->item) {
38  stringbuffer_append_printf(buf, "Object %s\n", item->item->name);
39  auto name = item->item->name;
40  item->item->name = nullptr;
41  get_ob_diff(buf, item->item, &empty_archetype->clone);
42  item->item->name = name;
44  if (item->item->anim_speed) {
45  stringbuffer_append_printf(buf, "anim_speed %ld\n", item->item->anim_speed);
46  }
47 
48  auto inv = item->item->inv;
49  while (inv) {
50  stringbuffer_append_printf(buf, "arch %s\n", inv->arch->name);
51  get_ob_diff(buf, inv, &inv->arch->clone);
52  stringbuffer_append_string(buf, "end\n");
53  inv = inv->below;
54  }
55  stringbuffer_append_string(buf, "end\n");
56  }
57 }
uint8_t anim_speed
Ticks between animation-frames.
Definition: object.h:429
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Append a formatted string to a string buffer instance.
uint8_t difficulty
Minimum map difficulty for the artifact to happen.
Definition: artifact.h:17
void stringbuffer_append_string(StringBuffer *sb, const char *str)
Append a string to a string buffer instance.
sstring name
The name of the object, obviously...
Definition: object.h:319
archetype * empty_archetype
Nice to have fast access to it.
Definition: init.cpp:119
void get_ob_diff(StringBuffer *sb, const object *op, const object *op2)
Returns a pointer to a static string which contains all variables which are different in the two give...
Definition: object.cpp:4971
object * inv
Pointer to the first object in the inventory.
Definition: object.h:298
virtual void write(const artifact *item, StringBuffer *buf)
Write the specified asset to the StringBuffer.
StringBuffer * buf
Definition: readable.cpp:1563
A buffer that will be expanded as content is added to it.
This is one artifact, ie one special item.
Definition: artifact.h:14
object clone
An object from which to do object_copy()
Definition: object.h:487
object * item
Special values of the artifact.
Definition: artifact.h:15
uint16_t chance
Chance of the artifact to happen.
Definition: artifact.h:16
std::vector< sstring > allowed
List of archetypes the artifact can affect.
Definition: artifact.h:18