Crossfire Server  1.75.0
Archetypes.h
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020-2021 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 #ifndef ARCHETYPES_H
14 #define ARCHETYPES_H
15 
16 #include <functional>
17 #include "AssetsCollection.h"
18 #include "global.h"
19 
23 class Archetypes : public AssetsCollection<archetype> {
24 
25 public:
27  typedef std::function<void(archetype*, archetype*)> updateListener;
28 
33  empty_archetype = get("empty_archetype");
34  }
35 
40  void setReplaceListener(updateListener fct) {
41  m_updateListener = fct;
42  }
43 
49  }
50 
59  archetype *findByObjectName(const char *name);
60 
72  archetype *findByObjectTypeName(int type, const char *name);
73 
83  archetype *findBySkillNameAndType(const char *skill, int type);
84 
100  archetype *findByTypeSubtype(int type, int subtype);
101 
111  static void recursive_update(object *item, archetype *updated);
112 
113 protected:
114  virtual void replace(archetype *existing, archetype *update) override;
115 
116  updateListener m_updateListener;
117 };
118 
119 #endif /* ARCHETYPES_H */
120 
static void recursive_update(object *item, archetype *updated)
Update if needed item based on the updated archetype, then recurse on item->below and item->inv...
Definition: Archetypes.cpp:31
void clearReplaceListener()
Remvove the listener for archetypes changes.
Definition: Archetypes.h:47
archetype * findBySkillNameAndType(const char *skill, int type)
Retrieve an archetype by skill name and type.
Definition: Archetypes.cpp:109
archetype * findByObjectName(const char *name)
Retrieve an archetype given the name that appears during the game (for example, "writing pen" instead...
Definition: Archetypes.cpp:82
std::function< void(archetype *, archetype *)> updateListener
Function prototype to be called when an archetype changes.
Definition: Archetypes.h:27
All archetypes in the game.
Definition: Archetypes.h:23
Collection of assets identified by a unique name.
Archetypes()
Standard constructor.
Definition: Archetypes.h:32
Global type definitions and header inclusions.
void setReplaceListener(updateListener fct)
Set the listener to be called when an archetype is updated.
Definition: Archetypes.h:40
virtual void replace(archetype *existing, archetype *update) override
Replace an asset by an updated version.
Definition: Archetypes.cpp:62
updateListener m_updateListener
Definition: Archetypes.h:116
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:483
archetype * findByObjectTypeName(int type, const char *name)
Retrieve an archetype by type and name that appears during the game.
Definition: Archetypes.cpp:97
archetype * empty_archetype
Nice to have fast access to it.
Definition: init.cpp:119
archetype * findByTypeSubtype(int type, int subtype)
Retrieve an archetype by type and subtype.
Definition: Archetypes.cpp:121