Crossfire Server, Branches 1.12  R18729
utils.c File Reference
#include <stdlib.h>
#include <global.h>
+ Include dependency graph for utils.c:

Go to the source code of this file.

Macros

#define EOL_SIZE   (sizeof("\n")-1)
 

Functions

void decay_objects (mapstruct *m)
 
int die_roll (int num, int size, const object *op, int goodbad)
 
void make_list_like (char *input)
 
materialtype_tname_to_material (const char *name)
 
int random_roll (int min, int max, const object *op, int goodbad)
 
sint64 random_roll64 (sint64 min, sint64 max, const object *op, int goodbad)
 
void replace (const char *src, const char *key, const char *replacement, char *result, size_t resultsize)
 
void replace_unprintable_chars (char *buf)
 
int rndm (int min, int max)
 
void set_materialname (object *op, int difficulty, materialtype_t *nmt)
 
void strip_endline (char *buf)
 
void strip_media_tag (char *message)
 
const char * strrstr (const char *haystack, const char *needle)
 
void transmute_materialname (object *op, const object *change)
 

Detailed Description

General convenience functions for crossfire.

The random functions here take luck into account when rolling random dice or numbers. This function has less of an impact the larger the difference becomes in the random numbers. IE, the effect is lessened on a 1-1000 roll, vs a 1-6 roll. This can be used by crafty programmers, to specifically disable luck in certain rolls, simply by making the numbers larger (ie, 1d1000 > 500 vs 1d6 > 3)

Definition in file utils.c.

Macro Definition Documentation

#define EOL_SIZE   (sizeof("\n")-1)

Definition at line 426 of file utils.c.

Referenced by strip_endline().

Function Documentation

void decay_objects ( mapstruct m)

Decay and destroy persihable items in a map

Definition at line 187 of file utils.c.

References obj::above, liv::ac, CLOAK, liv::dam, FLAG_IS_FLOOR, FLAG_OBJ_ORIGINAL, FLAG_OVERLAY_FLOOR, FLAG_UNIQUE, FLAG_UNPAID, liv::food, FOOD, free_object(), GET_MAP_OB, GIRDLE, GLOVES, obj::head, IS_ARMOR, IS_LIVE, IS_SHIELD, IS_WEAPON, M_ADAMANT, M_BONE, M_CLOTH, M_GLASS, M_ICE, M_IRON, M_LEATHER, M_LIQUID, M_ORGANIC, M_PAPER, M_SOFT_METAL, M_STONE, M_WOOD, MAP_HEIGHT, MAP_WIDTH, obj::material, QUERY_FLAG, remove_ob(), rndm(), obj::stats, obj::type, and mapdef::unique.

Referenced by ready_map_name().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int die_roll ( int  num,
int  size,
const object op,
int  goodbad 
)

Roll a number of dice (2d3, 4d6). Uses op to determine luck, If goodbad is non-zero, luck increases the roll, if zero, it decreases. Generally, op should be the player/caster/hitter requesting the roll, not the recipient (ie, the poor slob getting hit). The args are num D size (ie 4d6) [garbled 20010916]

Definition at line 134 of file utils.c.

References llevError, LOG(), liv::luck, MAX, MIN, PLAYER, obj::stats, and obj::type.

Referenced by attempt_hide(), attempt_pick_lock(), attempt_steal(), do_skill_ident2(), fire_swarm(), pick_arrow_target(), player_lvl_adj(), scroll_type_apply(), spellbook_type_apply(), and summon_object().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void make_list_like ( char *  input)

Taking a string as an argument, mutate it into a string that looks like a list.

A 'list' for the purposes here is a string of items, seperated by commas, except for the last entry, which has an 'and' before it, and a full stop (period) after it.

This function will also strip all trailing non alphanumeric characters.

It does not insert an oxford comma.

Parameters
inputstring to transform. Will be overwritten. Must be long enough to contain the modified string.
Todo:
use safe string functions.

Definition at line 485 of file utils.c.

References MAX_BUF.

Referenced by can_pay(), and describe_shop().

+ Here is the caller graph for this function:

materialtype_t* name_to_material ( const char *  name)

Convert materialname to materialtype_t

Todo:
why use a break?

Definition at line 262 of file utils.c.

References materialt, _materialtype::name, and _materialtype::next.

Referenced by animate_weapon(), did_make_save_item(), query_base_name(), query_name(), and transmute_materialname().

+ Here is the caller graph for this function:

int random_roll ( int  min,
int  max,
const object op,
int  goodbad 
)

Roll a random number between min and max. Uses op to determine luck, and if goodbad is non-zero, luck increases the roll, if zero, it decreases.

Generally, op should be the player/caster/hitter requesting the roll, not the recipient (ie, the poor slob getting hit). [garbled 20010916]

Definition at line 51 of file utils.c.

References llevError, LOG(), liv::luck, MAX, MIN, PLAYER, obj::stats, and obj::type.

Referenced by alchemy_failure_effect(), apply_special(), attack_ob_simple(), attempt_do_alchemy(), attempt_steal(), become_follower(), cast_detection(), cast_heal(), cast_smite_spell(), cast_spell(), charge_mana_effect(), cure_disease(), deathstrike_living(), did_make_save(), do_harvest(), do_hidden_move(), do_symptoms(), flee_player(), gate_type_process(), god_examines_priest(), god_intervention(), hit_with_one_attacktype(), infect_object(), kill_player(), learn_skill(), mood_change(), potion_type_apply(), pray_at_altar(), push_ob(), recharge(), roll_ob(), scroll_failure(), singing(), spellbook_type_apply(), summon_object(), trap_disarm(), trap_see(), use_oratory(), and write_scroll().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

sint64 random_roll64 ( sint64  min,
sint64  max,
const object op,
int  goodbad 
)

This is a 64 bit version of random_roll() above. This is needed for exp loss calculations for players changing religions.

Definition at line 86 of file utils.c.

References llevError, LOG(), liv::luck, MAX, MIN, PLAYER, obj::stats, and obj::type.

Referenced by pray_at_altar().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void replace ( const char *  src,
const char *  key,
const char *  replacement,
char *  result,
size_t  resultsize 
)

Replace in string src all occurrences of key by replacement. The resulting string is put into result; at most resultsize characters (including the terminating null character) will be written to result.

Definition at line 444 of file utils.c.

References snprintf().

Referenced by compilePython(), enter_fixed_template_map(), and enter_random_template_map().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void replace_unprintable_chars ( char *  buf)

Replaces any unprintable character in the given buffer with a space.

Parameters
bufthe buffer to modify

Definition at line 516 of file utils.c.

Referenced by command_party(), command_title(), and form_party().

+ Here is the caller graph for this function:

void strip_endline ( char *  buf)

Removes endline from buffer (modified in place).

Definition at line 431 of file utils.c.

References EOL_SIZE.

Referenced by parse_shop_string(), and send_news().

+ Here is the caller graph for this function:

void strip_media_tag ( char *  message)

Strip out the media tags from a String. Warning the input string will contain the result string

Definition at line 388 of file utils.c.

Referenced by draw_ext_info().

+ Here is the caller graph for this function:

const char* strrstr ( const char *  haystack,
const char *  needle 
)

Finds a string in a string.

Todo:
isn't there another function (porting.c?) for that?

Definition at line 414 of file utils.c.

void transmute_materialname ( object op,
const object change 
)

When doing transmutation of objects, we have to recheck the resistances, as some that did not apply previously, may apply now.

Only works on armors.

Definition at line 281 of file utils.c.

References obj::arch, CLOAK, GIRDLE, GLOVES, IS_ARMOR, IS_SHIELD, llevError, LOG(), obj::materialname, _materialtype::mod, obj::name, archt::name, name_to_material(), NROFATTACKS, obj::resist, and obj::type.

Referenced by cfapi_object_transmute(), and make_item_from_recipe().

+ Here is the call graph for this function:

+ Here is the caller graph for this function: