… | |
… | |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
24 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
25 | sub/add_weight will transcend the environment updating the carrying |
25 | sub/add_weight will transcend the environment updating the carrying |
26 | variable. */ |
26 | variable. */ |
|
|
27 | |
27 | #include <global.h> |
28 | #include <global.h> |
28 | #include <stdio.h> |
29 | #include <stdio.h> |
29 | #include <sys/types.h> |
30 | #include <sys/types.h> |
30 | #include <sys/uio.h> |
31 | #include <sys/uio.h> |
31 | #include <object.h> |
32 | #include <object.h> |
… | |
… | |
326 | |
327 | |
327 | /* Everything passes, must be OK. */ |
328 | /* Everything passes, must be OK. */ |
328 | return 1; |
329 | return 1; |
329 | } |
330 | } |
330 | |
331 | |
|
|
332 | static sint32 |
|
|
333 | weight_adjust (object *op, sint32 weight) |
|
|
334 | { |
|
|
335 | return op->type == CONTAINER |
|
|
336 | ? lerp (weight, 0, 100, 0, 100 - op->stats.Str) |
|
|
337 | : weight; |
|
|
338 | } |
|
|
339 | |
331 | /* |
340 | /* |
|
|
341 | * add_weight(object, weight) adds the specified weight to an object, |
|
|
342 | * and also updates how much the environment(s) is/are carrying. |
|
|
343 | */ |
|
|
344 | static void |
|
|
345 | add_weight (object *op, sint32 weight) |
|
|
346 | { |
|
|
347 | while (op) |
|
|
348 | { |
|
|
349 | weight = weight_adjust (op, weight); |
|
|
350 | |
|
|
351 | op->carrying += weight; |
|
|
352 | op = op->env; |
|
|
353 | } |
|
|
354 | } |
|
|
355 | |
|
|
356 | /* |
|
|
357 | * sub_weight() recursively (outwards) subtracts a number from the |
|
|
358 | * weight of an object (and what is carried by it's environment(s)). |
|
|
359 | */ |
|
|
360 | static void |
|
|
361 | sub_weight (object *op, long weight) |
|
|
362 | { |
|
|
363 | add_weight (op, -weight); |
|
|
364 | } |
|
|
365 | |
|
|
366 | /* |
332 | * sum_weight() is a recursive function which calculates the weight |
367 | * this is a recursive function which calculates the weight |
333 | * an object is carrying. It goes through in figures out how much |
368 | * an object is carrying. It goes through op and figures out how much |
334 | * containers are carrying, and sums it up. |
369 | * containers are carrying, and sums it up. |
335 | */ |
370 | */ |
336 | long |
371 | void |
337 | sum_weight (object *op) |
372 | object::update_weight () |
338 | { |
373 | { |
339 | long sum; |
374 | sint32 sum = 0; |
340 | object *inv; |
|
|
341 | |
375 | |
342 | for (sum = 0, inv = op->inv; inv; inv = inv->below) |
376 | for (object *op = inv; op; op = op->below) |
343 | { |
377 | { |
344 | if (inv->inv) |
378 | if (op->inv) |
345 | sum_weight (inv); |
379 | op->update_weight (); |
346 | |
380 | |
347 | sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); |
381 | sum += op->total_weight (); |
348 | } |
382 | } |
349 | |
383 | |
350 | if (op->type == CONTAINER && op->stats.Str) |
384 | carrying = weight_adjust (this, sum); |
351 | sum = (sum * (100 - op->stats.Str)) / 100; |
|
|
352 | |
|
|
353 | if (op->carrying != sum) |
|
|
354 | op->carrying = sum; |
|
|
355 | |
|
|
356 | return sum; |
|
|
357 | } |
|
|
358 | |
|
|
359 | /** |
|
|
360 | * Return the outermost environment object for a given object. |
|
|
361 | */ |
|
|
362 | |
|
|
363 | object * |
|
|
364 | object_get_env_recursive (object *op) |
|
|
365 | { |
|
|
366 | while (op->env != NULL) |
|
|
367 | op = op->env; |
|
|
368 | return op; |
|
|
369 | } |
385 | } |
370 | |
386 | |
371 | /* |
387 | /* |
372 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
388 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
373 | * Some error messages. |
389 | * Some error messages. |
… | |
… | |
974 | play_sound (sound_destroy); |
990 | play_sound (sound_destroy); |
975 | else if (flag [FLAG_MONSTER]) |
991 | else if (flag [FLAG_MONSTER]) |
976 | play_sound (sound_find ("monster_destroy")); // quick hack, too lazy to create a generic mechanism |
992 | play_sound (sound_find ("monster_destroy")); // quick hack, too lazy to create a generic mechanism |
977 | |
993 | |
978 | attachable::destroy (); |
994 | attachable::destroy (); |
979 | } |
|
|
980 | |
|
|
981 | /* |
|
|
982 | * sub_weight() recursively (outwards) subtracts a number from the |
|
|
983 | * weight of an object (and what is carried by it's environment(s)). |
|
|
984 | */ |
|
|
985 | void |
|
|
986 | sub_weight (object *op, signed long weight) |
|
|
987 | { |
|
|
988 | while (op != NULL) |
|
|
989 | { |
|
|
990 | if (op->type == CONTAINER) |
|
|
991 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
|
|
992 | |
|
|
993 | op->carrying -= weight; |
|
|
994 | op = op->env; |
|
|
995 | } |
|
|
996 | } |
995 | } |
997 | |
996 | |
998 | /* op->remove (): |
997 | /* op->remove (): |
999 | * This function removes the object op from the linked list of objects |
998 | * This function removes the object op from the linked list of objects |
1000 | * which it is currently tied to. When this function is done, the |
999 | * which it is currently tied to. When this function is done, the |
… | |
… | |
1609 | return op; |
1608 | return op; |
1610 | else |
1609 | else |
1611 | { |
1610 | { |
1612 | op->destroy (); |
1611 | op->destroy (); |
1613 | return 0; |
1612 | return 0; |
1614 | } |
|
|
1615 | } |
|
|
1616 | |
|
|
1617 | /* |
|
|
1618 | * add_weight(object, weight) adds the specified weight to an object, |
|
|
1619 | * and also updates how much the environment(s) is/are carrying. |
|
|
1620 | */ |
|
|
1621 | void |
|
|
1622 | add_weight (object *op, signed long weight) |
|
|
1623 | { |
|
|
1624 | while (op != NULL) |
|
|
1625 | { |
|
|
1626 | if (op->type == CONTAINER) |
|
|
1627 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
|
|
1628 | |
|
|
1629 | op->carrying += weight; |
|
|
1630 | op = op->env; |
|
|
1631 | } |
1613 | } |
1632 | } |
1614 | } |
1633 | |
1615 | |
1634 | object * |
1616 | object * |
1635 | insert_ob_in_ob (object *op, object *where) |
1617 | insert_ob_in_ob (object *op, object *where) |