 |
Crossfire Server, Trunk
1.75.0
|
Go to the documentation of this file.
42 int random_roll(
int min,
int max,
const object *op,
int goodbad) {
43 int omin, diff, luck, base, ran;
47 base = (diff > 2) ? 20 : 50;
49 if (max < 1 || diff < 1) {
50 LOG(
llevError,
"Calling random_roll with min=%d max=%d\n", min, max);
57 return((ran%diff)+min);
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);
77 int64_t
random_roll64(int64_t min, int64_t max,
const object *op,
int goodbad) {
78 int64_t omin, diff, ran;
84 base = (diff > 2) ? 20 : 50;
86 if (max < 1 || diff < 1) {
99 return((ran%diff)+min);
102 if (
RANDOM()%base < (
unsigned int)
MIN(10, abs(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);
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));
147 total +=
MAX(1,
MIN(size, (ran%diff)+min));
166 if (max < 1 || diff < 1)
169 return (
RANDOM()%diff+min);
200 if (op->stats.dam < 0)
206 || op->type ==
CLOAK) {
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)
231 if (op->material&
M_ICE &&
rndm(0, 100) > 70)
235 if (destroy &&
rndm(0, 1)) {
250 if (strcmp(
name, material->name) == 0) {
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) {
333 strlcpy(result, src, resultsize);
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++;
349 result[resultlen] =
'\0';
371 if (!input || strlen(input) >
MAX_BUF-5)
375 strncpy(tmp, 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++) {
473 size_t split_string(
char *str,
char *array[],
size_t array_size,
char sep) {
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");
#define M_LEATHER
Leather.
struct Settings settings
Server settings.
#define FOR_MAP_FINISH()
Finishes FOR_MAP_PREPARE().
void emergency_save(int flag)
Save all players.
@ llevError
Error, serious thing.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
#define FLAG_OVERLAY_FLOOR
Object is an overlay floor.
int8_t mod[NROFATTACKS]
Modification to resistances.
#define QUERY_FLAG(xyz, p)
int get_random_dir(void)
Returns a random direction (1..8).
const char *const spellpathnames[NRSPELLPATHS]
Perhaps not the best place for this, but needs to be in some file in the common area so that standalo...
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Append a formatted string to a string buffer instance.
struct archetype * arch
Pointer to archetype.
StringBuffer * stringbuffer_new(void)
Create a new string buffer.
int absdir(int d)
Computes an absolute direction.
#define FLAG_UNIQUE
Item is really unique (UNIQUE_ITEMS)
#define M_ORGANIC
General organic.
#define FLAG_OBJ_ORIGINAL
NEVER SET THIS.
void set_materialname(object *op)
Set the material name and type for an item, if not set.
int rndm(int min, int max)
Returns a number between min and max.
std::vector< materialtype_t * > materials
fatalHook fatal_hook
If not NULL then called when fatal() is called.
materialtype_t * name_to_material(const char *name)
Convert materialname to materialtype_t.
int ihypot(int a, int b)
Rough estimate of hypot(a, b).
int16_t resist[NROFATTACKS]
Resistance adjustments for attacks.
Plugin animator file specs[Config] name
#define FLAG_IS_FLOOR
Can't see what's underneath this object.
static event_registration m
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects,...
int adjust_dir(int dir, int destination_dir)
Adjusts a given direction by +/-1 towards a destination direction.
size_t split_string(char *str, char *array[], size_t array_size, char sep)
Splits a string delimited by passed in sep value into characters into an array of strings.
StringBuffer * describe_spellpath_attenuation(const char *attenuation, int value, StringBuffer *buf)
Describe the specified path attenuation.
sstring add_string(const char *str)
This will add 'str' to the hash table.
int64_t random_roll64(int64_t min, int64_t max, const object *op, int goodbad)
This is a 64 bit version of random_roll() above.
StringBuffer * describe_attacktype(const char *attack, int value, StringBuffer *buf)
Describe the specified attack type.
int isqrt(int n)
Compute the square root.
uint8_t type
PLAYER, BULLET, etc.
sstring materialname
Specific material name.
struct linked_char * next
FILE * logfile
Used by server/daemon.c.
void stringbuffer_append_string(StringBuffer *sb, const char *str)
Append a string to a string buffer instance.
int random_roll(int min, int max, const object *op, int goodbad)
Roll a random number between min and max.
void replace_unprintable_chars(char *buf)
Replaces any unprintable character in the given buffer with a space.
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
#define MAP_WIDTH(m)
Map width.
#define MAX_BUF
Used for all kinds of things.
size_t strlcpy(char *dst, const char *src, size_t size)
Portable implementation of strlcpy(3).
A buffer that will be expanded as content is added to it.
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Constructs a loop iterating over all objects of a map tile.
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.
void decay_objects(mapstruct *m)
Decay and destroy persihable items in a map.
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 p...
void clean_tmp_files(void)
Save unique maps and clean up temporary map files unless recycling temporary maps.
sstring name
The name of the object, obviously...
const char *const attacks[NROFATTACKS]
Attack type names.
#define M_ADAMANT
Adamant.
int get_randomized_dir(int dir)
Returns a random direction (1..8) similar to a given direction.
void make_list_like(char *input)
Taking a string as an argument, mutate it into a string that looks like a list.
#define MAP_HEIGHT(m)
Map height.
void strip_endline(char *buf)
Removes endline from buffer (modified in place).
int die_roll(int num, int size, const object *op, int goodbad)
Roll a number of dice (2d3, 4d6).
#define M_SOFT_METAL
Soft metal.
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to.
void free_charlinks(linked_char *lc)
Frees a link structure and its next items.
Magical Runes Runes are magical inscriptions on the dungeon which cast a spell or detonate when something steps on them Flying objects don t detonate runes Beware ! Runes are invisible most of the time They are only visible occasionally ! There are several runes which are there are some special runes which may only be called with the invoke and people may apply it to read it Maybe useful for mazes ! This rune will not nor is it ordinarily invisible Partial Visibility of they ll be visible only part of the time They have a(your level/2) chance of being visible in any given round
fatal_error
Fatal variables; used as arguments to fatal().
#define FLAG_UNPAID
Object hasn't been paid for yet.
sstring name
More definite name, like "generate_kobold".
const char * destination_dir
Root destination dir.
living stats
Str, Con, Dex, etc.
uint16_t material
What materials this object consist of.
int8_t luck
Affects thaco and ac from time to time.
#define NRSPELLPATHS
Number of spell paths.