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.11 by root, Tue Sep 12 19:20:06 2006 UTC vs.
Revision 1.22 by root, Tue Dec 12 21:39:56 2006 UTC

1
2/*
3 * static char *rcsid_utils_c =
4 * "$Id: utils.C,v 1.11 2006/09/12 19:20:06 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 */
103 diff = max - min + 1; 97 diff = max - min + 1;
104 ((diff > 2) ? (base = 20) : (base = 50)); /* d2 and d3 are corner cases */ 98 ((diff > 2) ? (base = 20) : (base = 50)); /* d2 and d3 are corner cases */
105 99
106 if (max < 1 || diff < 1) 100 if (max < 1 || diff < 1)
107 { 101 {
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); 102 LOG (llevError, "Calling random_roll with min=%" PRId64 " max=%" PRId64 "\n", min, max);
112#endif
113 return (min); /* avoids a float exception */ 103 return (min); /* avoids a float exception */
114 } 104 }
115 105
116 /* Don't know of a portable call to get 64 bit random values. 106 /* 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 107 * So make a call to get two 32 bit random numbers, and just to
206} 196}
207 197
208/* decay and destroy persihable items in a map */ 198/* decay and destroy persihable items in a map */
209 199
210void 200void
211decay_objects (mapstruct *m) 201decay_objects (maptile *m)
212{ 202{
213 int x, y, destroy; 203 int x, y, destroy;
214 object *op, *otmp; 204 object *op, *otmp;
215 205
216 if (m->unique) 206 if (m->unique)
264 if (op->material & M_ICE && MAP_TEMP (m) > 32) 254 if (op->material & M_ICE && MAP_TEMP (m) > 32)
265 destroy = 1; 255 destroy = 1;
266 } 256 }
267 /* adjust overall chance below */ 257 /* adjust overall chance below */
268 if (destroy && rndm (0, 1)) 258 if (destroy && rndm (0, 1))
269 { 259 op->destroy ();
270 remove_ob (op);
271 free_object (op);
272 }
273 } 260 }
274} 261}
275 262
276/* convert materialname to materialtype_t */ 263/* convert materialname to materialtype_t */
277 264
549 strcpy (input, tmp); 536 strcpy (input, tmp);
550 537
551 return; 538 return;
552} 539}
553 540
554void * 541/////////////////////////////////////////////////////////////////////////////
555zero_initialised::operator new (size_t s, void *p) 542
543#if 0
544refcounted *refcounted::rc_first;
545
546refcounted::refcounted ()
556{ 547{
557 memset (p, 0, s); 548 refcnt = 0;
549 rc_next = rc_first;
550 rc_first = this;
551}
552
553refcounted::~refcounted ()
554{
555 assert (!rc_next);
556 assert (!refcnt);
557}
558#endif
559
560void *alloc (int s) throw (std::bad_alloc)
561{
562 void *p = g_slice_alloc (s);
563
564 if (!p)
565 throw std::bad_alloc ();
566
558 return p; 567 return p;
559}
560
561void *
562zero_initialised::operator new (size_t s)
563{
564 //return calloc (1, s);
565 return g_slice_alloc0 (s);
566}
567
568void *
569 zero_initialised::operator new[] (size_t s)
570{
571 //return calloc (1, s);
572 return g_slice_alloc0 (s);
573}
574
575void
576zero_initialised::operator delete (void *p, size_t s)
577{
578 //free (p); return;
579 g_slice_free1 (s, p);
580}
581
582void
583zero_initialised::operator delete[] (void *p, size_t s)
584{
585 //free (p); return;
586 g_slice_free1 (s, p);
587} 568}
588 569
589void assign (char *dst, const char *src, int maxlen) 570void assign (char *dst, const char *src, int maxlen)
590{ 571{
591 if (!src) 572 if (!src)
608 } 589 }
609 else 590 else
610 memcpy (dst, src, len + 1); 591 memcpy (dst, src, len + 1);
611} 592}
612 593
594

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines