41 #include <unordered_map> 94 if (t->
item == NULL && t->
name == NULL)
95 LOG(
llevError,
"Treasurelist %s has element with no name or archetype\n", tl->
name);
97 LOG(
llevError,
"Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", tl->
name);
98 if (t->
name && strcmp(t->
name,
"NONE"))
114 LOG(
llevInfo,
"Starting to collect assets from %s\n", datadir);
148 if (what & ASSETS_ARTIFACTS) {
152 LOG(
llevInfo,
"Finished collecting assets from %s\n", datadir);
166 LOG(llevError,
"Fatal: %s is generator without content_on_gen but lacks other_arch.\n", arch->name);
171 LOG(llevError,
"Fatal: %s is generator with content_on_gen but lacks inventory.\n", arch->name);
187 if (arch->clone.type ==
SPELL && arch->clone.subtype ==
SP_SUMMON_GOLEM && arch->clone.other_arch) {
188 if (arch->clone.other_arch->clone.move_type == 0) {
189 LOG(llevError,
"Summonable archetype %s [%s] has no move_type defined!\n", arch->clone.other_arch->name, arch->clone.other_arch->clone.name);
190 fatal(SEE_LAST_ERROR);
206 if (arch->clone.type ==
SPELL && arch->clone.skill) {
207 auto skill = manager->archetypes()->first([&arch] (const archetype *skill) {
208 return skill->clone.type == SKILL && arch->clone.skill == skill->clone.name;
211 LOG(
llevError,
"Spell %s has improper associated skill %s\n", arch->name, arch->clone.skill);
237 check_treasurelist(list->items, list);
254 if (!strcmp(name,
"none"))
291 auto found = manager->
faces()->
find(name);
338 assets->
each([writer, buf] (T *asset) {
339 writer->
write(asset, buf);
348 for (
const auto item : list->
items) {
349 writer.
write(item, buf);
359 writer.
write(list, buf);
364 static void build_filename(
const char *name,
const char *prefix,
char *dest,
size_t max) {
365 auto dot = strrchr(name,
'.');
368 snprintf(dest, max,
"%s.%s", name, prefix);
373 memset(dest, 0, max);
376 snprintf(dest, max,
"%.*s%s.%s.png", (
int)(dot - name), name, prefix, dot);
388 memset(&h, 0,
sizeof(h));
389 strncpy(h.
name, filename,
sizeof(h.
name));
393 h.
mtime = time(NULL);
396 LOG(
llevError,
"Failed to write tar header for %s\n", filename);
400 LOG(
llevError,
"Failed to write tar data for %s\n", filename);
410 manager->
faces()->
each([&tar] (
const auto face) {
411 manager->
facesets()->
each([&tar, &face] (
const auto fs) {
412 if (!fs->prefix || fs->allocated <= face->number || !fs->faces[face->number].datalen) {
416 build_filename(face->name, fs->prefix, filename,
sizeof(filename));
417 add_to_tar(tar, fs->faces[face->number].data, fs->faces[face->number].datalen, filename);
431 bool isTar = (count > 1) || (strcmp(split[0],
"images") == 0);
435 LOG(
llevError,
"Failed to open tar file %s\n", filename);
440 for (
size_t t = 0; t < count; t++) {
441 const char *type = split[t];
442 const char *name =
nullptr;
445 if (strcmp(type,
"treasures") == 0) {
447 name =
"crossfire.trs";
448 }
else if (strcmp(type,
"faces") == 0) {
451 name =
"crossfire.face";
452 }
else if (strcmp(type,
"archs") == 0) {
454 name =
"crossfire.arc";
455 }
else if (strcmp(type,
"messages") == 0) {
458 }
else if (strcmp(type,
"facesets") == 0) {
461 }
else if (strcmp(type,
"artifacts") == 0) {
464 }
else if (strcmp(type,
"formulae") == 0) {
467 }
else if (strcmp(type,
"quests") == 0) {
469 name =
"crossfire.quests";
470 }
else if (strcmp(type,
"images") == 0) {
485 FILE *out = fopen(filename,
"w+");
490 if (fwrite(static_cast<void*>(data), 1, length, out) != length) {
491 LOG(
llevError,
"Failed to write all data for %s!\n", filename);
502 LOG(
llevError,
"Failed to finalize tar file %s\n", filename);
506 LOG(
llevError,
"Failed to closed tar file %s\n", filename);
515 object *op = &arch->
clone;
517 op->speed_left = op->speed_left - RANDOM() % 100 / 100.0;
518 op->speed = -op->speed;
528 LOG(
llevError,
"quest %s required but not found!\n", code);
544 manager->
quests()->
each([&op, &user] (
auto q) { op(q, user); });
T * next(T *current)
Allow browsing assets in a list-like manner.
static void build_filename(const char *name, const char *prefix, char *dest, size_t max)
char * stringbuffer_finish(StringBuffer *sb)
Deallocate the string buffer instance and return the string.
static void check_spells(void)
This ensures:
Treasures * treasures()
Get treasures.
This represents one animation.
void(* face_op)(const Face *)
Assets collector, recursing in directories and calling loaders on found files.
const char *const spell_mapping[SPELL_MAPPINGS]
This table is only necessary to convert objects that existed before the spell object conversion to th...
Definition of an in-game quest.
T * get(const Key &name)
Get a named asset.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
recipelist * next
Pointer to next recipe list.
static std::vector< std::string > split(const std::string &field, const std::string &by)
AllAnimations * animations()
Get animations.
archetype * find_archetype(const char *name)
size_t stringbuffer_length(StringBuffer *sb)
Return the current length of the buffer.
void assets_add_collector_hook(const char *name, collectorHook hook)
int mtar_write_header(mtar_t *tar, const mtar_header_t *h)
void archetypes_for_each(arch_op op)
New face structure - this enforces the notion that data is face by face only - you can not change the...
Quests * quests()
Get quests.
Represents all assets of the game.
sstring name
If non null, name of list to use instead.
const Face * findById(uint16_t id)
void quest_for_each(quest_op op, void *user)
Iterate over all quests.
Collection of assets identified by a unique name.
void assets_init()
Init assets-related variables.
void init_attackmess(BufferReader *reader, const char *filename)
Initializes the attack messages.
face_sets * find_faceset(int id)
Animations * find_animation(const char *name)
StringBuffer * stringbuffer_new(void)
Create a new string buffer.
static AssetsManager * manager
Facesets * facesets()
Get facesets.
static void pack_formulae(StringBuffer *buf)
Global type definitions and header inclusions.
#define ASSETS_ATTACK_MESSAGES
archetype * try_find_archetype(const char *name)
void collect(const std::string &directory)
Recurse in the specified directory, finding all files and calling loaders to process them...
int mtar_finalize(mtar_t *tar)
AssetsManager * getManager()
const Face * try_find_face(const char *name, const Face *error)
void assets_collect(const char *datadir, int what)
Collect all assets from the specified directory and all its subdirectories.
static void pack_images(mtar_t *tar)
Pack all client-side images in the specified tar file.
bool check_formulae(void)
Check if formula don't have the same index.
size_t split_string(char *str, char *array[], size_t array_size, char sep)
Splits a string delimited by passed in sep value into characters into an array of strings...
std::vector< artifact * > items
Artifacts for this type.
bool check_recipes()
Ensure that all recipes have a valid artifact, and that archetypes are correct.
static std::vector< std::pair< std::string, collectorHook > > collector_hooks
Collect hooks, as (filename, function) pairs.
Faces * faces()
Get faces.
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Image-related structures.
size_t assets_number_of_treasurelists()
void(* quest_op)(const quest_definition *, void *)
float speed
Frequency of object 'moves' relative to server tick rate.
static void add_to_tar(mtar_t *tar, void *data, size_t len, const char *filename)
Add a file to a .tar file.
face_sets * findById(int id)
Attempt to find a faceset from its identifier.
#define QUERY_FLAG(xyz, p)
Abstract writer of an asset to a StringBuffer.
artifactlist * next
Next list of artifacts.
size_t quests_count(bool includeSystem)
static void check_treasurelist(treasure *t, const treasurelist *tl)
Checks if a treasure if valid.
uint8_t chance
Percent chance for this item.
List of recipes with a certain number of ingredients.
void init_regions(BufferReader *reader, const char *filename)
Reads/parses the region file, and copies into a linked list of region structs.
artifactlist * first_artifactlist
First artifact.
void(* arch_op)(archetype *)
Archetypes * archetypes()
Get archetypes.
#define ASSETS_ARCHETYPES
size_t count() const
Get the number of assets.
This represents all archetypes for one particular object type.
static void pack_artifacts(StringBuffer *buf)
size_t nroftreasures
Number of treasure items, for malloc info.
struct Settings settings
Global settings.
archetype * get_next_archetype(archetype *current)
void artifact_post_load()
int mtar_write_data(mtar_t *tar, const void *data, unsigned size)
recipelist * get_formulalist(int i)
Gets a formula list by ingredients count.
Messages * messages()
Get messages.
treasure * next_no
If this item was not generated, then continue here.
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
static void check_generators(void)
Check all generators have the other_arch set or something in inventory.
void assets_pack(const char *what, const char *filename)
Pack the specified assets in a file.
Compatibility implementations of useful nonstandard types and functions.
void assets_finish_archetypes_for_play()
void assets_end_load()
Called after collect is complete, to check various things.
treasurelist represents one logical group of items to be generated together.
class AssetsTracker * assets_tracker
If not NULL, called each time an asset is defined.
treasure * next_yes
If this item was generated, use this link instead of ->next.
void addLoader(AssetLoader *loader)
Register a loader to be called on found files.
const char * datadir
Read only data files.
quest_definition * quest_get_by_code(sstring code)
Find a quest from its code if it exists.
#define FLAG_GENERATOR
Will generate type ob->stats.food.
Loader calling a function for files ending with a specific string.
treasure * next
Next treasure-item in a linked list.
virtual void write(const T *asset, StringBuffer *buf)=0
Write the specified asset to the StringBuffer.
Animations * try_find_animation(const char *name)
void faces_for_each(face_op op)
std::function< void(BufferReader *, const char *)> collectorHook
sstring name
Usually monster-name/combination.
const Face * find_face(const char *name)
int mtar_open(mtar_t *tar, const char *filename, const char *mode)
void stringbuffer_delete(StringBuffer *sb)
Totally delete a string buffer.
treasurelist * find_treasurelist(const char *name)
Search for the given treasurelist by name.
treasure is one element in a linked list, which together consist of a complete treasure-list.
virtual void write(const artifact *item, StringBuffer *buf)
Write the specified asset to the StringBuffer.
size_t visibleCount() const
const GeneralMessage * get_message_from_identifier(const char *identifier)
Find the message from its identifier.
T * find(const Key &name)
Get a named asset if it exists.
C function wrappers to interact with assets.
One general message, from the lib/messages file.
struct archetype * item
Which item this link can be.
void init_formulae(BufferReader *reader, const char *filename)
Builds up the lists of formula from the file in the libdir.
A buffer that will be expanded as content is added to it.
int mtar_close(mtar_t *tar)
quest_definition * quest_find_by_code(sstring code)
Find a quest from its code, logging if no matching quest.
void check_summoned(void)
This checks all summonable items for move_type and other things.
Information about one face set.
#define FLAG_CONTENT_ON_GEN
Use
object clone
An object from which to do object_copy()
static void do_pack(AssetWriter< T > *writer, AssetsCollection< T > *assets, StringBuffer *buf)
size_t assets_number_of_treasures()
void assets_free()
Free all assets-related memory.
const Face * get_face_by_id(uint16_t id)
Get a face from its unique identifier.
void each(std::function< void(T *)> op)
Apply a function to each asset.