… | |
… | |
27 | |
27 | |
28 | #include <global.h> |
28 | #include <global.h> |
29 | #include <funcpoint.h> |
29 | #include <funcpoint.h> |
30 | #include <material.h> |
30 | #include <material.h> |
31 | |
31 | |
|
|
32 | #include <sys/time.h> |
|
|
33 | #include <time.h> |
32 | #include <glib.h> |
34 | #include <glib.h> |
33 | |
35 | |
34 | /* |
36 | /* |
35 | * The random functions here take luck into account when rolling random |
37 | * The random functions here take luck into account when rolling random |
36 | * dice or numbers. This function has less of an impact the larger the |
38 | * dice or numbers. This function has less of an impact the larger the |
… | |
… | |
97 | diff = max - min + 1; |
99 | diff = max - min + 1; |
98 | ((diff > 2) ? (base = 20) : (base = 50)); /* d2 and d3 are corner cases */ |
100 | ((diff > 2) ? (base = 20) : (base = 50)); /* d2 and d3 are corner cases */ |
99 | |
101 | |
100 | if (max < 1 || diff < 1) |
102 | if (max < 1 || diff < 1) |
101 | { |
103 | { |
102 | LOG (llevError, "Calling random_roll with min=%lld max=%lld\n", min, max); |
104 | LOG (llevError, "Calling random_roll with min=%" PRId64 " max=%" PRId64 "\n", min, max); |
103 | return (min); /* avoids a float exception */ |
105 | return (min); /* avoids a float exception */ |
104 | } |
106 | } |
105 | |
107 | |
106 | /* Don't know of a portable call to get 64 bit random values. |
108 | /* Don't know of a portable call to get 64 bit random values. |
107 | * So make a call to get two 32 bit random numbers, and just to |
109 | * So make a call to get two 32 bit random numbers, and just to |
… | |
… | |
254 | if (op->material & M_ICE && MAP_TEMP (m) > 32) |
256 | if (op->material & M_ICE && MAP_TEMP (m) > 32) |
255 | destroy = 1; |
257 | destroy = 1; |
256 | } |
258 | } |
257 | /* adjust overall chance below */ |
259 | /* adjust overall chance below */ |
258 | if (destroy && rndm (0, 1)) |
260 | if (destroy && rndm (0, 1)) |
259 | { |
261 | op->destroy (); |
260 | remove_ob (op); |
|
|
261 | free_object (op); |
|
|
262 | } |
|
|
263 | } |
262 | } |
264 | } |
263 | } |
265 | |
264 | |
266 | /* convert materialname to materialtype_t */ |
265 | /* convert materialname to materialtype_t */ |
267 | |
266 | |
… | |
… | |
558 | assert (!rc_next); |
557 | assert (!rc_next); |
559 | assert (!refcnt); |
558 | assert (!refcnt); |
560 | } |
559 | } |
561 | #endif |
560 | #endif |
562 | |
561 | |
563 | void *alloc (int s) throw (std::bad_alloc) |
562 | void *salloc_ (int n) throw (std::bad_alloc) |
564 | { |
563 | { |
565 | void *p = g_slice_alloc (s); |
564 | void *ptr = g_slice_alloc (n); |
566 | |
565 | |
567 | if (!p) |
566 | if (!ptr) |
568 | throw std::bad_alloc (); |
567 | throw std::bad_alloc (); |
569 | |
568 | |
570 | return p; |
569 | return ptr; |
|
|
570 | } |
|
|
571 | |
|
|
572 | void *salloc_ (int n, void *src) throw (std::bad_alloc) |
|
|
573 | { |
|
|
574 | void *ptr = salloc_ (n); |
|
|
575 | |
|
|
576 | if (src) |
|
|
577 | memcpy (ptr, src, n); |
|
|
578 | else |
|
|
579 | memset (ptr, 0, n); |
|
|
580 | |
|
|
581 | return ptr; |
571 | } |
582 | } |
572 | |
583 | |
573 | void assign (char *dst, const char *src, int maxlen) |
584 | void assign (char *dst, const char *src, int maxlen) |
574 | { |
585 | { |
575 | if (!src) |
586 | if (!src) |
… | |
… | |
592 | } |
603 | } |
593 | else |
604 | else |
594 | memcpy (dst, src, len + 1); |
605 | memcpy (dst, src, len + 1); |
595 | } |
606 | } |
596 | |
607 | |
|
|
608 | tstamp now () |
|
|
609 | { |
|
|
610 | struct timeval tv; |
597 | |
611 | |
|
|
612 | gettimeofday (&tv, 0); |
|
|
613 | return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); |
|
|
614 | } |
|
|
615 | |