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 extern "C" {
14 #include "global.h"
15 #include "loader.h"
16 #include "object.h"
17 }
18 
19 #include "ArchetypeLoader.h"
20 #include "Archetypes.h"
21 
22 int arch_init;
24 ArchetypeLoader::ArchetypeLoader(Archetypes *archetypes, AssetsTracker *tracker) : m_archetypes(archetypes), m_tracker(tracker) {
25 }
26 
27 void ArchetypeLoader::load(BufferReader *reader, const std::string &filename) {
28  archetype *at, *head = NULL, *last_more = NULL;
29  int i;
30 
31  at = get_archetype_struct();
32 
33  arch_init = 1;
34 
35  while ((i = load_object_from_reader(reader, &at->clone, MAP_STYLE))) {
36  at->clone.speed_left = (float)(-0.1);
37  at = m_archetypes->define(at->name, at);
38 
39  if (m_tracker) {
41  }
42 
43  switch (i) {
44  case LL_NORMAL: /* A new archetype, just link it with the previous */
45  head = last_more = at;
46  at->tail_x = 0;
47  at->tail_y = 0;
48  break;
49 
50  case LL_MORE: /* Another part of the previous archetype, link it correctly */
51  at->head = head;
52  at->clone.head = &head->clone;
53  if (last_more != NULL) {
54  last_more->more = at;
55  last_more->clone.more = &at->clone;
56  }
57  last_more = at;
58 
59  /* Set FLAG_MONSTER throughout parts if head has it */
60  if (QUERY_FLAG(&head->clone, FLAG_MONSTER)) {
62  }
63 
64  /* If this multipart image is still composed of individual small
65  * images, don't set the tail_.. values. We can't use them anyways,
66  * and setting these to zero makes the map sending to the client much
67  * easier as just looking at the head, we know what to do.
68  */
69  if (at->clone.face != head->clone.face) {
70  head->tail_x = 0;
71  head->tail_y = 0;
72  } else {
73  if (at->clone.x > head->tail_x)
74  head->tail_x = at->clone.x;
75  if (at->clone.y > head->tail_y)
76  head->tail_y = at->clone.y;
77  }
78  break;
79  }
80 
81  at = get_archetype_struct();
82  }
83  at->clone.arch = NULL; /* arch is checked for temporary archetypes if not NULL. */
84  free(at);
85 
86  arch_init = 0;
87 }
global.h
Archetypes
Definition: Archetypes.h:27
obj::face
const Face * face
Definition: object.h:334
archt::head
struct archt * head
Definition: object.h:470
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
load_object_from_reader
int load_object_from_reader(BufferReader *reader, object *op, int map_flags)
Definition: loader.c:5216
archt::tail_x
int8_t tail_x
Definition: object.h:473
get_archetype_struct
archetype * get_archetype_struct(void)
Definition: arch.cpp:198
archt::tail_y
int8_t tail_y
Definition: object.h:473
npc_dialog.filename
filename
Definition: npc_dialog.py:99
MAP_STYLE
#define MAP_STYLE
Definition: map.h:99
archt
Definition: object.h:468
AssetsTracker
Definition: AssetsTracker.h:28
AssetsCollection::define
T * define(const Key &name, T *asset)
Definition: AssetsCollection.h:97
ArchetypeLoader::load
virtual void load(BufferReader *reader, const std::string &filename) override
Definition: ArchetypeLoader.cpp:27
obj::speed_left
float speed_left
Definition: object.h:331
AssetsTracker::assetDefined
virtual void assetDefined(const archetype *asset, const std::string &filename)
Definition: AssetsTracker.h:36
obj::x
int16_t x
Definition: object.h:328
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
obj::y
int16_t y
Definition: object.h:328
obj::arch
struct archt * arch
Definition: object.h:416
ArchetypeLoader::m_archetypes
Archetypes * m_archetypes
Definition: ArchetypeLoader.h:33
archt::clone
object clone
Definition: object.h:472
Archetypes.h
obj::head
struct obj * head
Definition: object.h:297
obj::more
struct obj * more
Definition: object.h:296
ArchetypeLoader.h
loader.h
LL_NORMAL
#define LL_NORMAL
Definition: loader.h:12
archt::name
sstring name
Definition: object.h:469
BufferReader
Definition: bufferreader.c:21
ArchetypeLoader::m_tracker
AssetsTracker * m_tracker
Definition: ArchetypeLoader.h:34
object.h
ArchetypeLoader::ArchetypeLoader
ArchetypeLoader(Archetypes *archetypes, AssetsTracker *tracker)
Definition: ArchetypeLoader.cpp:24
LL_MORE
#define LL_MORE
Definition: loader.h:11
arch_init
int arch_init
Definition: ArchetypeLoader.cpp:22