… | |
… | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <stdio.h> |
25 | #include <stdio.h> |
26 | #include <sys/types.h> |
26 | #include <sys/types.h> |
27 | #include <sys/uio.h> |
27 | #include <sys/uio.h> |
28 | #include <object.h> |
28 | #include <object.h> |
29 | #include <funcpoint.h> |
|
|
30 | #include <sproto.h> |
29 | #include <sproto.h> |
31 | #include <loader.h> |
30 | #include <loader.h> |
32 | |
31 | |
33 | #include <bitset> |
32 | #include <bitset> |
34 | |
33 | |
… | |
… | |
351 | { |
350 | { |
352 | while (op) |
351 | while (op) |
353 | { |
352 | { |
354 | weight = weight_adjust (op, weight); |
353 | weight = weight_adjust (op, weight); |
355 | |
354 | |
|
|
355 | if (!weight) |
|
|
356 | return; |
|
|
357 | |
356 | op->carrying += weight; |
358 | op->carrying += weight; |
|
|
359 | |
|
|
360 | if (object *pl = op->visible_to ()) |
|
|
361 | esrv_update_item (UPD_WEIGHT, pl, op); |
|
|
362 | |
357 | op = op->env; |
363 | op = op->env; |
358 | } |
364 | } |
359 | } |
365 | } |
360 | |
366 | |
361 | /* |
367 | /* |
… | |
… | |
374 | op->update_weight (); |
380 | op->update_weight (); |
375 | |
381 | |
376 | sum += op->total_weight (); |
382 | sum += op->total_weight (); |
377 | } |
383 | } |
378 | |
384 | |
379 | carrying = weight_adjust (this, sum); |
385 | sum = weight_adjust (this, sum); |
|
|
386 | |
|
|
387 | if (sum != carrying) |
|
|
388 | { |
|
|
389 | carrying = sum; |
|
|
390 | |
|
|
391 | if (object *pl = visible_to ()) |
|
|
392 | esrv_update_item (UPD_WEIGHT, pl, this); |
|
|
393 | } |
380 | } |
394 | } |
381 | |
395 | |
382 | /* |
396 | /* |
383 | * Used by: Server DM commands: dumpbelow, dump. Some error messages. |
397 | * Used by: Server DM commands: dumpbelow, dump. Some error messages. |
384 | */ |
398 | */ |
… | |
… | |
916 | } |
930 | } |
917 | |
931 | |
918 | void |
932 | void |
919 | object::do_destroy () |
933 | object::do_destroy () |
920 | { |
934 | { |
921 | attachable::do_destroy (); |
|
|
922 | |
|
|
923 | if (flag [FLAG_IS_LINKED]) |
935 | if (flag [FLAG_IS_LINKED]) |
924 | remove_button_link (this); |
936 | remove_button_link (this); |
925 | |
937 | |
926 | if (flag [FLAG_FRIENDLY]) |
938 | if (flag [FLAG_FRIENDLY]) |
927 | remove_friendly_object (this); |
939 | remove_friendly_object (this); |
928 | |
940 | |
929 | if (!flag [FLAG_REMOVED]) |
|
|
930 | remove (); |
941 | remove (); |
|
|
942 | |
|
|
943 | attachable::do_destroy (); |
931 | |
944 | |
932 | destroy_inv (true); |
945 | destroy_inv (true); |
933 | |
946 | |
934 | deactivate (); |
947 | deactivate (); |
935 | unlink (); |
948 | unlink (); |
… | |
… | |
1003 | object::do_remove () |
1016 | object::do_remove () |
1004 | { |
1017 | { |
1005 | object *tmp, *last = 0; |
1018 | object *tmp, *last = 0; |
1006 | object *otmp; |
1019 | object *otmp; |
1007 | |
1020 | |
1008 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
1021 | if (flag [FLAG_REMOVED]) |
1009 | return; |
1022 | return; |
1010 | |
1023 | |
1011 | SET_FLAG (this, FLAG_REMOVED); |
|
|
1012 | INVOKE_OBJECT (REMOVE, this); |
1024 | INVOKE_OBJECT (REMOVE, this); |
|
|
1025 | |
|
|
1026 | if (object *pl = visible_to ()) |
|
|
1027 | esrv_del_item (pl->contr, count); |
|
|
1028 | |
|
|
1029 | flag [FLAG_REMOVED] = true; |
1013 | |
1030 | |
1014 | if (more) |
1031 | if (more) |
1015 | more->remove (); |
1032 | more->remove (); |
1016 | |
1033 | |
1017 | /* |
1034 | /* |
… | |
… | |
1478 | else |
1495 | else |
1479 | return where->map->insert (this, where->x, where->y, originator, flags); |
1496 | return where->map->insert (this, where->x, where->y, originator, flags); |
1480 | } |
1497 | } |
1481 | |
1498 | |
1482 | // find player who can see this object |
1499 | // find player who can see this object |
1483 | static object * |
1500 | object * |
1484 | visible_to (object *op) |
1501 | object::visible_to () const |
1485 | { |
1502 | { |
1486 | if (!op->flag [FLAG_REMOVED]) |
1503 | if (!flag [FLAG_REMOVED]) |
1487 | { |
1504 | { |
1488 | // see if we are in a container of sorts |
1505 | // see if we are in a container of sorts |
1489 | if (object *env = op->env) |
1506 | if (env) |
1490 | { |
1507 | { |
1491 | // the player inventory itself is always visible |
1508 | // the player inventory itself is always visible |
1492 | if (env->type == PLAYER) |
1509 | if (env->type == PLAYER) |
1493 | return env; |
1510 | return env; |
1494 | |
1511 | |
1495 | // else a player could have our env open |
1512 | // else a player could have our env open |
1496 | env = env->outer_env (); |
1513 | object *envest = env->outer_env (); |
1497 | |
1514 | |
1498 | // the player itself is always on a map, so we will find him here |
1515 | // the player itself is always on a map, so we will find him here |
1499 | // even if our inv is in a player. |
1516 | // even if our inv is in a player. |
1500 | if (env->is_on_map ()) |
1517 | if (envest->is_on_map ()) |
1501 | if (object *pl = env->ms ().player ()) |
1518 | if (object *pl = envest->ms ().player ()) |
1502 | if (pl->container == op->env) |
1519 | if (pl->container == env) |
1503 | return pl; |
1520 | return pl; |
1504 | } |
1521 | } |
1505 | else |
1522 | else |
1506 | { |
1523 | { |
1507 | // maybe there is a player standing on the same mapspace |
1524 | // maybe there is a player standing on the same mapspace |
|
|
1525 | // this will catch the case where "this" is a player |
1508 | if (object *pl = env->ms ().player ()) |
1526 | if (object *pl = ms ().player ()) |
1509 | return pl; |
1527 | return pl; |
1510 | } |
1528 | } |
1511 | } |
1529 | } |
1512 | |
1530 | |
1513 | return 0; |
1531 | return 0; |
… | |
… | |
1521 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1539 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1522 | */ |
1540 | */ |
1523 | bool |
1541 | bool |
1524 | object::decrease (sint32 nr) |
1542 | object::decrease (sint32 nr) |
1525 | { |
1543 | { |
|
|
1544 | if (!nr) |
|
|
1545 | return true; |
|
|
1546 | |
1526 | nr = min (nr, nrof); |
1547 | nr = min (nr, nrof); |
1527 | |
1548 | |
1528 | if (!nr) |
|
|
1529 | return 1; |
|
|
1530 | |
|
|
1531 | nrof -= nr; |
1549 | nrof -= nr; |
1532 | |
1550 | |
1533 | object *visible = visible_to (this); |
|
|
1534 | |
|
|
1535 | if (nrof) |
1551 | if (nrof) |
1536 | { |
1552 | { |
1537 | adjust_weight (env, -weight * nr); // carrying == 0 |
1553 | adjust_weight (env, -weight * nr); // carrying == 0 |
1538 | |
1554 | |
1539 | if (visible) |
1555 | if (object *pl = visible_to ()) |
1540 | esrv_send_item (visible, this); |
1556 | esrv_update_item (UPD_NROF, pl, this); |
1541 | |
1557 | |
1542 | return 1; |
1558 | return true; |
1543 | } |
1559 | } |
1544 | else |
1560 | else |
1545 | { |
1561 | { |
1546 | if (visible) |
|
|
1547 | esrv_del_item (visible->contr, count); |
|
|
1548 | |
|
|
1549 | this->destroy (1); |
1562 | destroy (1); |
1550 | return 0; |
1563 | return false; |
1551 | } |
1564 | } |
1552 | } |
1565 | } |
1553 | |
1566 | |
1554 | /* |
1567 | /* |
1555 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
1568 | * split(ob,nr) splits up ob into two parts. The part which |
1556 | * is returned contains nr objects, and the remaining parts contains |
1569 | * is returned contains nr objects, and the remaining parts contains |
1557 | * the rest (or is removed and freed if that number is 0). |
1570 | * the rest (or is removed and returned if that number is 0). |
1558 | * On failure, NULL is returned, and the reason put into the |
1571 | * On failure, NULL is returned. |
1559 | * global static errmsg array. |
|
|
1560 | */ |
1572 | */ |
1561 | object * |
1573 | object * |
1562 | object::split (sint32 nr) |
1574 | object::split (sint32 nr) |
1563 | { |
1575 | { |
|
|
1576 | int have = number_of (); |
|
|
1577 | |
1564 | if (nrof < nr) |
1578 | if (have < nr) |
1565 | return 0; |
1579 | return 0; |
1566 | else if (nrof == nr) |
1580 | else if (have == nr) |
1567 | { |
1581 | { |
1568 | remove (); |
1582 | remove (); |
1569 | return this; |
1583 | return this; |
1570 | } |
1584 | } |
1571 | else |
1585 | else |
… | |
… | |
1574 | |
1588 | |
1575 | object *op = object_create_clone (this); |
1589 | object *op = object_create_clone (this); |
1576 | op->nrof = nr; |
1590 | op->nrof = nr; |
1577 | return op; |
1591 | return op; |
1578 | } |
1592 | } |
1579 | } |
|
|
1580 | |
|
|
1581 | //TODO: remove, but semantics differs from split_nr |
|
|
1582 | object * |
|
|
1583 | get_split_ob (object *orig_ob, uint32 nr) |
|
|
1584 | { |
|
|
1585 | if (orig_ob->nrof < nr) |
|
|
1586 | { |
|
|
1587 | sprintf (errmsg, "There are only %d %ss.", orig_ob->nrof ? orig_ob->nrof : 1, &orig_ob->name); |
|
|
1588 | return 0; |
|
|
1589 | } |
|
|
1590 | |
|
|
1591 | return orig_ob->split (nr); |
|
|
1592 | } |
1593 | } |
1593 | |
1594 | |
1594 | object * |
1595 | object * |
1595 | insert_ob_in_ob (object *op, object *where) |
1596 | insert_ob_in_ob (object *op, object *where) |
1596 | { |
1597 | { |
… | |
… | |
1637 | if (object::can_merge (tmp, op)) |
1638 | if (object::can_merge (tmp, op)) |
1638 | { |
1639 | { |
1639 | /* return the original object and remove inserted object |
1640 | /* return the original object and remove inserted object |
1640 | (client needs the original object) */ |
1641 | (client needs the original object) */ |
1641 | tmp->nrof += op->nrof; |
1642 | tmp->nrof += op->nrof; |
|
|
1643 | adjust_weight (this, op->total_weight ()); |
|
|
1644 | |
1642 | op->destroy (1); |
1645 | op->destroy (1); |
1643 | op = tmp; |
1646 | op = tmp; |
1644 | goto inserted; |
1647 | goto inserted; |
1645 | } |
1648 | } |
1646 | |
1649 | |