Crossfire Server, Trunk  1.75.0
ArchetypeLoader.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 "global.h"
14 #include "loader.h"
15 #include "object.h"
16 
17 #include "ArchetypeLoader.h"
18 #include "Archetypes.h"
19 
20 ArchetypeLoader::ArchetypeLoader(Archetypes *archetypes, AssetsTracker *tracker) : m_archetypes(archetypes), m_tracker(tracker) {
21 }
22 
23 void ArchetypeLoader::load(BufferReader *reader, const std::string &filename) {
24  archetype *at, *head = NULL, *last_more = NULL;
25  int i;
26 
27  at = get_archetype_struct();
28 
29  while ((i = load_object_from_reader(reader, &at->clone, MAP_STYLE, true, false))) {
30  at->clone.speed_left = (float)(-0.1);
31  at = m_archetypes->define(at->name, at);
32 
33  if (m_tracker) {
34  m_tracker->assetDefined(at, filename);
35  }
36 
37  switch (i) {
38  case LL_NORMAL: /* A new archetype, just link it with the previous */
39  head = last_more = at;
40  at->tail_x = 0;
41  at->tail_y = 0;
42  break;
43 
44  case LL_MORE: /* Another part of the previous archetype, link it correctly */
45  if (last_more == NULL) {
46  LOG(llevError, "Error loading arch from %s: multi-part object requires an object before 'more' parts can follow\n", filename.c_str());
48  }
49 
50  at->head = head;
51  at->clone.head = &head->clone;
52  last_more->more = at;
53  last_more->clone.more = &at->clone;
54  last_more = at;
55 
56  /* Set FLAG_MONSTER throughout parts if head has it */
57  if (QUERY_FLAG(&head->clone, FLAG_MONSTER)) {
59  }
60 
61  /* If this multipart image is still composed of individual small
62  * images, don't set the tail_.. values. We can't use them anyways,
63  * and setting these to zero makes the map sending to the client much
64  * easier as just looking at the head, we know what to do.
65  */
66  if (at->clone.face != head->clone.face) {
67  head->tail_x = 0;
68  head->tail_y = 0;
69  } else {
70  if (at->clone.x > head->tail_x)
71  head->tail_x = at->clone.x;
72  if (at->clone.y > head->tail_y)
73  head->tail_y = at->clone.y;
74  }
75  break;
76  }
77 
78  at = get_archetype_struct();
79  }
80  at->clone.arch = NULL; /* arch is checked for temporary archetypes if not NULL. */
81  free(at);
82 }
global.h
Archetypes
All archetypes in the game.
Definition: Archetypes.h:23
llevError
@ llevError
Problems requiring server admin to fix.
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.cpp:82
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:369
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:371
MAP_STYLE
#define MAP_STYLE
Active objects shouldn't be put on active list.
Definition: map.h:99
get_archetype_struct
archetype * get_archetype_struct(void)
Allocates, initialises and returns the pointer to an archetype structure.
Definition: arch.cpp:193
object::arch
struct archetype * arch
Pointer to archetype.
Definition: object.h:426
archetypes
in that case they will be relative to whatever the PWD of the crossfire server process is You probably shouldn though Notes on Specific and settings file datadir Usually usr share crossfire Contains data that the server does not need to modify while such as the archetypes
Definition: server-directories.txt:45
object::x
int16_t x
Definition: object.h:337
object::speed_left
float speed_left
How much speed is left to spend this round.
Definition: object.h:340
archetype::head
archetype * head
The main part of a linked object.
Definition: object.h:487
SEE_LAST_ERROR
@ SEE_LAST_ERROR
Definition: define.h:52
object::y
int16_t y
Position in the map for this object.
Definition: object.h:337
AssetsTracker
Base class to be informed of where an asset is defined.
Definition: AssetsTracker.h:24
AssetsCollection::define
T * define(const Key &name, T *asset)
Define an asset, erasing an existing one.
Definition: AssetsCollection.h:120
archetype::clone
object clone
An object from which to do object_copy()
Definition: object.h:489
ArchetypeLoader::load
virtual void load(BufferReader *reader, const std::string &filename) override
Load assets from the specified reader.
Definition: ArchetypeLoader.cpp:23
FLAG_MONSTER
#define FLAG_MONSTER
Will attack players.
Definition: define.h:232
object::face
const Face * face
Face with colors.
Definition: object.h:343
AssetsTracker::assetDefined
virtual void assetDefined(const archetype *asset, const std::string &filename)
Function called when an asset is defined in a file.
Definition: AssetsTracker.h:32
archetype
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:485
fatal
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
Definition: utils.cpp:595
object::head
object * head
Points to the main object of a large body.
Definition: object.h:306
ArchetypeLoader::m_archetypes
Archetypes * m_archetypes
Definition: ArchetypeLoader.h:33
archetype::tail_x
int8_t tail_x
Definition: object.h:490
Archetypes.h
ArchetypeLoader.h
loader.h
LL_NORMAL
#define LL_NORMAL
Definition: loader.h:12
archetype::tail_y
int8_t tail_y
Where the lower right most portion of the object is in comparison to the head.
Definition: object.h:490
archetype::name
sstring name
More definite name, like "generate_kobold".
Definition: object.h:486
object::more
object * more
Pointer to the rest of a large body of objects.
Definition: object.h:305
BufferReader
Definition: bufferreader.cpp:22
ArchetypeLoader::m_tracker
AssetsTracker * m_tracker
Definition: ArchetypeLoader.h:34
object.h
ArchetypeLoader::ArchetypeLoader
ArchetypeLoader(Archetypes *archetypes, AssetsTracker *tracker)
Definition: ArchetypeLoader.cpp:20
LL_MORE
#define LL_MORE
Definition: loader.h:11
load_object_from_reader
int load_object_from_reader(BufferReader *reader, object *op, int map_flags, bool arch_init, bool artifact_init)
Load an object from the specified reader, stopping when the object is complete.
Definition: loader.cpp:39007