… | |
… | |
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; |
… | |
… | |
1290 | * of areas of callers (eg, anything that uses find_free_spot would now |
1293 | * of areas of callers (eg, anything that uses find_free_spot would now |
1291 | * need extra work |
1294 | * need extra work |
1292 | */ |
1295 | */ |
1293 | if (!xy_normalise (m, op->x, op->y)) |
1296 | if (!xy_normalise (m, op->x, op->y)) |
1294 | { |
1297 | { |
1295 | op->destroy (1); |
1298 | op->head_ ()->destroy (1);// remove head_ once all tail object destroyers found |
1296 | return 0; |
1299 | return 0; |
1297 | } |
1300 | } |
1298 | |
1301 | |
1299 | if (object *more = op->more) |
1302 | if (object *more = op->more) |
1300 | if (!insert_ob_in_map (more, m, originator, flag)) |
1303 | if (!insert_ob_in_map (more, m, originator, flag)) |
… | |
… | |
1818 | LOG (llevError, "Present_arch called outside map.\n"); |
1821 | LOG (llevError, "Present_arch called outside map.\n"); |
1819 | return NULL; |
1822 | return NULL; |
1820 | } |
1823 | } |
1821 | |
1824 | |
1822 | for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above) |
1825 | for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above) |
1823 | if (tmp->arch == at) |
1826 | if (tmp->arch->archname == at->archname) |
1824 | return tmp; |
1827 | return tmp; |
1825 | |
1828 | |
1826 | return NULL; |
1829 | return NULL; |
1827 | } |
1830 | } |
1828 | |
1831 | |
… | |
… | |
1892 | * The first matching object is returned, or NULL if none. |
1895 | * The first matching object is returned, or NULL if none. |
1893 | */ |
1896 | */ |
1894 | object * |
1897 | object * |
1895 | present_arch_in_ob (const archetype *at, const object *op) |
1898 | present_arch_in_ob (const archetype *at, const object *op) |
1896 | { |
1899 | { |
1897 | for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) |
1900 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1898 | if (tmp->arch == at) |
1901 | if (tmp->arch->archname == at->archname) |
1899 | return tmp; |
1902 | return tmp; |
1900 | |
1903 | |
1901 | return NULL; |
1904 | return NULL; |
1902 | } |
1905 | } |
1903 | |
1906 | |