… | |
… | |
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 |
… | |
… | |
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 |
… | |
… | |
558 | assert (!rc_next); |
561 | assert (!rc_next); |
559 | assert (!refcnt); |
562 | assert (!refcnt); |
560 | } |
563 | } |
561 | #endif |
564 | #endif |
562 | |
565 | |
563 | void *alloc (int s) throw (std::bad_alloc) |
566 | void *salloc_ (int n) throw (std::bad_alloc) |
564 | { |
567 | { |
565 | void *p = g_slice_alloc (s); |
568 | void *ptr = g_slice_alloc (n); |
566 | |
569 | |
567 | if (!p) |
570 | if (!ptr) |
568 | throw std::bad_alloc (); |
571 | throw std::bad_alloc (); |
569 | |
572 | |
570 | return p; |
573 | return ptr; |
|
|
574 | } |
|
|
575 | |
|
|
576 | void *salloc_ (int n, void *src) throw (std::bad_alloc) |
|
|
577 | { |
|
|
578 | void *ptr = salloc_ (n); |
|
|
579 | |
|
|
580 | if (src) |
|
|
581 | memcpy (ptr, src, n); |
|
|
582 | else |
|
|
583 | memset (ptr, 0, n); |
|
|
584 | |
|
|
585 | return ptr; |
571 | } |
586 | } |
572 | |
587 | |
573 | void assign (char *dst, const char *src, int maxlen) |
588 | void assign (char *dst, const char *src, int maxlen) |
574 | { |
589 | { |
575 | if (!src) |
590 | if (!src) |
… | |
… | |
592 | } |
607 | } |
593 | else |
608 | else |
594 | memcpy (dst, src, len + 1); |
609 | memcpy (dst, src, len + 1); |
595 | } |
610 | } |
596 | |
611 | |
|
|
612 | tstamp now () |
|
|
613 | { |
|
|
614 | struct timeval tv; |
597 | |
615 | |
|
|
616 | gettimeofday (&tv, 0); |
|
|
617 | return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); |
|
|
618 | } |
|
|
619 | |