Crossfire Server, Trunk  1.75.0
assets.cpp File Reference
#include <sys/stat.h>
#include "autoconf.h"
#include "global.h"
#include "compat.h"
#include "assets.h"
#include "AssetsManager.h"
#include "AssetCollector.h"
#include "TreasureLoader.h"
#include "ArchetypeLoader.h"
#include "PngLoader.h"
#include "FacesetLoader.h"
#include "FaceLoader.h"
#include "WrapperLoader.h"
#include "MessageLoader.h"
#include "QuestLoader.h"
#include "ArtifactLoader.h"
#include "Faces.h"
#include <string.h>
#include <set>
#include <unordered_map>
#include <memory>
#include "AssetWriter.h"
#include "TreasureWriter.h"
#include "FaceWriter.h"
#include "AnimationWriter.h"
#include "ArchetypeWriter.h"
#include "MessageWriter.h"
#include "image.h"
#include "FacesetWriter.h"
#include "ArtifactWriter.h"
#include "FormulaeWriter.h"
#include "QuestWriter.h"
#include "microtar.h"
#include "TarLoader.h"
+ Include dependency graph for assets.cpp:

Go to the source code of this file.

Macros

#define MAX_PACK   100
 

Functions

static void add_to_tar (mtar_t *tar, void *data, size_t len, const char *filename)
 Add a file to a .tar file. More...
 
void archetypes_for_each (arch_op op)
 
void assets_collect (const char *datadir, int what)
 Collect all assets from the specified directory and all its subdirectories. More...
 
void assets_end_load ()
 Called after collect is complete, to check various things. More...
 
void assets_finish_archetypes_for_play ()
 
void assets_free ()
 Free all assets-related memory. More...
 
void assets_init ()
 Init assets-related variables. More...
 
size_t assets_number_of_treasurelists ()
 
size_t assets_number_of_treasures ()
 
void assets_pack (const char *what, const char *filename)
 Pack the specified assets in a file. More...
 
static void build_filename (const char *name, const char *prefix, char *dest, size_t max)
 
static void check_generators (void)
 Check all generators have the other_arch set or something in inventory. More...
 
static void check_spells (void)
 This ensures: More...
 
void check_summoned (void)
 This checks all summonable items for move_type and other things. More...
 
static void check_treasurelist (treasure *t, const treasurelist *tl)
 Checks if a treasure if valid. More...
 
template<class T >
static void do_pack (AssetWriter< T > *writer, AssetsCollection< T > *assets, StringBuffer *buf)
 
void faces_for_each (face_op op)
 
Animationsfind_animation (const char *name)
 
archetypefind_archetype (const char *name)
 
const Facefind_face (const char *name)
 
face_setsfind_faceset (int id)
 
treasurelistfind_treasurelist (const char *name)
 Search for the given treasurelist by name. More...
 
const Faceget_face_by_id (uint16_t id)
 Get a face from its unique identifier. More...
 
size_t get_faces_count ()
 
const GeneralMessageget_message_from_identifier (const char *identifier)
 Find the message from its identifier. More...
 
archetypeget_next_archetype (archetype *current)
 
AssetsManagergetManager ()
 
static void pack_artifacts (StringBuffer *buf)
 
static void pack_formulae (StringBuffer *buf)
 
static void pack_images (mtar_t *tar)
 Pack all client-side images in the specified tar file. More...
 
quest_definitionquest_find_by_code (sstring code)
 Find a quest from its code, logging if no matching quest. More...
 
void quest_for_each (quest_op op, void *user)
 Iterate over all quests. More...
 
quest_definitionquest_get_by_code (sstring code)
 Find a quest from its code if it exists. More...
 
size_t quests_count (bool includeSystem)
 
Animationstry_find_animation (const char *name)
 
archetypetry_find_archetype (const char *name)
 
const Facetry_find_face (const char *name, const Face *error)
 

Variables

static AssetsManagermanager = nullptr
 
size_t nroftreasures = 0
 Number of treasure items, for malloc info. More...
 

Detailed Description

Handles asset collection.

Definition in file assets.cpp.

Macro Definition Documentation

◆ MAX_PACK

#define MAX_PACK   100

Function Documentation

◆ add_to_tar()

static void add_to_tar ( mtar_t tar,
void *  data,
size_t  len,
const char *  filename 
)
static

Add a file to a .tar file.

Parameters
tarwhere to add the file.
datafile content.
lenlength of data.
filenamename in the .tar file.

Definition at line 381 of file assets.cpp.

References fatal(), llevError, LOG(), mtar_header_t::mode, MTAR_ESUCCESS, MTAR_TREG, mtar_write_data(), mtar_write_header(), mtar_header_t::mtime, mtar_header_t::name, SEE_LAST_ERROR, mtar_header_t::size, time, and mtar_header_t::type.

Referenced by assets_pack(), and pack_images().

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

◆ archetypes_for_each()

void archetypes_for_each ( arch_op  op)

Definition at line 300 of file assets.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), and manager.

Referenced by cast_create_food(), init_gods(), init_mon_info(), init_skills(), and spellpath_msg().

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

◆ assets_collect()

void assets_collect ( const char *  datadir,
int  what 
)

◆ assets_end_load()

void assets_end_load ( )

Called after collect is complete, to check various things.

Definition at line 226 of file assets.cpp.

References check_formulae(), check_generators(), check_recipes(), check_spells(), check_summoned(), AssetsCollection< T, Key >::each(), list, manager, and AssetsManager::treasures().

Referenced by load_assets().

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

◆ assets_finish_archetypes_for_play()

void assets_finish_archetypes_for_play ( )

Definition at line 508 of file assets.cpp.

References AssetsManager::archetypes(), archetype::clone, AssetsCollection< T, Key >::each(), manager, and object::speed.

Referenced by command_recollect(), and init_beforeplay().

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

◆ assets_free()

void assets_free ( )

Free all assets-related memory.

Definition at line 71 of file assets.cpp.

References manager.

Referenced by free_globals().

+ Here is the caller graph for this function:

◆ assets_init()

void assets_init ( )

Init assets-related variables.

Definition at line 64 of file assets.cpp.

References manager.

Referenced by init_library().

+ Here is the caller graph for this function:

◆ assets_number_of_treasurelists()

size_t assets_number_of_treasurelists ( )

Definition at line 257 of file assets.cpp.

References AssetsCollection< T, Key >::count(), manager, and AssetsManager::treasures().

Referenced by malloc_info().

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

◆ assets_number_of_treasures()

size_t assets_number_of_treasures ( )

Definition at line 254 of file assets.cpp.

References nroftreasures.

Referenced by malloc_info().

+ Here is the caller graph for this function:

◆ assets_pack()

void assets_pack ( const char *  type,
const char *  filename 
)

◆ build_filename()

static void build_filename ( const char *  name,
const char *  prefix,
char *  dest,
size_t  max 
)
static

Definition at line 359 of file assets.cpp.

References name.

Referenced by pack_images().

+ Here is the caller graph for this function:

◆ check_generators()

static void check_generators ( void  )
static

Check all generators have the other_arch set or something in inventory.

Definition at line 153 of file assets.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), fatal(), FLAG_CONTENT_ON_GEN, FLAG_GENERATOR, if(), manager, QUERY_FLAG, and SEE_LAST_ERROR.

Referenced by assets_end_load().

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

◆ check_spells()

static void check_spells ( void  )
static

This ensures:

  • all spells have a valid skill defined
  • spell_mapping contains valid spells fatal() is called if any error was found.

Definition at line 197 of file assets.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), llevError, LOG(), manager, skill, and SPELL.

Referenced by assets_end_load().

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

◆ check_summoned()

void check_summoned ( void  )

This checks all summonable items for move_type and other things.

Will call fatal() if an error is found.

Definition at line 180 of file assets.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), manager, SP_SUMMON_GOLEM, and SPELL.

Referenced by assets_end_load().

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

◆ check_treasurelist()

static void check_treasurelist ( treasure t,
const treasurelist tl 
)
static

Checks if a treasure if valid.

Will also check its yes and no options.

Will LOG() to error.

Parameters
ttreasure to check.
tlneeded only so that the treasure name can be printed out.

Definition at line 92 of file assets.cpp.

References find_treasurelist(), llevError, LOG(), treasurelist::name, and t.

+ Here is the call graph for this function:

◆ do_pack()

template<class T >
static void do_pack ( AssetWriter< T > *  writer,
AssetsCollection< T > *  assets,
StringBuffer buf 
)
static

Definition at line 332 of file assets.cpp.

References buf, AssetsCollection< T, Key >::each(), and AssetWriter< T >::write().

Referenced by assets_pack().

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

◆ faces_for_each()

void faces_for_each ( face_op  op)

Definition at line 296 of file assets.cpp.

References AssetsCollection< T, Key >::each(), AssetsManager::faces(), and manager.

+ Here is the call graph for this function:

◆ find_animation()

Animations* find_animation ( const char *  name)

Definition at line 273 of file assets.cpp.

References AssetsManager::animations(), AssetsCollection< T, Key >::get(), manager, and name.

Referenced by mimic_type_apply(), transport_type_apply(), and while().

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

◆ find_archetype()

◆ find_face()

const Face* find_face ( const char *  name)

Definition at line 281 of file assets.cpp.

References AssetsManager::faces(), AssetsCollection< T, Key >::get(), manager, and name.

Referenced by MessageLoader::load(), FaceLoader::loadAnimationBlock(), and while().

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

◆ find_faceset()

face_sets* find_faceset ( int  id)

Definition at line 327 of file assets.cpp.

References AssetsManager::facesets(), Facesets::findById(), and manager.

Referenced by esrv_send_face(), get_face_fallback(), is_valid_faceset(), main(), process_map(), and send_image_sums().

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

◆ find_treasurelist()

treasurelist* find_treasurelist ( const char *  name)

Search for the given treasurelist by name.

Parameters
nametreasure list to search.
Returns
match, or NULL if treasurelist doesn't exist or is 'none'.

Definition at line 248 of file assets.cpp.

References AssetsCollection< T, Key >::get(), manager, name, and AssetsManager::treasures().

Referenced by apply_race_and_class(), check_treasurelist(), create_all_treasures(), create_one_treasure(), do_harvest(), dragon_ability_gain(), dump_monster_treasure_rec(), find_treasure_by_name(), god_intervention(), key_change_class(), place_chest(), resurrect_player(), and while().

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

◆ get_face_by_id()

const Face* get_face_by_id ( uint16_t  id)

Get a face from its unique identifier.

Parameters
idface identifier.
Returns
matching face, NULL if no face with this identifier.
Todo:
move back to image.c when migrated

Definition at line 314 of file assets.cpp.

References AssetsManager::faces(), Faces::findById(), and manager.

Referenced by ask_smooth_cmd(), cfapi_system_find_face(), send_face_cmd(), and send_image_sums().

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

◆ get_faces_count()

size_t get_faces_count ( )

Definition at line 292 of file assets.cpp.

References AssetsCollection< T, Key >::count(), AssetsManager::faces(), and manager.

Referenced by init_connection(), main(), new_connection(), reset_faces_sent(), send_image_info(), and send_image_sums().

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

◆ get_message_from_identifier()

const GeneralMessage* get_message_from_identifier ( const char *  identifier)

Find the message from its identifier.

Parameters
identifiermessage's identifier.
Returns
corresponding message, NULL if no such message.

Definition at line 323 of file assets.cpp.

References AssetsCollection< T, Key >::find(), manager, and AssetsManager::messages().

Referenced by knowledge_message_detail(), knowledge_message_face(), knowledge_message_summary(), and knowledge_message_validate().

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

◆ get_next_archetype()

archetype* get_next_archetype ( archetype current)

Definition at line 261 of file assets.cpp.

References AssetsManager::archetypes(), manager, and AssetsCollection< T, Key >::next().

Referenced by artifact_get_face(), and cfapi_archetype_get_property().

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

◆ getManager()

◆ pack_artifacts()

static void pack_artifacts ( StringBuffer buf)
static

Definition at line 339 of file assets.cpp.

References buf, first_artifactlist, list, and ArtifactWriter::write().

Referenced by assets_pack().

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

◆ pack_formulae()

static void pack_formulae ( StringBuffer buf)
static

Definition at line 350 of file assets.cpp.

References buf, get_formulalist(), list, and FormulaeWriter::write().

Referenced by assets_pack().

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

◆ pack_images()

static void pack_images ( mtar_t tar)
static

Pack all client-side images in the specified tar file.

Parameters
tarwhere to pack images.

Definition at line 404 of file assets.cpp.

References add_to_tar(), build_filename(), each, AssetsCollection< T, Key >::each(), face(), AssetsManager::faces(), AssetsManager::facesets(), manager, and treasurelist::name.

Referenced by assets_pack().

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

◆ quest_find_by_code()

quest_definition* quest_find_by_code ( sstring  code)

Find a quest from its code, logging if no matching quest.

Parameters
codequest to search.
Returns
quest, or NULL if no such quest.

Definition at line 518 of file assets.cpp.

References code, llevError, LOG(), and quest_get_by_code().

Referenced by get_quest_by_number(), quest_display(), quest_get_player_state(), quest_info(), quest_set_state(), and quest_start().

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

◆ quest_for_each()

void quest_for_each ( quest_op  op,
void *  user 
)

Iterate over all quests.

Parameters
opfunction to call for each quest.
userextra parameter to give the function.

Definition at line 538 of file assets.cpp.

References AssetsCollection< T, Key >::each(), manager, and AssetsManager::quests().

Referenced by dump_quests(), main(), output_quests(), and update_quests().

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

◆ quest_get_by_code()

quest_definition* quest_get_by_code ( sstring  code)

Find a quest from its code if it exists.

Returns
quest, or NULL if no such quest.

Definition at line 529 of file assets.cpp.

References code, AssetsCollection< T, Key >::find(), manager, and AssetsManager::quests().

Referenced by command_quest(), quest_find_by_code(), quest_read_player_data(), and quest_send_initial_states().

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

◆ quests_count()

size_t quests_count ( bool  includeSystem)

Definition at line 542 of file assets.cpp.

References AssetsCollection< T, Key >::count(), manager, AssetsManager::quests(), and Quests::visibleCount().

+ Here is the call graph for this function:

◆ try_find_animation()

Animations* try_find_animation ( const char *  name)

Definition at line 277 of file assets.cpp.

References AssetsManager::animations(), AssetsCollection< T, Key >::find(), manager, and name.

Referenced by add_abilities(), apply_anim_suffix(), apply_changes_to_player(), cfapi_object_set_property(), cfapi_system_find_animation(), move_aura(), object_give_identified_properties(), and write_rune().

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

◆ try_find_archetype()

◆ try_find_face()

Variable Documentation

◆ manager

◆ nroftreasures

size_t nroftreasures = 0

Number of treasure items, for malloc info.

Definition at line 79 of file assets.cpp.

Referenced by assets_number_of_treasures(), and TreasureLoader::loadTreasure().