Crossfire Server, Trunk  1.75.0
Archetypes Class Reference

All archetypes in the game. More...

#include <Archetypes.h>

+ Inheritance diagram for Archetypes:
+ Collaboration diagram for Archetypes:

Public Types

typedef std::function< void(archetype *, archetype *)> updateListener
 Function prototype to be called when an archetype changes. More...
 

Public Member Functions

 Archetypes ()
 Standard constructor. More...
 
void clearReplaceListener ()
 Remvove the listener for archetypes changes. More...
 
archetypefindByObjectName (const char *name)
 Retrieve an archetype given the name that appears during the game (for example, "writing pen" instead of "stylus"). More...
 
archetypefindByObjectTypeName (int type, const char *name)
 Retrieve an archetype by type and name that appears during the game. More...
 
archetypefindBySkillNameAndType (const char *skill, int type)
 Retrieve an archetype by skill name and type. More...
 
archetypefindByTypeSubtype (int type, int subtype)
 Retrieve an archetype by type and subtype. More...
 
void setReplaceListener (updateListener fct)
 Set the listener to be called when an archetype is updated. More...
 
- Public Member Functions inherited from AssetsCollection< archetype >
void clear ()
 Clear all assets. More...
 
size_t count () const
 Get the number of assets. More...
 
archetypedefine (const std::string &name, archetype *asset)
 Define an asset, erasing an existing one. More...
 
void each (std::function< void(archetype *)> op)
 Apply a function to each asset. More...
 
archetypefind (const std::string &name)
 Get a named asset if it exists. More...
 
archetypefirst (std::function< bool(const archetype *)> op)
 Find the first asset matching some condition. More...
 
archetypeget (const std::string &name)
 Get a named asset. More...
 
std::vector< std::string > keys () const
 Get the names of all defined assets. More...
 
archetypenext (archetype *current)
 Allow browsing assets in a list-like manner. More...
 
const std::set< std::string > & undefined () const
 Return the list of undefined assets, that is assets requested through get() but not defined through define(). More...
 
virtual ~AssetsCollection ()
 Destroy this instance and all assets it owns. More...
 

Static Public Member Functions

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. More...
 

Protected Member Functions

virtual void replace (archetype *existing, archetype *update) override
 Replace an asset by an updated version. More...
 
- Protected Member Functions inherited from AssetsCollection< archetype >
virtual void added (archetype *)
 An asset was either referenced (but undefined) or defined. More...
 

Protected Attributes

updateListener m_updateListener
 
- Protected Attributes inherited from AssetsCollection< archetype >
std::unordered_map< std::string, archetype * > m_assets
 Known assets. More...
 
std::set< std::string > m_undefined
 List of undefined assets. More...
 

Detailed Description

All archetypes in the game.

Definition at line 23 of file Archetypes.h.

Member Typedef Documentation

◆ updateListener

typedef std::function<void(archetype*, archetype*)> Archetypes::updateListener

Function prototype to be called when an archetype changes.

Definition at line 27 of file Archetypes.h.

Constructor & Destructor Documentation

◆ Archetypes()

Archetypes::Archetypes ( )
inline

Standard constructor.

Definition at line 32 of file Archetypes.h.

References empty_archetype, and AssetsCollection< archetype >::get().

+ Here is the call graph for this function:

Member Function Documentation

◆ clearReplaceListener()

void Archetypes::clearReplaceListener ( )
inline

Remvove the listener for archetypes changes.

Definition at line 47 of file Archetypes.h.

References m_updateListener.

Referenced by AssetsManager::~AssetsManager().

+ Here is the caller graph for this function:

◆ findByObjectName()

archetype * Archetypes::findByObjectName ( const char *  name)

Retrieve an archetype given the name that appears during the game (for example, "writing pen" instead of "stylus").

Parameters
namethe name we're searching for (ex: "writing pen")
Returns
the archetype found or NULL if nothing was found

Definition at line 82 of file Archetypes.cpp.

References find_string(), AssetsCollection< archetype >::m_assets, and name.

Referenced by create_archetype_by_object_name(), and find_archetype_by_object_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findByObjectTypeName()

archetype * Archetypes::findByObjectTypeName ( int  type,
const char *  name 
)

Retrieve an archetype by type and name that appears during the game.

It is basically the same as findByObjectName() except that it considers only items of the given type.

Parameters
typeitem type we're searching
namethe name we're searching for (ex: "writing pen")
Returns
found archetype, NULL if none matched.

Definition at line 97 of file Archetypes.cpp.

References AssetsCollection< archetype >::m_assets, name, and is_valid_types_gen::type.

Referenced by find_archetype_by_object_type_name().

+ Here is the caller graph for this function:

◆ findBySkillNameAndType()

archetype * Archetypes::findBySkillNameAndType ( const char *  skill,
int  type 
)

Retrieve an archetype by skill name and type.

Parameters
skillskill to search for. Must not be NULL.
typeitem type to search for. -1 means that it doesn't matter.
Returns
matching archetype, or NULL if none found.

Definition at line 109 of file Archetypes.cpp.

References AssetsCollection< archetype >::m_assets, skill, and is_valid_types_gen::type.

Referenced by get_archetype_by_skill_name().

+ Here is the caller graph for this function:

◆ findByTypeSubtype()

archetype * Archetypes::findByTypeSubtype ( int  type,
int  subtype 
)

Retrieve an archetype by type and subtype.

This returns the first archetype that matches both the type and subtype. type and subtype can be -1 to say ignore, but in this case, the match it does may not be very useful. This function is most useful when subtypes are known to be unique for a particular type (eg, skills).

Parameters
typeobject type to search for. -1 means any
subtypeobject subtype to search for. -1 means any
Returns
matching archetype, or NULL if none found.

Definition at line 121 of file Archetypes.cpp.

References AssetsCollection< archetype >::m_assets, and is_valid_types_gen::type.

Referenced by get_archetype_by_type_subtype().

+ Here is the caller graph for this function:

◆ recursive_update()

void Archetypes::recursive_update ( object item,
archetype updated 
)
static

Update if needed item based on the updated archetype, then recurse on item->below and item->inv.

Updating implies getting the difference with the obsolete archetype's clone, then applying it to the updated version of the archetype. Inventory items of the updated version are not taken into account.

Parameters
itemwhat to update from.
updatedupdated archetype.

Definition at line 31 of file Archetypes.cpp.

References object::arch, object::below, archetype::clone, get_ob_diff(), object::inv, archetype::name, object_copy_with_inv(), object_free_inventory(), set_variable(), stringbuffer_finish(), stringbuffer_new(), and updated.

Referenced by AssetsManager::archetypeUpdated(), and replace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replace()

void Archetypes::replace ( archetype existing,
archetype update 
)
overrideprotectedvirtual

Replace an asset by an updated version.

Parameters
existingasset to be updated.
updatenew version of the asset, which must be destroyed.

Implements AssetsCollection< archetype >.

Definition at line 62 of file Archetypes.cpp.

References object::arch, archetype::clone, free_arch(), AssetsCollection< archetype >::m_assets, m_updateListener, mark_inv_not_removed(), object_copy_with_inv(), object_free_inventory(), and recursive_update().

+ Here is the call graph for this function:

◆ setReplaceListener()

void Archetypes::setReplaceListener ( updateListener  fct)
inline

Set the listener to be called when an archetype is updated.

Parameters
fctlistener, may be an empty std::function.

Definition at line 40 of file Archetypes.h.

References m_updateListener.

Referenced by AssetsManager::AssetsManager().

+ Here is the caller graph for this function:

Field Documentation

◆ m_updateListener

updateListener Archetypes::m_updateListener
protected

Definition at line 116 of file Archetypes.h.

Referenced by clearReplaceListener(), replace(), and setReplaceListener().


The documentation for this class was generated from the following files: