ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/utils.C
(Generate patch)

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.12 by root, Tue Sep 12 20:55:40 2006 UTC vs.
Revision 1.25 by root, Sun Dec 17 23:10:34 2006 UTC

1
2/*
3 * static char *rcsid_utils_c =
4 * "$Id: utils.C,v 1.12 2006/09/12 20:55:40 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30/* 24/*
31 * General convenience functions for crossfire. 25 * General convenience functions for crossfire.
32 */ 26 */
33 27
34#include <global.h> 28#include <global.h>
35#include <funcpoint.h> 29#include <funcpoint.h>
36#include <material.h> 30#include <material.h>
37 31
32#include <sys/time.h>
33#include <time.h>
38#include <glib.h> 34#include <glib.h>
39 35
40/* 36/*
41 * The random functions here take luck into account when rolling random 37 * The random functions here take luck into account when rolling random
42 * 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
103 diff = max - min + 1; 99 diff = max - min + 1;
104 ((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 */
105 101
106 if (max < 1 || diff < 1) 102 if (max < 1 || diff < 1)
107 { 103 {
108#ifndef WIN32
109 LOG (llevError, "Calling random_roll with min=%lld max=%lld\n", min, max);
110#else
111 LOG (llevError, "Calling random_roll with min=%I64d max=%I64d\n", min, max); 104 LOG (llevError, "Calling random_roll with min=%" PRId64 " max=%" PRId64 "\n", min, max);
112#endif
113 return (min); /* avoids a float exception */ 105 return (min); /* avoids a float exception */
114 } 106 }
115 107
116 /* 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.
117 * 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
206} 198}
207 199
208/* decay and destroy persihable items in a map */ 200/* decay and destroy persihable items in a map */
209 201
210void 202void
211decay_objects (mapstruct *m) 203decay_objects (maptile *m)
212{ 204{
213 int x, y, destroy; 205 int x, y, destroy;
214 object *op, *otmp; 206 object *op, *otmp;
215 207
216 if (m->unique) 208 if (m->unique)
264 if (op->material & M_ICE && MAP_TEMP (m) > 32) 256 if (op->material & M_ICE && MAP_TEMP (m) > 32)
265 destroy = 1; 257 destroy = 1;
266 } 258 }
267 /* adjust overall chance below */ 259 /* adjust overall chance below */
268 if (destroy && rndm (0, 1)) 260 if (destroy && rndm (0, 1))
269 { 261 op->destroy ();
270 remove_ob (op);
271 free_object (op);
272 }
273 } 262 }
274} 263}
275 264
276/* convert materialname to materialtype_t */ 265/* convert materialname to materialtype_t */
277 266
549 strcpy (input, tmp); 538 strcpy (input, tmp);
550 539
551 return; 540 return;
552} 541}
553 542
543/////////////////////////////////////////////////////////////////////////////
544
545#if 0
546refcounted *refcounted::rc_first;
547
548refcounted::refcounted ()
549{
550 refcnt = 0;
551 rc_next = rc_first;
552 rc_first = this;
553}
554
555refcounted::~refcounted ()
556{
557 assert (!rc_next);
558 assert (!refcnt);
559}
560#endif
561
554void *alloc (int s) throw (std::bad_alloc) 562void *salloc_ (int n) throw (std::bad_alloc)
555{ 563{
564 void *ptr = g_slice_alloc (n);
565
566 if (!ptr)
567 throw std::bad_alloc ();
568
569 return ptr;
570}
571
572void *salloc_ (int n, void *src) throw (std::bad_alloc)
573{
574 void *ptr = salloc_ (n);
575
556 if (s) 576 if (src)
557 return g_slice_alloc (s); 577 memcpy (ptr, src, n);
558 else 578 else
579 memset (ptr, 0, n);
580
559 return 0; 581 return ptr;
560}
561
562void dealloc (void *p, int s) throw ()
563{
564 if (s)
565 g_slice_free1 (s, p);
566} 582}
567 583
568void assign (char *dst, const char *src, int maxlen) 584void assign (char *dst, const char *src, int maxlen)
569{ 585{
570 if (!src) 586 if (!src)
587 } 603 }
588 else 604 else
589 memcpy (dst, src, len + 1); 605 memcpy (dst, src, len + 1);
590} 606}
591 607
608tstamp now ()
609{
610 struct timeval tv;
611
612 gettimeofday (&tv, 0);
613 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6);
614}
615

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines