Crossfire Server, Trunk
|
#include <Archetypes.h>
Public Types | |
typedef std::function< void(archetype *, archetype *)> | updateListener |
Public Member Functions | |
Archetypes () | |
void | clearReplaceListener () |
archetype * | findByObjectName (const char *name) |
archetype * | findByObjectTypeName (int type, const char *name) |
archetype * | findBySkillNameAndType (const char *skill, int type) |
archetype * | findByTypeSubtype (int type, int subtype) |
void | setReplaceListener (updateListener fct) |
![]() | |
void | clear () |
size_t | count () const |
archetype * | define (const std::string &name, archetype *asset) |
void | each (std::function< void(archetype *)> op) |
archetype * | find (const std::string &name) |
archetype * | first (std::function< bool(const archetype *)> op) |
archetype * | get (const std::string &name) |
archetype * | next (archetype *current) |
const std::set< std::string > & | undefined () const |
Static Public Member Functions | |
static void | recursive_update (object *item, archetype *updated) |
Protected Member Functions | |
virtual archetype * | create (const std::string &name) |
virtual void | destroy (archetype *item) |
virtual void | replace (archetype *existing, archetype *update) |
![]() | |
virtual void | added (archetype *) |
Protected Attributes | |
updateListener | m_updateListener |
![]() | |
std::map< std::string, archetype * > | m_assets |
std::set< std::string > | m_undefined |
All archetypes in the game.
Definition at line 27 of file Archetypes.h.
typedef std::function<void(archetype*, archetype*)> Archetypes::updateListener |
Function prototype to be called when an archetype changes.
Definition at line 31 of file Archetypes.h.
|
inline |
Standard constructor.
Definition at line 36 of file Archetypes.h.
References empty_archetype, and AssetsCollection< archetype >::get().
|
inline |
Remvove the listener for archetypes changes.
Definition at line 51 of file Archetypes.h.
References m_updateListener.
Referenced by AssetsManager::~AssetsManager().
|
protectedvirtual |
Create a new asset.
name | asset unique name. |
Implements AssetsCollection< archetype >.
Definition at line 17 of file Archetypes.cpp.
References add_string(), archininventory::arch, CLEAR_FLAG, FLAG_REMOVED, get_archetype_struct(), and give::name.
|
protectedvirtual |
Destroy an asset.
item | asset to destroy. |
Implements AssetsCollection< archetype >.
Definition at line 24 of file Archetypes.cpp.
References free_arch(), and object_free_inventory().
archetype * Archetypes::findByObjectName | ( | const char * | name | ) |
Retrieve an archetype given the name that appears during the game (for example, "writing pen" instead of "stylus").
name | the name we're searching for (ex: "writing pen") |
Definition at line 80 of file Archetypes.cpp.
References archininventory::arch, find_string(), AssetsCollection< archetype >::m_assets, give::name, and Ice::tmp.
Referenced by create_archetype_by_object_name(), and find_archetype_by_object_name().
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.
type | item type we're searching |
name | the name we're searching for (ex: "writing pen") |
Definition at line 95 of file Archetypes.cpp.
References archininventory::arch, AssetsCollection< archetype >::m_assets, give::name, and is_valid_types_gen::type.
Referenced by find_archetype_by_object_type_name().
archetype * Archetypes::findBySkillNameAndType | ( | const char * | skill, |
int | type | ||
) |
Retrieve an archetype by skill name and type.
skill | skill to search for. Must not be NULL. |
type | item type to search for. -1 means that it doesn't matter. |
Definition at line 107 of file Archetypes.cpp.
References archininventory::arch, AssetsCollection< archetype >::m_assets, and is_valid_types_gen::type.
Referenced by get_archetype_by_skill_name().
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).
type | object type to search for. -1 means any |
subtype | object subtype to search for. -1 means any |
Definition at line 119 of file Archetypes.cpp.
References archininventory::arch, AssetsCollection< archetype >::m_assets, and is_valid_types_gen::type.
Referenced by get_archetype_by_type_subtype().
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.
item | what to update from. |
updated | updated archetype. |
Definition at line 29 of file Archetypes.cpp.
References archininventory::arch, archt::clone, get_ob_diff(), archt::name, object_copy_with_inv(), object_free_inventory(), set_variable(), stringbuffer_finish(), and stringbuffer_new().
Referenced by AssetsManager::archetypeUpdated(), and replace().
Replace an asset by an updated version.
existing | asset to be updated. |
update | new version of the asset, which must be destroyed. |
Implements AssetsCollection< archetype >.
Definition at line 60 of file Archetypes.cpp.
References archininventory::arch, obj::arch, archt::clone, free_arch(), AssetsCollection< archetype >::m_assets, m_updateListener, mark_inv_not_removed(), object_copy_with_inv(), object_free_inventory(), and recursive_update().
|
inline |
Set the listener to be called when an archetype is updated.
fct | listener, may be an empty std::function. |
Definition at line 44 of file Archetypes.h.
References m_updateListener.
Referenced by AssetsManager::AssetsManager().
|
protected |
Definition at line 122 of file Archetypes.h.
Referenced by clearReplaceListener(), replace(), and setReplaceListener().