51 int random_roll(
int min,
int max,
const object *op,
int goodbad) {
52 int omin, diff, luck, base, ran;
56 ((diff > 2) ? (base = 20) : (base = 50));
58 if (max < 1 || diff < 1) {
59 LOG(
llevError,
"Calling random_roll with min=%d max=%d\n", min, max);
66 return((ran%diff)+min);
69 if (RANDOM()%base <
MIN(10, abs(luck))) {
71 ((luck > 0) ? (luck = 1) : (luck = -1));
75 ((goodbad) ? (min += luck) : (diff));
77 return(
MAX(omin,
MIN(max, (ran%diff)+min)));
79 return((ran%diff)+min);
86 sint64
random_roll64(sint64 min, sint64 max,
const object *op,
int goodbad) {
87 sint64 omin, diff, luck, ran;
92 ((diff > 2) ? (base = 20) : (base = 50));
94 if (max < 1 || diff < 1) {
96 LOG(
llevError,
"Calling random_roll with min=%lld max=%lld\n", min, max);
98 LOG(
llevError,
"Calling random_roll with min=%I64d max=%I64d\n", min, max);
108 ran = (RANDOM()&0xffffffff)|((sint64)RANDOM()<<32);
111 return((ran%diff)+min);
114 if (RANDOM()%base <
MIN(10, abs(luck))) {
116 ((luck > 0) ? (luck = 1) : (luck = -1));
120 ((goodbad) ? (min += luck) : (diff));
122 return (
MAX(omin,
MIN(max, (ran%diff)+min)));
124 return ((ran%diff)+min);
134 int die_roll(
int num,
int size,
const object *op,
int goodbad) {
135 int min, diff, luck, total, i, gotlucky, base, ran;
139 luck = total = gotlucky = 0;
140 ((diff > 2) ? (base = 20) : (base = 50));
141 if (size < 2 || diff < 1) {
142 LOG(
llevError,
"Calling die_roll with num=%d size=%d\n", num, size);
149 for (i = 0; i < num; i++) {
150 if (RANDOM()%base <
MIN(10, abs(luck)) && !gotlucky) {
153 ((luck > 0) ? (luck = 1) : (luck = -1));
157 ((goodbad) ? (min += luck) : (diff));
159 total +=
MAX(1,
MIN(size, (ran%diff)+min));
161 total += RANDOM()%size+1;
178 if (max < 1 || diff < 1)
181 return (RANDOM()%diff+min);
196 for (op =
GET_MAP_OB(m, x, y); op; op = otmp) {
249 if (destroy &&
rndm(0, 1)) {
267 if (strcmp(name, nmt->
name) == 0) {
322 #ifndef NEW_MATERIAL_CODE
346 #ifndef NEW_MATERIAL_CODE
392 src = dest = message;
394 while (*src !=
'\0') {
397 }
else if (in_tag && (*src ==
']'))
414 const char *
strrstr(
const char *haystack,
const char *needle) {
415 const char *lastneedle;
418 while ((haystack = strstr(haystack, needle)) != NULL) {
419 lastneedle = haystack;
426 #define EOL_SIZE (sizeof("\n")-1)
432 if (strlen(buf) <
sizeof(
"\n")) {
435 if (!strcmp(buf+strlen(buf)-
EOL_SIZE,
"\n"))
444 void replace(
const char *src,
const char *key,
const char *replacement,
char *result,
size_t resultsize) {
449 if (strcmp(key, replacement) == 0) {
450 snprintf(result, resultsize,
"%s", src);
454 keylen = strlen(key);
457 while (*src !=
'\0' && resultlen+1 < resultsize) {
458 if (strncmp(src, key, keylen) == 0) {
459 snprintf(result+resultlen, resultsize-resultlen,
"%s", replacement);
460 resultlen += strlen(result+resultlen);
463 result[resultlen++] = *src++;
466 result[resultlen] =
'\0';
488 if (!input || strlen(input) >
MAX_BUF-5)
492 strncpy(tmp, input,
MAX_BUF-5);
494 for (i = strlen(tmp); !isalnum(tmp[i]) && i >= 0; i--)
498 p = strrchr(tmp,
',');
503 strcat(input,
" and");
519 for (p = buf; *p !=
'\0'; p++) {
void strip_media_tag(char *message)
const char * strrstr(const char *haystack, const char *needle)
materialtype_t * name_to_material(const char *name)
EXTERN materialtype_t * materialt
void decay_objects(mapstruct *m)
void strip_endline(char *buf)
void transmute_materialname(object *op, const object *change)
void set_materialname(object *op, int difficulty, materialtype_t *nmt)
int rndm(int min, int max)
void make_list_like(char *input)
void remove_ob(object *op)
#define FLAG_OBJ_ORIGINAL
const char * materialname
int die_roll(int num, int size, const object *op, int goodbad)
#define FLAG_OVERLAY_FLOOR
#define QUERY_FLAG(xyz, p)
void replace_unprintable_chars(char *buf)
sint16 resist[NROFATTACKS]
int snprintf(char *dest, int max, const char *format,...)
void replace(const char *src, const char *key, const char *replacement, char *result, size_t resultsize)
sstring add_string(const char *str)
#define GET_MAP_OB(M, X, Y)
void LOG(LogLevel logLevel, const char *format,...)
struct _materialtype * next
void free_object(object *ob)
int random_roll(int min, int max, const object *op, int goodbad)
sint64 random_roll64(sint64 min, sint64 max, const object *op, int goodbad)