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)) {
250 if (strcmp(
name, material->name) == 0) {
267 if (
op->materialname == NULL)
279 LOG(
llevError,
"archetype '%s>%s' uses nonexistent material '%s'\n",
op->arch->name,
op->name,
op->materialname);
284 if (
op->resist[j] == 0 && change->
resist[j] != 0) {
285 op->resist[j] += mt->
mod[j];
286 if (
op->resist[j] > 100)
288 if (
op->resist[j] < -100)
289 op->resist[j] = -100;
298 if (
op->materialname != NULL)
302 if (
op->material & material->material) {
309 #define EOL_SIZE (sizeof("\n")-1)
315 if (strlen(
buf) <
sizeof(
"\n")) {
327 void replace(
const char *src,
const char *
key,
const char *replacement,
char *
result,
size_t resultsize) {
332 if (strcmp(
key, replacement) == 0) {
337 keylen = strlen(
key);
340 while (*src !=
'\0' && resultlen+1 < resultsize) {
341 if (strncmp(src,
key, keylen) == 0) {
342 snprintf(
result+resultlen, resultsize-resultlen,
"%s", replacement);
343 resultlen += strlen(
result+resultlen);
346 result[resultlen++] = *src++;
371 if (!input || strlen(input) >
MAX_BUF-5)
377 for (i = strlen(
tmp); i >= 0 && !isalnum(
tmp[i]); i--) {
382 p = strrchr(
tmp,
',');
387 strcat(input,
" and");
430 if (1 <= diff && diff <= 3)
432 else if (5 <= diff && diff <= 7)
434 else if (
rndm(0, 1) == 0)
450 for (p =
buf; *p !=
'\0'; p++) {
487 while (pos < array_size) {
489 while (*p !=
'\0' && *p != sep)
491 if (pos >= array_size)
580 return ((sqrt(2) - 1) *
a) +
b;
591 const char *fatalmsgs[] = {
592 "Failed to allocate memory",
593 "Failed repeatedly to load maps",
594 "Hashtable for archetypes is too small",
595 "Fatal issue in archetype file",
603 fprintf(
logfile,
"Fatal error: %s\n", fatalmsgs[err]);
606 fprintf(
logfile,
"Exiting...\n");
void emergency_save(int flag)
void LOG(LogLevel logLevel, const char *format,...)
#define FLAG_OVERLAY_FLOOR
#define QUERY_FLAG(xyz, p)
const char *const spellpathnames[NRSPELLPATHS]
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
StringBuffer * stringbuffer_new(void)
#define FLAG_OBJ_ORIGINAL
void set_materialname(object *op)
int rndm(int min, int max)
std::vector< materialtype_t * > materials
materialtype_t * name_to_material(const char *name)
int16_t resist[NROFATTACKS]
static event_registration m
void object_free_drop_inventory(object *ob)
int adjust_dir(int dir, int destination_dir)
size_t split_string(char *str, char *array[], size_t array_size, char sep)
StringBuffer * describe_spellpath_attenuation(const char *attenuation, int value, StringBuffer *buf)
sstring add_string(const char *str)
int64_t random_roll64(int64_t min, int64_t max, const object *op, int goodbad)
StringBuffer * describe_attacktype(const char *attack, int value, StringBuffer *buf)
struct linked_char * next
void stringbuffer_append_string(StringBuffer *sb, const char *str)
int random_roll(int min, int max, const object *op, int goodbad)
void replace_unprintable_chars(char *buf)
void fatal(enum fatal_error err)
size_t strlcpy(char *dst, const char *src, size_t size)
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
void replace(const char *src, const char *key, const char *replacement, char *result, size_t resultsize)
void decay_objects(mapstruct *m)
void transmute_materialname(object *op, const object *change)
void clean_tmp_files(void)
const char *const attacks[NROFATTACKS]
int get_randomized_dir(int dir)
void make_list_like(char *input)
void strip_endline(char *buf)
int die_roll(int num, int size, const object *op, int goodbad)
void object_remove(object *op)
void free_charlinks(linked_char *lc)
const char * destination_dir