Go to the documentation of this file.
43 int omin, diff, luck, base, ran;
47 base = (diff > 2) ? 20 : 50;
49 if (
max < 1 || diff < 1) {
57 return((ran%diff)+min);
59 luck =
op->stats.luck;
60 if (
RANDOM()%base < (
unsigned int)
MIN(10, abs(luck))) {
62 ((luck > 0) ? (luck = 1) : (luck = -1));
66 ((goodbad) ? (min += luck) : (diff));
68 return(
MAX(omin,
MIN(
max, (ran%diff)+min)));
70 return((ran%diff)+min);
78 int64_t omin, diff, ran;
84 base = (diff > 2) ? 20 : 50;
86 if (
max < 1 || diff < 1) {
99 return((ran%diff)+min);
101 luck =
op->stats.luck;
104 ((luck > 0) ? (luck = 1) : (luck = -1));
108 ((goodbad) ? (min += luck) : (diff));
110 return (
MAX(omin,
MIN(
max, (ran%diff)+min)));
112 return ((ran%diff)+min);
122 int die_roll(
int num,
int size,
const object *
op,
int goodbad) {
123 int min, diff, luck,
total, i, gotlucky, base, ran;
127 luck =
total = gotlucky = 0;
128 base = (diff > 2) ? 20 : 50;
129 if (size < 2 || diff < 1) {
130 LOG(
llevError,
"Calling die_roll with num=%d size=%d\n", num, size);
135 luck =
op->stats.luck;
137 for (i = 0; i < num; i++) {
138 if (
RANDOM()%base < (
unsigned int)
MIN(10, abs(luck)) && !gotlucky) {
141 ((luck > 0) ? (luck = 1) : (luck = -1));
145 ((goodbad) ? (min += luck) : (diff));
166 if (
max < 1 || diff < 1)
169 return (
RANDOM()%diff+min);
200 if (
op->stats.dam < 0)
208 if (
op->stats.ac < 0)
210 }
else if (
op->type ==
FOOD) {
211 op->stats.food -=
rndm(5, 20);
212 if (
op->stats.food < 0)
235 if (destroy &&
rndm(0, 1)) {
271 if (
op->materialname == NULL)
283 LOG(
llevError,
"archetype '%s>%s' uses nonexistent material '%s'\n",
op->arch->name,
op->name,
op->materialname);
288 if (
op->resist[j] == 0 && change->
resist[j] != 0) {
289 op->resist[j] += mt->
mod[j];
290 if (
op->resist[j] > 100)
292 if (
op->resist[j] < -100)
293 op->resist[j] = -100;
304 if (
op->materialname != NULL)
319 #define EOL_SIZE (sizeof("\n")-1)
325 if (strlen(
buf) <
sizeof(
"\n")) {
337 void replace(
const char *src,
const char *
key,
const char *replacement,
char *
result,
size_t resultsize) {
342 if (strcmp(
key, replacement) == 0) {
347 keylen = strlen(
key);
350 while (*src !=
'\0' && resultlen+1 < resultsize) {
351 if (strncmp(src,
key, keylen) == 0) {
352 snprintf(
result+resultlen, resultsize-resultlen,
"%s", replacement);
353 resultlen += strlen(
result+resultlen);
356 result[resultlen++] = *src++;
381 if (!input || strlen(input) >
MAX_BUF-5)
387 for (i = strlen(
tmp); i >= 0 && !isalnum(
tmp[i]); i--) {
392 p = strrchr(
tmp,
',');
397 strcat(input,
" and");
440 if (1 <= diff && diff <= 3)
442 else if (5 <= diff && diff <= 7)
444 else if (
rndm(0, 1) == 0)
460 for (p =
buf; *p !=
'\0'; p++) {
497 while (pos < array_size) {
499 while (*p !=
'\0' && *p != sep)
501 if (pos >= array_size)
581 const char *fatalmsgs[] = {
582 "Failed to allocate memory",
583 "Failed repeatedly to load maps",
584 "Hashtable for archetypes is too small",
585 "Fatal issue in archetype file",
593 fprintf(
logfile,
"Fatal error: %s\n", fatalmsgs[err]);
596 fprintf(
logfile,
"Exiting...\n");
sstring add_string(const char *str)
void object_remove(object *op)
StringBuffer * stringbuffer_new(void)
int adjust_dir(int dir, int destination_dir)
void emergency_save(int flag)
#define FLAG_OVERLAY_FLOOR
#define QUERY_FLAG(xyz, p)
void decay_objects(mapstruct *m)
#define FLAG_OBJ_ORIGINAL
void set_materialname(object *op)
EXTERN materialtype_t * materialt
void make_list_like(char *input)
int64_t random_roll64(int64_t min, int64_t max, const object *op, int goodbad)
static event_registration m
materialtype_t * name_to_material(const char *name)
void strip_endline(char *buf)
int get_randomized_dir(int dir)
struct _materialtype * next
void fatal(enum fatal_error err)
void stringbuffer_append_string(StringBuffer *sb, const char *str)
void transmute_materialname(object *op, const object *change)
struct linked_char * next
int rndm(int min, int max)
void replace_unprintable_chars(char *buf)
StringBuffer * describe_spellpath_attenuation(const char *attenuation, int value, StringBuffer *buf)
void free_charlinks(linked_char *lc)
size_t strlcpy(char *dst, const char *src, size_t size)
size_t split_string(char *str, char *array[], size_t array_size, char sep)
int random_roll(int min, int max, const object *op, int goodbad)
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
const char *const attacks[NROFATTACKS]
int die_roll(int num, int size, const object *op, int goodbad)
const char *const spellpathnames[NRSPELLPATHS]
void clean_tmp_files(void)
void LOG(LogLevel logLevel, const char *format,...)
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
void replace(const char *src, const char *key, const char *replacement, char *result, size_t resultsize)
StringBuffer * describe_attacktype(const char *attack, int value, StringBuffer *buf)
void object_free_drop_inventory(object *ob)
const char * destination_dir
int16_t resist[NROFATTACKS]