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.22 by root, Tue Dec 12 21:39:56 2006 UTC vs.
Revision 1.29 by root, Mon Dec 25 11:25:49 2006 UTC

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
206 if (m->unique) 208 if (m->unique)
207 return; 209 return;
208 210
209 for (x = 0; x < MAP_WIDTH (m); x++) 211 for (x = 0; x < MAP_WIDTH (m); x++)
210 for (y = 0; y < MAP_HEIGHT (m); y++) 212 for (y = 0; y < MAP_HEIGHT (m); y++)
211 for (op = get_map_ob (m, x, y); op; op = otmp) 213 for (op = GET_MAP_OB (m, x, y); op; op = otmp)
212 { 214 {
213 destroy = 0; 215 destroy = 0;
214 otmp = op->above; 216 otmp = op->above;
215 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 217 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
216 break; 218 break;
217 if (QUERY_FLAG (op, FLAG_IS_FLOOR) || 219 if (QUERY_FLAG (op, FLAG_IS_FLOOR)
218 QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) || 220 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL)
219 QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) || 221 || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL)
220 QUERY_FLAG (op, FLAG_UNIQUE) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) || QUERY_FLAG (op, FLAG_UNPAID) || IS_LIVE (op)) 222 || QUERY_FLAG (op, FLAG_UNIQUE)
223 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)
224 || QUERY_FLAG (op, FLAG_UNPAID)
225 || op->is_alive ())
221 continue; 226 continue;
227
222 /* otherwise, we decay and destroy */ 228 /* otherwise, we decay and destroy */
223 if (IS_WEAPON (op)) 229 if (op->is_weapon ())
224 { 230 {
225 op->stats.dam--; 231 op->stats.dam--;
226 if (op->stats.dam < 0) 232 if (op->stats.dam < 0)
227 destroy = 1; 233 destroy = 1;
228 } 234 }
229 else if (IS_ARMOR (op)) 235 else if (op->is_armor ())
230 { 236 {
231 op->stats.ac--; 237 op->stats.ac--;
232 if (op->stats.ac < 0) 238 if (op->stats.ac < 0)
233 destroy = 1; 239 destroy = 1;
234 } 240 }
293 return; 299 return;
294 300
295 if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) 301 if (change->materialname != NULL && strcmp (op->materialname, change->materialname))
296 return; 302 return;
297 303
298 if (!IS_ARMOR (op)) 304 if (!op->is_armor ())
299 return; 305 return;
300 306
301 mt = name_to_material (op->materialname); 307 mt = name_to_material (op->materialname);
302 if (!mt) 308 if (!mt)
303 { 309 {
349 { 355 {
350 if (op->material & mt->material && rndm (1, 100) <= mt->chance && 356 if (op->material & mt->material && rndm (1, 100) <= mt->chance &&
351 difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) 357 difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0))
352 { 358 {
353 lmt = mt; 359 lmt = mt;
354 if (!(IS_WEAPON (op) || IS_ARMOR (op))) 360 if (!(op->is_weapon () || op->is_armor ()))
355 break; 361 break;
356 } 362 }
357 } 363 }
358#endif 364#endif
359 } 365 }
367#ifndef NEW_MATERIAL_CODE 373#ifndef NEW_MATERIAL_CODE
368 op->materialname = lmt->name; 374 op->materialname = lmt->name;
369 return; 375 return;
370#else 376#else
371 377
372 if (op->stats.dam && IS_WEAPON (op)) 378 if (op->stats.dam && op->is_weapon ())
373 { 379 {
374 op->stats.dam += lmt->damage; 380 op->stats.dam += lmt->damage;
375 if (op->stats.dam < 1) 381 if (op->stats.dam < 1)
376 op->stats.dam = 1; 382 op->stats.dam = 1;
377 } 383 }
378 if (op->stats.sp && op->type == BOW) 384 if (op->stats.sp && op->type == BOW)
379 op->stats.sp += lmt->sp; 385 op->stats.sp += lmt->sp;
380 if (op->stats.wc && IS_WEAPON (op)) 386 if (op->stats.wc && op->is_weapon ())
381 op->stats.wc += lmt->wc; 387 op->stats.wc += lmt->wc;
382 if (IS_ARMOR (op)) 388 if (op->is_armor ())
383 { 389 {
384 if (op->stats.ac) 390 if (op->stats.ac)
385 op->stats.ac += lmt->ac; 391 op->stats.ac += lmt->ac;
386 for (j = 0; j < NROFATTACKS; j++) 392 for (j = 0; j < NROFATTACKS; j++)
387 if (op->resist[j] != 0) 393 if (op->resist[j] != 0)
393 op->resist[j] = -100; 399 op->resist[j] = -100;
394 } 400 }
395 } 401 }
396 op->materialname = add_string (lmt->name); 402 op->materialname = add_string (lmt->name);
397 /* dont make it unstackable if it doesn't need to be */ 403 /* dont make it unstackable if it doesn't need to be */
398 if (IS_WEAPON (op) || IS_ARMOR (op)) 404 if (op->is_weapon () || op->is_armor ())
399 { 405 {
400 op->weight = (op->weight * lmt->weight) / 100; 406 op->weight = (op->weight * lmt->weight) / 100;
401 op->value = (op->value * lmt->value) / 100; 407 op->value = (op->value * lmt->value) / 100;
402 } 408 }
403#endif 409#endif
538 return; 544 return;
539} 545}
540 546
541///////////////////////////////////////////////////////////////////////////// 547/////////////////////////////////////////////////////////////////////////////
542 548
543#if 0
544refcounted *refcounted::rc_first;
545
546refcounted::refcounted ()
547{
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) 549void *salloc_ (int n) throw (std::bad_alloc)
561{ 550{
562 void *p = g_slice_alloc (s); 551 void *ptr = g_slice_alloc (n);
563 552
564 if (!p) 553 if (!ptr)
565 throw std::bad_alloc (); 554 throw std::bad_alloc ();
566 555
567 return p; 556 return ptr;
557}
558
559void *salloc_ (int n, void *src) throw (std::bad_alloc)
560{
561 void *ptr = salloc_ (n);
562
563 if (src)
564 memcpy (ptr, src, n);
565 else
566 memset (ptr, 0, n);
567
568 return ptr;
568} 569}
569 570
570void assign (char *dst, const char *src, int maxlen) 571void assign (char *dst, const char *src, int maxlen)
571{ 572{
572 if (!src) 573 if (!src)
589 } 590 }
590 else 591 else
591 memcpy (dst, src, len + 1); 592 memcpy (dst, src, len + 1);
592} 593}
593 594
595tstamp now ()
596{
597 struct timeval tv;
594 598
599 gettimeofday (&tv, 0);
600 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6);
601}
602

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines