Crossfire Server, Trunk
|
#include "global.h"
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <memory>
#include "object.h"
#include "assets.h"
#include "AssetsManager.h"
Go to the source code of this file.
Functions | |
static void | build_stringlist (const char *str, char ***result_list, size_t *result_size) |
void | check_formulae (void) |
static int | check_recipe (const recipe *rp) |
void | check_recipes () |
void | dump_alchemy (void) |
void | dump_alchemy_costs (void) |
recipe * | find_recipe_for_tool (const char *tool, recipe *from) |
archetype * | find_treasure_by_name (const treasure *t, const char *name, int depth) |
void | free_all_recipes (void) |
static recipe * | get_empty_formula (void) |
recipelist * | get_formulalist (int i) |
recipe * | get_random_recipe (recipelist *rpl) |
static recipelist * | get_random_recipelist (void) |
static const char * | ingred_name (const char *name) |
void | init_formulae (BufferReader *reader, const char *filename) |
static recipelist * | init_recipelist (void) |
const artifact * | locate_recipe_artifact (const recipe *rp, size_t idx) |
static int | numb_ingred (const char *buf) |
static long | recipe_find_ingredient_cost (const char *name) |
const Face * | recipe_get_face (const recipe *rp) |
int | strtoint (const char *buf) |
Variables | |
static recipelist * | formulalist |
Basic stuff for use with the alchemy code. Clearly some of this stuff could go into server/alchemy, but I left it here just in case it proves more generally useful.
Nov 1995 - file created by b.t. thoma s@as tro.p su.e du
Our definition of 'formula' is any product of an alchemical process. Ingredients are just comma delimited list of archetype (or object) names.
Example 'formula' entry in libdir/formulae: Object transparency chance 10 ingred dust of beholdereye,gem arch potion_generic
An ingredient is a name, which can contain an initial number for how many are needed.
Definition in file recipe.cpp.
|
static |
Split a comma separated string list into words.
str | the string to split | |
[out] | result_list | pointer to return value for the newly created list; the caller is responsible for freeing both *result_list and **result_list. |
[out] | result_size | pointer to return value for the size of the newly created list |
Definition at line 863 of file recipe.cpp.
References fatal(), OUT_OF_MEMORY, make_face_from_files::str, and strdup_local.
Referenced by init_formulae().
void check_formulae | ( | void | ) |
Check if formula don't have the same index.
Since we are doing a squential search on the formulae lists now, we have to be carefull that we dont have 2 formula with the exact same index value. Under the new nbatches code, it is possible to have multiples of ingredients in a cauldron which could result in an index formula mismatch. We *don't *check for that possibility here. -b.t.
LOG() to error level.
Definition at line 295 of file recipe.cpp.
References recipe::arch_name, recipe::arch_names, recipe::cauldron, bigchest::check, formulalist, recipe::index, recipelist::items, llevDebug, llevError, LOG(), recipe::next, recipelist::next, recipe::title, recipe::tool, recipe::tool_size, and try_find_archetype().
Referenced by assets_end_load().
|
static |
Makes sure we actually have the requested artifact and archetype.
rp | recipe we want to check. |
Definition at line 120 of file recipe.cpp.
References recipe::arch_name, recipe::arch_names, llevError, locate_recipe_artifact(), LOG(), rotate-tower::result, recipe::title, and try_find_archetype().
Referenced by check_recipes().
void check_recipes | ( | ) |
Ensure that all recipes have a valid artifact, and that archetypes are correct. Will call fatal() if any error is found.
Definition at line 148 of file recipe.cpp.
References check_recipe(), fatal(), formulalist, recipelist::items, recipe::next, recipelist::next, and SEE_LAST_ERROR.
Referenced by assets_end_load().
void dump_alchemy | ( | void | ) |
Dumps alchemy recipes to output. Borrowed (again) from the artifacts code for this.
Definition at line 352 of file recipe.cpp.
References recipe::arch_name, recipe::arch_names, buf, recipe::cauldron, recipe::chance, recipe::diff, recipe::exp, formulalist, recipe::index, recipe::ingred, recipelist::items, llevError, locate_recipe_artifact(), LOG(), logfile, MAX_BUF, recipe::next, recipelist::next, give::next, recipelist::number, recipe::skill, strlcpy(), strtoint(), recipe::title, recipelist::total_chance, and try_find_archetype().
Referenced by init_beforeplay().
void dump_alchemy_costs | ( | void | ) |
Dumps to output all costs of recipes.
Code copied from dump_alchemy() and modified by Raphael Quinet
Definition at line 590 of file recipe.cpp.
References recipe::arch_name, recipe::arch_names, buf, recipe::chance, archetype::clone, diamondslots::cost, formulalist, recipe::ingred, artifact::item, recipelist::items, llevError, locate_recipe_artifact(), LOG(), logfile, MAX_BUF, recipe::next, recipelist::next, give::next, recipelist::number, recipe_find_ingredient_cost(), recipe::skill, strlcpy(), recipe::title, recipelist::total_chance, try_find_archetype(), object::value, and recipe::yield.
Referenced by init_beforeplay().
Find a recipe for a specified tool. This function can be called multiple times to browse the whole list, using the 'from' parameter.
tool | tool's archetype name. |
from | formula to search from, if NULL from the first one. |
Definition at line 896 of file recipe.cpp.
References formulalist, get_formulalist(), recipe::ingred_count, guildoracle::list, recipe::next, Floor::t, recipe::tool, and recipe::tool_size.
Referenced by command_use().
Find a treasure with a matching name. The 'depth' parameter is only there to prevent infinite loops in treasure lists (a list referencing another list pointing back to the first one).
t | item of treasure list to search from |
name | name we're trying to find. Doesn't need to be a shared string. |
depth | current depth. Code will exit if greater than 10. |
Definition at line 424 of file recipe.cpp.
References find_treasure_by_name(), find_treasurelist(), treasurelist::items, give::name, strcasecmp(), and Floor::t.
Referenced by find_treasure_by_name().
void free_all_recipes | ( | void | ) |
Frees all memory allocated to recipes and recipes lists.
Definition at line 813 of file recipe.cpp.
References recipe::arch_name, recipe::cauldron, recipe::failure_arch, recipe::failure_message, formulalist, free_string(), recipe::ingred, recipelist::items, llevDebug, LOG(), linked_char::name, recipe::next, recipelist::next, give::next, linked_char::next, recipe::skill, recipe::title, and recipe::tool.
Referenced by cleanup(), and init_formulae().
|
static |
Allocates a new recipe.
Will call fatal() if memory allocation error.
Definition at line 79 of file recipe.cpp.
References fatal(), OUT_OF_MEMORY, and Floor::t.
Referenced by init_formulae().
recipelist* get_formulalist | ( | int | i | ) |
Gets a formula list by ingredients count.
i | number of ingredients. |
Definition at line 98 of file recipe.cpp.
References formulalist, and recipelist::next.
Referenced by alchemy_failure_effect(), alchemyTable(), attempt_do_alchemy(), RecipesWrapper::child(), RecipesWrapper::childIndex(), ArtifactPanel::computeMadeViaAlchemy(), find_recipe_for_tool(), get_random_recipelist(), knowledge_alchemy_get_recipe(), ResourcesManager::load(), make_formula_book(), CREMainWindow::onReportAlchemyGraph(), and pack_formulae().
recipe* get_random_recipe | ( | recipelist * | rpl | ) |
Gets a random recipe from a list, based on chance.
rpl | recipelist we want a recipe from. Can be NULL in which case a random one is selected. |
Definition at line 789 of file recipe.cpp.
References recipe::chance, get_random_recipelist(), recipelist::items, recipe::next, ring_occidental_mages::r, RANDOM, and recipelist::total_chance.
Referenced by alchemy_failure_effect().
|
static |
Gets a random recipe list.
Definition at line 753 of file recipe.cpp.
References get_formulalist(), llevError, LOG(), recipelist::next, RANDOM, and recipelist::total_chance.
Referenced by get_random_recipe().
|
static |
Extracts the name from an ingredient.
name | ingredient to extract from. Can contain a number at start. |
Definition at line 676 of file recipe.cpp.
References give::name.
Referenced by strtoint().
void init_formulae | ( | BufferReader * | reader, |
const char * | filename | ||
) |
Builds up the lists of formula from the file in the libdir. -b.t.
Definition at line 169 of file recipe.cpp.
References add_string(), recipe::arch_name, recipe::arch_names, buf, bufferreader_current_line(), bufferreader_next_line(), build_stringlist(), recipe::cauldron, recipe::chance, recipe::diff, recipe::exp, recipe::failure_arch, recipe::failure_message, fatal(), npc_dialog::filename, formulalist, free_all_recipes(), get_empty_formula(), recipe::index, recipe::ingred, recipe::ingred_count, init_recipelist(), recipe::is_combination, recipelist::items, recipe::keycode, llevDebug, llevError, LOG(), recipe::min_level, recipe::next, recipelist::next, give::next, numb_ingred(), recipelist::number, SEE_LAST_ERROR, recipe::skill, strtoint(), recipe::title, Ice::tmp, recipe::tool, recipe::tool_size, recipelist::total_chance, recipe::transmute, autojail::value, and recipe::yield.
Referenced by assets_collect().
|
static |
Allocates a new recipelist.
Will call fatal() if memory allocation error.
Definition at line 60 of file recipe.cpp.
References fatal(), recipelist::items, recipelist::next, recipelist::number, OUT_OF_MEMORY, and recipelist::total_chance.
Referenced by init_formulae().
Finds an artifact for a recipe.
rp | recipe |
idx | index of ingredient in recipe. |
Definition at line 732 of file recipe.cpp.
References recipe::arch_name, create_archetype(), find_artifactlist(), say::item, legal_artifact_combination(), diamondslots::object, object_free_drop_inventory(), recipe::title, and nlohmann::detail::void().
Referenced by check_recipe(), dump_alchemy(), dump_alchemy_costs(), make_item_from_recipe(), and recipe_get_face().
|
static |
Extracts the number part of an ingredient.
buf | ingredient. |
Definition at line 692 of file recipe.cpp.
References buf.
Referenced by init_formulae(), and strtoint().
|
static |
Try to find an ingredient with specified name.
If several archetypes have the same name, the value of the first one with that name will be returned. This happens for the mushrooms (mushroom_1, mushroom_2 and mushroom_3). For the monsters' body parts, there may be several monsters with the same name. This is not a problem if these monsters have the same level (e.g. sage & c_sage) or if only one of the monsters generates the body parts that we are looking for (e.g. big_dragon and big_dragon_worthless).
Will also search in artifacts.
name | ingredient we're searching for. Can start with a number. |
Definition at line 475 of file recipe.cpp.
References AssetsManager::archetypes(), archetype::clone, AssetsCollection< T, Key >::each(), is_valid_types_gen::found, getManager(), give::name, object::name, strcasecmp(), object::title, and autojail::value.
Referenced by dump_alchemy_costs().
Return the best face associated with a recipe.
rp | recipe to get the face of. |
Definition at line 922 of file recipe.cpp.
References archininventory::arch, recipe::arch_name, recipe::arch_names, arch_to_object(), blank_face, FREE_OBJ_FREE_INVENTORY, FREE_OBJ_NO_DESTROY_CALLBACK, give_artifact_abilities(), artifact::item, say::item, locate_recipe_artifact(), object_free(), object_give_identified_properties(), recipe::title, and try_find_archetype().
Referenced by RecipeWrapper::displayIcon(), and knowledge_alchemy_face().
int strtoint | ( | const char * | buf | ) |
Convert buf into an integer equal to the coadded sum of the (lowercase) character
ASCII values in buf (times prepended integers).
buf | buffer we want to convert. Can contain an initial number. |
Definition at line 711 of file recipe.cpp.
References buf, ingred_name(), numb_ingred(), and tolower.
Referenced by add_book_to_list(), content_recipe_value(), dump_alchemy(), find_title(), and init_formulae().
|
static |
Pointer to first recipelist.
Definition at line 50 of file recipe.cpp.
Referenced by check_formulae(), check_recipes(), dump_alchemy(), dump_alchemy_costs(), find_recipe_for_tool(), free_all_recipes(), get_formulalist(), and init_formulae().