Crossfire Server, Branches 1.12
R18729
|
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_t * | name_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) |
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.
#define EOL_SIZE (sizeof("\n")-1) |
Definition at line 426 of file utils.c.
Referenced by strip_endline().
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().
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().
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.
input | string to transform. Will be overwritten. Must be long enough to contain the modified string. |
Definition at line 485 of file utils.c.
References MAX_BUF.
Referenced by can_pay(), and describe_shop().
materialtype_t* name_to_material | ( | const char * | name | ) |
Convert materialname to materialtype_t
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().
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().
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().
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().
void replace_unprintable_chars | ( | char * | buf | ) |
Replaces any unprintable character in the given buffer with a space.
buf | the buffer to modify |
Definition at line 516 of file utils.c.
Referenced by command_party(), command_title(), and form_party().
int rndm | ( | int | min, |
int | max | ||
) |
Returns a number between min and max.
It is suggested one use these functions rather than RANDOM()%, as it would appear that a number of off-by-one-errors exist due to improper use of %. This should also prevent SIGFPE.
Definition at line 174 of file utils.c.
Referenced by adjust_product(), alchemy_failure_effect(), alchemy_object(), apply_changes_to_player(), attack_message(), attack_ob_simple(), cancellation(), cast_change_ability(), cast_spell(), cast_wonder(), cauldron_sound(), check_spell_knockback(), choose_cult_monster(), command_cointoss(), common_process_projectile(), common_trap_type_process(), convert_item(), counterspell(), decay_objects(), deep_swamp_type_process(), determine_god(), determine_holy_arch(), did_make_save_item(), do_harvest(), do_skill_ident2(), find_recipe(), fix_generated_item(), fix_stopped_arrow(), forklightning(), generate_monster(), generate_monster_arch(), generate_monster_inv(), hit_player(), hit_with_one_attacktype(), level_for_item(), move_ball_spell(), move_bolt(), move_creator(), move_firewall(), move_player_mover(), move_swarm_spell(), peacemaker_type_process(), pet_move(), polymorph(), polymorph_item(), polymorph_living(), reflwall(), resurrection_fails(), save_throw_object(), scroll_type_apply(), set_materialname(), shuffle_attack(), spell_find_dir(), spellbook_type_apply(), swap_random_stats(), transmute_item_to_flower(), and trap_adjust().
void set_materialname | ( | object * | op, |
int | difficulty, | ||
materialtype_t * | nmt | ||
) |
Set the materialname and type for an item
Definition at line 314 of file utils.c.
References _materialtype::ac, liv::ac, add_string(), BOW, _materialtype::chance, CLOAK, liv::dam, _materialtype::damage, _materialtype::difficulty, GIRDLE, GLOVES, IS_ARMOR, IS_SHIELD, IS_WEAPON, _materialtype::magic, obj::magic, _materialtype::material, obj::material, obj::materialname, materialt, _materialtype::mod, _materialtype::name, _materialtype::next, NROFATTACKS, obj::resist, rndm(), _materialtype::sp, liv::sp, obj::stats, obj::type, _materialtype::value, obj::value, _materialtype::wc, liv::wc, _materialtype::weight, and obj::weight.
Referenced by fix_generated_item(), and local_check_loaded_object().
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().
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().
const char* strrstr | ( | const char * | haystack, |
const char * | needle | ||
) |
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().