… | |
… | |
354 | return 0; |
354 | return 0; |
355 | } |
355 | } |
356 | |
356 | |
357 | // adjust weight per container type ("of holding") |
357 | // adjust weight per container type ("of holding") |
358 | static sint32 |
358 | static sint32 |
359 | weight_adjust (object *op, sint32 weight) |
359 | weight_adjust_for (object *op, sint32 weight) |
360 | { |
360 | { |
361 | return op->type == CONTAINER |
361 | return op->type == CONTAINER |
362 | ? lerp (weight, 0, 100, 0, 100 - op->stats.Str) |
362 | ? lerp (weight, 0, 100, 0, 100 - op->stats.Str) |
363 | : weight; |
363 | : weight; |
364 | } |
364 | } |
… | |
… | |
370 | static void |
370 | static void |
371 | adjust_weight (object *op, sint32 weight) |
371 | adjust_weight (object *op, sint32 weight) |
372 | { |
372 | { |
373 | while (op) |
373 | while (op) |
374 | { |
374 | { |
|
|
375 | // adjust by actual difference to account for rounding errors |
|
|
376 | // i.e. (w2 - w1) / f != w2 / f - w1 / f and the latter is correct |
375 | weight = weight_adjust (op, weight); |
377 | weight = weight_adjust_for (op, op->carrying) |
|
|
378 | - weight_adjust_for (op, op->carrying - weight); |
376 | |
379 | |
377 | if (!weight) |
380 | if (!weight) |
378 | return; |
381 | return; |
379 | |
382 | |
380 | op->carrying += weight; |
383 | op->carrying += weight; |