ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.208 by root, Mon Apr 21 06:16:01 2008 UTC vs.
Revision 1.211 by root, Mon Apr 21 21:32:32 2008 UTC

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 */
1489object *
1490object::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
1510object *
1511get_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
1523static object * 1483static object *
1524visible_to (object *op) 1484visible_to (object *op)
1525{ 1485{
1526 if (!op->flag [FLAG_REMOVED]) 1486 if (!op->flag [FLAG_REMOVED])
1543 return pl; 1503 return pl;
1544 } 1504 }
1545 else 1505 else
1546 { 1506 {
1547 // maybe there is a player standing on the same mapspace 1507 // maybe there is a player standing on the same mapspace
1548 if (object *pl = env->ms ().player ()) 1508 if (object *pl = op->ms ().player ())
1549 return pl; 1509 return pl;
1550 } 1510 }
1551 } 1511 }
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 */
1563bool 1523bool
1564object::decrease_nr (sint32 nr) 1524object::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 * split(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 returned if that number is 0).
1558 * On failure, NULL is returned.
1559 */
1595object * 1560object *
1596decrease_ob_nr (object *op, uint32 i) 1561object::split (sint32 nr)
1597{ 1562{
1598 return op->decrease_nr (i) ? op : 0; 1563 if (nrof < nr)
1564 return 0;
1565 else if (nrof == nr)
1566 {
1567 remove ();
1568 return this;
1569 }
1570 else
1571 {
1572 decrease (nr);
1573
1574 object *op = object_create_clone (this);
1575 op->nrof = nr;
1576 return op;
1577 }
1599} 1578}
1600 1579
1601object * 1580object *
1602insert_ob_in_ob (object *op, object *where) 1581insert_ob_in_ob (object *op, object *where)
1603{ 1582{
1644 if (object::can_merge (tmp, op)) 1623 if (object::can_merge (tmp, op))
1645 { 1624 {
1646 /* return the original object and remove inserted object 1625 /* return the original object and remove inserted object
1647 (client needs the original object) */ 1626 (client needs the original object) */
1648 tmp->nrof += op->nrof; 1627 tmp->nrof += op->nrof;
1628 adjust_weight (this, op->total_weight ());
1629
1649 op->destroy (1); 1630 op->destroy (1);
1650 op = tmp; 1631 op = tmp;
1651 goto inserted; 1632 goto inserted;
1652 } 1633 }
1653 1634

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines