Crossfire Server, Trunk  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);
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);
30  inv = inv->below;
31  }
33  if (arch->more) {
35  doWrite(arch->more, buf);
36  }
37 }
38 
40  if (arch->head) {
41  return;
42  }
43  doWrite(arch, buf);
44 }
ArchetypeWriter.h
archetype::more
archetype * more
Next part of a linked object.
Definition: object.h:486
object::inv
object * inv
Pointer to the first object in the inventory.
Definition: object.h:298
ArchetypeWriter::write
virtual void write(const archetype *arch, StringBuffer *buf)
Write the specified asset to the StringBuffer.
Definition: ArchetypeWriter.cpp:39
stringbuffer_append_printf
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Append a formatted string to a string buffer instance.
Definition: stringbuffer.cpp:138
archetype::head
archetype * head
The main part of a linked object.
Definition: object.h:485
buf
StringBuffer * buf
Definition: readable.cpp:1565
doWrite
static void doWrite(const archetype *arch, StringBuffer *buf)
Definition: ArchetypeWriter.cpp:15
object::anim_speed
uint8_t anim_speed
Ticks between animation-frames.
Definition: object.h:429
archetype::clone
object clone
An object from which to do object_copy()
Definition: object.h:487
object::casting_time
int16_t casting_time
Time left before spell goes off.
Definition: object.h:414
archetype
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:483
stringbuffer_append_string
void stringbuffer_append_string(StringBuffer *sb, const char *str)
Append a string to a string buffer instance.
Definition: stringbuffer.cpp:95
StringBuffer
A buffer that will be expanded as content is added to it.
Definition: stringbuffer.cpp:25
get_ob_diff
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:4986
empty_archetype
archetype * empty_archetype
Nice to have fast access to it.
Definition: init.cpp:119
archetype::name
sstring name
More definite name, like "generate_kobold".
Definition: object.h:484