Crossfire Server, Trunk
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) {
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  at->head = head;
46  at->clone.head = &head->clone;
47  if (last_more != NULL) {
48  last_more->more = at;
49  last_more->clone.more = &at->clone;
50  }
51  last_more = at;
52 
53  /* Set FLAG_MONSTER throughout parts if head has it */
54  if (QUERY_FLAG(&head->clone, FLAG_MONSTER)) {
56  }
57 
58  /* If this multipart image is still composed of individual small
59  * images, don't set the tail_.. values. We can't use them anyways,
60  * and setting these to zero makes the map sending to the client much
61  * easier as just looking at the head, we know what to do.
62  */
63  if (at->clone.face != head->clone.face) {
64  head->tail_x = 0;
65  head->tail_y = 0;
66  } else {
67  if (at->clone.x > head->tail_x)
68  head->tail_x = at->clone.x;
69  if (at->clone.y > head->tail_y)
70  head->tail_y = at->clone.y;
71  }
72  break;
73  }
74 
75  at = get_archetype_struct();
76  }
77  at->clone.arch = NULL; /* arch is checked for temporary archetypes if not NULL. */
78  free(at);
79 }
global.h
Archetypes
Definition: Archetypes.h:23
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
get_archetype_struct
archetype * get_archetype_struct(void)
Definition: arch.cpp:195
object::arch
struct archetype * arch
Definition: object.h:424
object::x
int16_t x
Definition: object.h:335
object::speed_left
float speed_left
Definition: object.h:338
archetype::head
archetype * head
Definition: object.h:485
npc_dialog.filename
filename
Definition: npc_dialog.py:99
MAP_STYLE
#define MAP_STYLE
Definition: map.h:94
object::y
int16_t y
Definition: object.h:335
AssetsTracker
Definition: AssetsTracker.h:26
AssetsCollection::define
T * define(const Key &name, T *asset)
Definition: AssetsCollection.h:120
archetype::clone
object clone
Definition: object.h:487
ArchetypeLoader::load
virtual void load(BufferReader *reader, const std::string &filename) override
Definition: ArchetypeLoader.cpp:23
object::face
const Face * face
Definition: object.h:341
AssetsTracker::assetDefined
virtual void assetDefined(const archetype *asset, const std::string &filename)
Definition: AssetsTracker.h:34
archetype
Definition: object.h:483
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
object::head
object * head
Definition: object.h:304
ArchetypeLoader::m_archetypes
Archetypes * m_archetypes
Definition: ArchetypeLoader.h:33
archetype::tail_x
int8_t tail_x
Definition: object.h:488
Archetypes.h
ArchetypeLoader.h
loader.h
LL_NORMAL
#define LL_NORMAL
Definition: loader.h:12
archetype::tail_y
int8_t tail_y
Definition: object.h:488
archetype::name
sstring name
Definition: object.h:484
object::more
object * more
Definition: object.h:303
BufferReader
Definition: bufferreader.cpp:21
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)
Definition: loader.cpp:38996