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.20 by root, Mon Dec 11 21:32:16 2006 UTC vs.
Revision 1.28 by root, Sat Dec 23 16:05:19 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 }
254 if (op->material & M_ICE && MAP_TEMP (m) > 32) 260 if (op->material & M_ICE && MAP_TEMP (m) > 32)
255 destroy = 1; 261 destroy = 1;
256 } 262 }
257 /* adjust overall chance below */ 263 /* adjust overall chance below */
258 if (destroy && rndm (0, 1)) 264 if (destroy && rndm (0, 1))
259 { 265 op->destroy ();
260 remove_ob (op);
261 free_object (op);
262 }
263 } 266 }
264} 267}
265 268
266/* convert materialname to materialtype_t */ 269/* convert materialname to materialtype_t */
267 270
296 return; 299 return;
297 300
298 if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) 301 if (change->materialname != NULL && strcmp (op->materialname, change->materialname))
299 return; 302 return;
300 303
301 if (!IS_ARMOR (op)) 304 if (!op->is_armor ())
302 return; 305 return;
303 306
304 mt = name_to_material (op->materialname); 307 mt = name_to_material (op->materialname);
305 if (!mt) 308 if (!mt)
306 { 309 {
352 { 355 {
353 if (op->material & mt->material && rndm (1, 100) <= mt->chance && 356 if (op->material & mt->material && rndm (1, 100) <= mt->chance &&
354 difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) 357 difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0))
355 { 358 {
356 lmt = mt; 359 lmt = mt;
357 if (!(IS_WEAPON (op) || IS_ARMOR (op))) 360 if (!(op->is_weapon () || op->is_armor ()))
358 break; 361 break;
359 } 362 }
360 } 363 }
361#endif 364#endif
362 } 365 }
370#ifndef NEW_MATERIAL_CODE 373#ifndef NEW_MATERIAL_CODE
371 op->materialname = lmt->name; 374 op->materialname = lmt->name;
372 return; 375 return;
373#else 376#else
374 377
375 if (op->stats.dam && IS_WEAPON (op)) 378 if (op->stats.dam && op->is_weapon ())
376 { 379 {
377 op->stats.dam += lmt->damage; 380 op->stats.dam += lmt->damage;
378 if (op->stats.dam < 1) 381 if (op->stats.dam < 1)
379 op->stats.dam = 1; 382 op->stats.dam = 1;
380 } 383 }
381 if (op->stats.sp && op->type == BOW) 384 if (op->stats.sp && op->type == BOW)
382 op->stats.sp += lmt->sp; 385 op->stats.sp += lmt->sp;
383 if (op->stats.wc && IS_WEAPON (op)) 386 if (op->stats.wc && op->is_weapon ())
384 op->stats.wc += lmt->wc; 387 op->stats.wc += lmt->wc;
385 if (IS_ARMOR (op)) 388 if (op->is_armor ())
386 { 389 {
387 if (op->stats.ac) 390 if (op->stats.ac)
388 op->stats.ac += lmt->ac; 391 op->stats.ac += lmt->ac;
389 for (j = 0; j < NROFATTACKS; j++) 392 for (j = 0; j < NROFATTACKS; j++)
390 if (op->resist[j] != 0) 393 if (op->resist[j] != 0)
396 op->resist[j] = -100; 399 op->resist[j] = -100;
397 } 400 }
398 } 401 }
399 op->materialname = add_string (lmt->name); 402 op->materialname = add_string (lmt->name);
400 /* dont make it unstackable if it doesn't need to be */ 403 /* dont make it unstackable if it doesn't need to be */
401 if (IS_WEAPON (op) || IS_ARMOR (op)) 404 if (op->is_weapon () || op->is_armor ())
402 { 405 {
403 op->weight = (op->weight * lmt->weight) / 100; 406 op->weight = (op->weight * lmt->weight) / 100;
404 op->value = (op->value * lmt->value) / 100; 407 op->value = (op->value * lmt->value) / 100;
405 } 408 }
406#endif 409#endif
550{ 553{
551 refcnt = 0; 554 refcnt = 0;
552 rc_next = rc_first; 555 rc_next = rc_first;
553 rc_first = this; 556 rc_first = this;
554} 557}
558#endif
555 559
556refcounted::~refcounted () 560refcounted::~refcounted ()
557{ 561{
562#if 0
558 assert (!rc_next); 563 assert (!rc_next);
559 assert (!refcnt); 564 assert (!refcnt);
560}
561#endif 565#endif
566}
562 567
563void *alloc (int s) throw (std::bad_alloc) 568void *salloc_ (int n) throw (std::bad_alloc)
564{ 569{
565 void *p = g_slice_alloc (s); 570 void *ptr = g_slice_alloc (n);
566 571
567 if (!p) 572 if (!ptr)
568 throw std::bad_alloc (); 573 throw std::bad_alloc ();
569 574
570 return p; 575 return ptr;
576}
577
578void *salloc_ (int n, void *src) throw (std::bad_alloc)
579{
580 void *ptr = salloc_ (n);
581
582 if (src)
583 memcpy (ptr, src, n);
584 else
585 memset (ptr, 0, n);
586
587 return ptr;
571} 588}
572 589
573void assign (char *dst, const char *src, int maxlen) 590void assign (char *dst, const char *src, int maxlen)
574{ 591{
575 if (!src) 592 if (!src)
592 } 609 }
593 else 610 else
594 memcpy (dst, src, len + 1); 611 memcpy (dst, src, len + 1);
595} 612}
596 613
614tstamp now ()
615{
616 struct timeval tv;
597 617
618 gettimeofday (&tv, 0);
619 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6);
620}
621

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines