… | |
… | |
1477 | return where->env->insert (this); |
1477 | return where->env->insert (this); |
1478 | else |
1478 | else |
1479 | return where->map->insert (this, where->x, where->y, originator, flags); |
1479 | return where->map->insert (this, where->x, where->y, originator, flags); |
1480 | } |
1480 | } |
1481 | |
1481 | |
1482 | /* |
|
|
1483 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
|
|
1484 | * is returned contains nr objects, and the remaining parts contains |
|
|
1485 | * the rest (or is removed and freed if that number is 0). |
|
|
1486 | * On failure, NULL is returned, and the reason put into the |
|
|
1487 | * global static errmsg array. |
|
|
1488 | */ |
|
|
1489 | object * |
|
|
1490 | object::split_nr (sint32 nr) |
|
|
1491 | { |
|
|
1492 | if (nrof < nr) |
|
|
1493 | return 0; |
|
|
1494 | else if (nrof == nr) |
|
|
1495 | { |
|
|
1496 | remove (); |
|
|
1497 | return this; |
|
|
1498 | } |
|
|
1499 | else |
|
|
1500 | { |
|
|
1501 | decrease_nr (nr); |
|
|
1502 | |
|
|
1503 | object *op = object_create_clone (this); |
|
|
1504 | op->nrof = nr; |
|
|
1505 | return op; |
|
|
1506 | } |
|
|
1507 | } |
|
|
1508 | |
|
|
1509 | //TODO: remove, but semantics differs from split_nr |
|
|
1510 | object * |
|
|
1511 | get_split_ob (object *orig_ob, uint32 nr) |
|
|
1512 | { |
|
|
1513 | if (orig_ob->nrof < nr) |
|
|
1514 | { |
|
|
1515 | sprintf (errmsg, "There are only %d %ss.", orig_ob->nrof ? orig_ob->nrof : 1, &orig_ob->name); |
|
|
1516 | return 0; |
|
|
1517 | } |
|
|
1518 | |
|
|
1519 | return orig_ob->split_nr (nr); |
|
|
1520 | } |
|
|
1521 | |
|
|
1522 | // find player who can see this object |
1482 | // find player who can see this object |
1523 | static object * |
1483 | static object * |
1524 | visible_to (object *op) |
1484 | visible_to (object *op) |
1525 | { |
1485 | { |
1526 | if (!op->flag [FLAG_REMOVED]) |
1486 | if (!op->flag [FLAG_REMOVED]) |
… | |
… | |
1552 | |
1512 | |
1553 | return 0; |
1513 | return 0; |
1554 | } |
1514 | } |
1555 | |
1515 | |
1556 | /* |
1516 | /* |
1557 | * decrease_ob_nr(object, number) decreases a specified number from |
1517 | * decrease(object, number) decreases a specified number from |
1558 | * the amount of an object. If the amount reaches 0, the object |
1518 | * the amount of an object. If the amount reaches 0, the object |
1559 | * is subsequently removed and freed. |
1519 | * is subsequently removed and freed. |
1560 | * |
1520 | * |
1561 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1521 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1562 | */ |
1522 | */ |
1563 | bool |
1523 | bool |
1564 | object::decrease_nr (sint32 nr) |
1524 | object::decrease (sint32 nr) |
1565 | { |
1525 | { |
1566 | nr = min (nr, nrof); |
1526 | nr = min (nr, nrof); |
1567 | |
1527 | |
1568 | if (!nr) |
1528 | if (!nr) |
1569 | return 1; |
1529 | return 1; |
… | |
… | |
1589 | this->destroy (1); |
1549 | this->destroy (1); |
1590 | return 0; |
1550 | return 0; |
1591 | } |
1551 | } |
1592 | } |
1552 | } |
1593 | |
1553 | |
1594 | //TODO: remove |
1554 | /* |
|
|
1555 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
|
|
1556 | * is returned contains nr objects, and the remaining parts contains |
|
|
1557 | * the rest (or is removed and freed if that number is 0). |
|
|
1558 | * On failure, NULL is returned, and the reason put into the |
|
|
1559 | * global static errmsg array. |
|
|
1560 | */ |
1595 | object * |
1561 | object * |
1596 | decrease_ob_nr (object *op, uint32 i) |
1562 | object::split (sint32 nr) |
1597 | { |
1563 | { |
1598 | return op->decrease_nr (i) ? op : 0; |
1564 | if (nrof < nr) |
|
|
1565 | return 0; |
|
|
1566 | else if (nrof == nr) |
|
|
1567 | { |
|
|
1568 | remove (); |
|
|
1569 | return this; |
|
|
1570 | } |
|
|
1571 | else |
|
|
1572 | { |
|
|
1573 | decrease (nr); |
|
|
1574 | |
|
|
1575 | object *op = object_create_clone (this); |
|
|
1576 | op->nrof = nr; |
|
|
1577 | return op; |
|
|
1578 | } |
|
|
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); |
1599 | } |
1592 | } |
1600 | |
1593 | |
1601 | object * |
1594 | object * |
1602 | insert_ob_in_ob (object *op, object *where) |
1595 | insert_ob_in_ob (object *op, object *where) |
1603 | { |
1596 | { |