Crossfire Server  1.75.0
ArchetypeWriter.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 "ArchetypeWriter.h"
14 
15 static void doWrite(const archetype *arch, StringBuffer *buf) {
16  stringbuffer_append_printf(buf, "Object %s\n", arch->name);
17  get_ob_diff(buf, &arch->clone, &empty_archetype->clone);
19  if (arch->clone.anim_speed) {
20  stringbuffer_append_printf(buf, "anim_speed %ld\n", arch->clone.anim_speed);
21  }
22  if (arch->clone.casting_time) {
23  stringbuffer_append_printf(buf, "casting_time %d\n", arch->clone.casting_time);
24  }
25  auto inv = arch->clone.inv;
26  while (inv) {
27  stringbuffer_append_printf(buf, "arch %s\n", inv->arch->name);
28  get_ob_diff(buf, inv, &inv->arch->clone);
29  stringbuffer_append_string(buf, "end\n");
30  inv = inv->below;
31  }
32  stringbuffer_append_string(buf, "end\n");
33  if (arch->more) {
34  stringbuffer_append_string(buf, "more\n");
35  doWrite(arch->more, buf);
36  }
37 }
38 
40  if (arch->head) {
41  return;
42  }
43  doWrite(arch, buf);
44 }
uint8_t anim_speed
Ticks between animation-frames.
Definition: object.h:429
archetype * head
The main part of a linked object.
Definition: object.h:485
static void doWrite(const archetype *arch, StringBuffer *buf)
int16_t casting_time
Time left before spell goes off.
Definition: object.h:414
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:483
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.
archetype * empty_archetype
Nice to have fast access to it.
Definition: init.cpp:119
virtual void write(const archetype *arch, StringBuffer *buf)
Write the specified asset to the StringBuffer.
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
archetype * more
Next part of a linked object.
Definition: object.h:486
StringBuffer * buf
Definition: readable.cpp:1563
A buffer that will be expanded as content is added to it.
object clone
An object from which to do object_copy()
Definition: object.h:487