… | |
… | |
426 | |
426 | |
427 | return 0; |
427 | return 0; |
428 | } |
428 | } |
429 | |
429 | |
430 | // adjust weight per container type ("of holding") |
430 | // adjust weight per container type ("of holding") |
431 | static sint32 |
431 | static uint32 |
432 | weight_adjust_for (object *op, sint32 weight) |
432 | weight_adjust_for (object *op, uint32 weight) |
433 | { |
433 | { |
434 | return op->type == CONTAINER |
434 | return op->type == CONTAINER |
435 | ? lerp (weight, 0, 100, 0, 100 - op->stats.Str) |
435 | ? weight - weight * op->stats.Str / 100 |
436 | : weight; |
436 | : weight; |
437 | } |
437 | } |
438 | |
438 | |
439 | /* |
439 | /* |
440 | * adjust_weight(object, weight) adds the specified weight to an object, |
440 | * subtracts, then adds, the specified weight to an object, |
441 | * and also updates how much the environment(s) is/are carrying. |
441 | * and also updates how much the environment(s) is/are carrying. |
442 | */ |
442 | */ |
443 | static void |
443 | static void |
444 | adjust_weight (object *op, sint32 weight) |
444 | adjust_weight (object *op, sint32 sub, sint32 add) |
445 | { |
445 | { |
446 | while (op) |
446 | while (op) |
447 | { |
447 | { |
448 | // adjust by actual difference to account for rounding errors |
448 | sint32 ocarrying = op->carrying; |
449 | // i.e. (w2 - w1) / f != w2 / f - w1 / f and the latter is correct |
|
|
450 | weight = weight_adjust_for (op, op->carrying + weight) |
|
|
451 | - weight_adjust_for (op, op->carrying); |
|
|
452 | |
449 | |
453 | if (!weight) |
450 | op->carrying -= weight_adjust_for (op, sub); |
454 | return; |
451 | op->carrying += weight_adjust_for (op, add); |
455 | |
|
|
456 | op->carrying += weight; |
|
|
457 | |
452 | |
458 | if (object *pl = op->visible_to ()) |
453 | if (object *pl = op->visible_to ()) |
459 | if (pl != op) // player is handled lazily |
454 | if (pl != op) // player is handled lazily |
460 | esrv_update_item (UPD_WEIGHT, pl, op); |
455 | esrv_update_item (UPD_WEIGHT, pl, op); |
461 | |
456 | |
|
|
457 | sub = ocarrying; |
|
|
458 | add = op->carrying; |
|
|
459 | |
462 | op = op->env; |
460 | op = op->env; |
463 | } |
461 | } |
464 | } |
462 | } |
465 | |
463 | |
466 | /* |
464 | /* |
… | |
… | |
473 | { |
471 | { |
474 | sint32 sum = 0; |
472 | sint32 sum = 0; |
475 | |
473 | |
476 | for (object *op = inv; op; op = op->below) |
474 | for (object *op = inv; op; op = op->below) |
477 | { |
475 | { |
478 | if (op->inv) |
|
|
479 | op->update_weight (); |
476 | op->update_weight (); |
480 | |
477 | |
481 | sum += op->total_weight (); |
478 | sum += weight_adjust_for (this, op->total_weight ()); |
482 | } |
479 | } |
483 | |
|
|
484 | sum = weight_adjust_for (this, sum); |
|
|
485 | |
480 | |
486 | if (sum != carrying) |
481 | if (sum != carrying) |
487 | { |
482 | { |
488 | if (carrying != sum)//D |
483 | if (carrying != sum && carrying)//D |
489 | LOG (llevDebug, "updating carrying got %ld, expected %ld (%s)\n", |
484 | LOG (llevDebug, "updating carrying got %ld, expected %ld (%s)\n", |
490 | (long long)sum, (long long)carrying, debug_desc ()); |
485 | (long long)sum, (long long)carrying, debug_desc ()); |
491 | |
486 | |
492 | carrying = sum; |
487 | carrying = sum; |
493 | |
488 | |
… | |
… | |
1144 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
1139 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
1145 | if (object *pl = visible_to ()) |
1140 | if (object *pl = visible_to ()) |
1146 | esrv_del_item (pl->contr, count); |
1141 | esrv_del_item (pl->contr, count); |
1147 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
1142 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
1148 | |
1143 | |
1149 | adjust_weight (env, -total_weight ()); |
1144 | adjust_weight (env, total_weight (), 0); |
1150 | |
1145 | |
1151 | object *pl = in_player (); |
1146 | object *pl = in_player (); |
1152 | |
1147 | |
1153 | /* we set up values so that it could be inserted into |
1148 | /* we set up values so that it could be inserted into |
1154 | * the map, but we don't actually do that - it is up |
1149 | * the map, but we don't actually do that - it is up |
… | |
… | |
1655 | |
1650 | |
1656 | nr = min (nr, nrof); |
1651 | nr = min (nr, nrof); |
1657 | |
1652 | |
1658 | if (nrof > nr) |
1653 | if (nrof > nr) |
1659 | { |
1654 | { |
|
|
1655 | sint64 oweight = total_weight (); |
|
|
1656 | |
1660 | nrof -= nr; |
1657 | nrof -= nr; |
1661 | adjust_weight (env, -weight * max (1, nr)); // carrying == 0 |
|
|
1662 | |
1658 | |
1663 | if (object *pl = visible_to ()) |
1659 | if (object *pl = visible_to ()) |
1664 | esrv_update_item (UPD_NROF, pl, this); |
1660 | esrv_update_item (UPD_NROF, pl, this); |
|
|
1661 | |
|
|
1662 | adjust_weight (env, oweight, total_weight ()); |
1665 | |
1663 | |
1666 | return true; |
1664 | return true; |
1667 | } |
1665 | } |
1668 | else |
1666 | else |
1669 | { |
1667 | { |
… | |
… | |
1744 | if (op->nrof) |
1742 | if (op->nrof) |
1745 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1743 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1746 | if (object::can_merge (tmp, op)) |
1744 | if (object::can_merge (tmp, op)) |
1747 | { |
1745 | { |
1748 | /* return the original object and remove inserted object |
1746 | /* return the original object and remove inserted object |
1749 | (client needs the original object) */ |
1747 | (client prefers the original object) */ |
|
|
1748 | |
|
|
1749 | // carring must be 0 for mergable objects |
|
|
1750 | sint64 oweight = tmp->weight * tmp->nrof; |
|
|
1751 | |
1750 | tmp->nrof += op->nrof; |
1752 | tmp->nrof += op->nrof; |
1751 | |
1753 | |
1752 | if (object *pl = tmp->visible_to ()) |
1754 | if (object *pl = tmp->visible_to ()) |
1753 | esrv_update_item (UPD_NROF, pl, tmp); |
1755 | esrv_update_item (UPD_NROF, pl, tmp); |
1754 | |
1756 | |
1755 | adjust_weight (this, op->total_weight ()); |
1757 | adjust_weight (this, oweight, tmp->weight * tmp->nrof); |
1756 | |
1758 | |
1757 | op->destroy (); |
1759 | op->destroy (); |
1758 | op = tmp; |
1760 | op = tmp; |
1759 | goto inserted; |
1761 | goto inserted; |
1760 | } |
1762 | } |
… | |
… | |
1776 | op->flag [FLAG_REMOVED] = 0; |
1778 | op->flag [FLAG_REMOVED] = 0; |
1777 | |
1779 | |
1778 | if (object *pl = op->visible_to ()) |
1780 | if (object *pl = op->visible_to ()) |
1779 | esrv_send_item (pl, op); |
1781 | esrv_send_item (pl, op); |
1780 | |
1782 | |
1781 | adjust_weight (this, op->total_weight ()); |
1783 | adjust_weight (this, 0, op->total_weight ()); |
1782 | |
1784 | |
1783 | inserted: |
1785 | inserted: |
1784 | /* reset the light list and los of the players on the map */ |
1786 | /* reset the light list and los of the players on the map */ |
1785 | if (op->glow_radius && is_on_map ()) |
1787 | if (op->glow_radius && is_on_map ()) |
1786 | { |
1788 | { |