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.330 by root, Sun Apr 18 14:01:33 2010 UTC vs.
Revision 1.337 by root, Thu May 6 21:45:49 2010 UTC

426 426
427 return 0; 427 return 0;
428} 428}
429 429
430// adjust weight per container type ("of holding") 430// adjust weight per container type ("of holding")
431static sint32 431static uint32
432weight_adjust_for (object *op, sint32 weight) 432weight_adjust_for (object *op, uint32 weight)
433{ 433{
434 return op->type == CONTAINER 434 return op->type == CONTAINER
435 ? lerp (weight, 0, 100, 0, 100 - op->stats.Str) 435 ? weight - weight * op->stats.Str / 100
436 : weight; 436 : weight;
437} 437}
438 438
439/* 439/*
440 * adjust_weight(object, weight) adds the specified weight to an object, 440 * subtracts, then adds, the specified weight to an object,
441 * and also updates how much the environment(s) is/are carrying. 441 * and also updates how much the environment(s) is/are carrying.
442 */ 442 */
443static void 443static void
444adjust_weight (object *op, sint32 weight) 444adjust_weight (object *op, sint32 sub, sint32 add)
445{ 445{
446 while (op) 446 while (op)
447 { 447 {
448 // adjust by actual difference to account for rounding errors 448 sint32 ocarrying = op->carrying;
449 // i.e. (w2 - w1) / f != w2 / f - w1 / f and the latter is correct
450 weight = weight_adjust_for (op, op->carrying)
451 - weight_adjust_for (op, op->carrying - weight);
452 449
453 if (!weight) 450 op->carrying -= weight_adjust_for (op, sub);
454 return; 451 op->carrying += weight_adjust_for (op, add);
455
456 op->carrying += weight;
457 452
458 if (object *pl = op->visible_to ()) 453 if (object *pl = op->visible_to ())
459 if (pl != op) // player is handled lazily 454 if (pl != op) // player is handled lazily
460 esrv_update_item (UPD_WEIGHT, pl, op); 455 esrv_update_item (UPD_WEIGHT, pl, op);
461 456
457 sub = ocarrying;
458 add = op->carrying;
459
462 op = op->env; 460 op = op->env;
463 } 461 }
464} 462}
465 463
466/* 464/*
473{ 471{
474 sint32 sum = 0; 472 sint32 sum = 0;
475 473
476 for (object *op = inv; op; op = op->below) 474 for (object *op = inv; op; op = op->below)
477 { 475 {
478 if (op->inv)
479 op->update_weight (); 476 op->update_weight ();
480 477
481 sum += op->total_weight (); 478 sum += weight_adjust_for (this, op->total_weight ());
482 } 479 }
483
484 sum = weight_adjust_for (this, sum);
485 480
486 if (sum != carrying) 481 if (sum != carrying)
487 { 482 {
488 if (carrying != sum)//D 483 if (carrying != sum && carrying)//D
489 LOG (llevDebug, "updating weight got %ld, expected %ld (%s)\n", 484 LOG (llevDebug, "updating carrying got %ld, expected %ld (%s)\n",
490 (long long)sum, (long long)carrying, debug_desc ()); 485 (long long)sum, (long long)carrying, debug_desc ());
491 486
492 carrying = sum; 487 carrying = sum;
493 488
494 if (object *pl = visible_to ()) 489 if (object *pl = visible_to ())
1144 flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed 1139 flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed
1145 if (object *pl = visible_to ()) 1140 if (object *pl = visible_to ())
1146 esrv_del_item (pl->contr, count); 1141 esrv_del_item (pl->contr, count);
1147 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed 1142 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1148 1143
1149 adjust_weight (env, -total_weight ()); 1144 adjust_weight (env, total_weight (), 0);
1150 1145
1151 object *pl = in_player (); 1146 object *pl = in_player ();
1152 1147
1153 /* we set up values so that it could be inserted into 1148 /* we set up values so that it could be inserted into
1154 * the map, but we don't actually do that - it is up 1149 * the map, but we don't actually do that - it is up
1572 */ 1567 */
1573 1568
1574 /* if this is not the head or flag has been passed, don't check walk on status */ 1569 /* if this is not the head or flag has been passed, don't check walk on status */
1575 if (!(flag & INS_NO_WALK_ON) && op->is_head ()) 1570 if (!(flag & INS_NO_WALK_ON) && op->is_head ())
1576 { 1571 {
1577 if (check_move_on (op, originator)) 1572 if (check_move_on (op, originator, flag))
1578 return 0; 1573 return 0;
1579 1574
1580 /* If we are a multi part object, lets work our way through the check 1575 /* If we are a multi part object, let's work our way through the check
1581 * walk on's. 1576 * walk on's.
1582 */ 1577 */
1583 for (object *tmp = op->more; tmp; tmp = tmp->more) 1578 for (object *tmp = op->more; tmp; tmp = tmp->more)
1584 if (check_move_on (tmp, originator)) 1579 if (check_move_on (tmp, originator, flag))
1585 return 0; 1580 return 0;
1586 } 1581 }
1587 1582
1588 return op; 1583 return op;
1589} 1584}
1655 1650
1656 nr = min (nr, nrof); 1651 nr = min (nr, nrof);
1657 1652
1658 if (nrof > nr) 1653 if (nrof > nr)
1659 { 1654 {
1655 sint64 oweight = total_weight ();
1656
1660 nrof -= nr; 1657 nrof -= nr;
1661 adjust_weight (env, -weight * max (1, nr)); // carrying == 0
1662 1658
1663 if (object *pl = visible_to ()) 1659 if (object *pl = visible_to ())
1664 esrv_update_item (UPD_NROF, pl, this); 1660 esrv_update_item (UPD_NROF, pl, this);
1661
1662 adjust_weight (env, oweight, total_weight ());
1665 1663
1666 return true; 1664 return true;
1667 } 1665 }
1668 else 1666 else
1669 { 1667 {
1744 if (op->nrof) 1742 if (op->nrof)
1745 for (object *tmp = inv; tmp; tmp = tmp->below) 1743 for (object *tmp = inv; tmp; tmp = tmp->below)
1746 if (object::can_merge (tmp, op)) 1744 if (object::can_merge (tmp, op))
1747 { 1745 {
1748 /* return the original object and remove inserted object 1746 /* return the original object and remove inserted object
1749 (client needs the original object) */ 1747 (client prefers the original object) */
1748
1749 // carring must be 0 for mergable objects
1750 sint64 oweight = tmp->weight * tmp->nrof;
1751
1750 tmp->nrof += op->nrof; 1752 tmp->nrof += op->nrof;
1751 1753
1752 if (object *pl = tmp->visible_to ()) 1754 if (object *pl = tmp->visible_to ())
1753 esrv_update_item (UPD_NROF, pl, tmp); 1755 esrv_update_item (UPD_NROF, pl, tmp);
1754 1756
1755 adjust_weight (this, op->total_weight ()); 1757 adjust_weight (this, oweight, tmp->weight * tmp->nrof);
1756 1758
1757 op->destroy (); 1759 op->destroy ();
1758 op = tmp; 1760 op = tmp;
1759 goto inserted; 1761 goto inserted;
1760 } 1762 }
1776 op->flag [FLAG_REMOVED] = 0; 1778 op->flag [FLAG_REMOVED] = 0;
1777 1779
1778 if (object *pl = op->visible_to ()) 1780 if (object *pl = op->visible_to ())
1779 esrv_send_item (pl, op); 1781 esrv_send_item (pl, op);
1780 1782
1781 adjust_weight (this, op->total_weight ()); 1783 adjust_weight (this, 0, op->total_weight ());
1782 1784
1783inserted: 1785inserted:
1784 /* reset the light list and los of the players on the map */ 1786 /* reset the light list and los of the players on the map */
1785 if (op->glow_radius && is_on_map ()) 1787 if (op->glow_radius && is_on_map ())
1786 { 1788 {
1815 * MSW 2001-07-08: Check all objects on space, not just those below 1817 * MSW 2001-07-08: Check all objects on space, not just those below
1816 * object being inserted. insert_ob_in_map may not put new objects 1818 * object being inserted. insert_ob_in_map may not put new objects
1817 * on top. 1819 * on top.
1818 */ 1820 */
1819int 1821int
1820check_move_on (object *op, object *originator) 1822check_move_on (object *op, object *originator, int flags)
1821{ 1823{
1822 if (op->flag [FLAG_NO_APPLY]) 1824 if (op->flag [FLAG_NO_APPLY])
1823 return 0; 1825 return 0;
1824 1826
1825 object *tmp; 1827 object *tmp;
1884 1886
1885 /* Basically same logic as above, except now for actual apply. */ 1887 /* Basically same logic as above, except now for actual apply. */
1886 if ((!op->move_type && tmp->move_on & MOVE_WALK) || 1888 if ((!op->move_type && tmp->move_on & MOVE_WALK) ||
1887 ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0)) 1889 ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0))
1888 { 1890 {
1891 if ((flags & INS_NO_AUTO_EXIT)
1892 && (tmp->type == EXIT || tmp->type == TELEPORTER
1893 || tmp->type == HOLE || tmp->type == TRAPDOOR)) //TODO: temporary, fix exits instead
1894 continue;
1895
1889 move_apply (tmp, op, originator); 1896 move_apply (tmp, op, originator);
1890 1897
1891 if (op->destroyed ()) 1898 if (op->destroyed ())
1892 return 1; 1899 return 1;
1893 1900
2230#if 1 // new algorithm 2237#if 1 // new algorithm
2231 // this works by putting x, y into 16 sectors, which 2238 // this works by putting x, y into 16 sectors, which
2232 // are not equal sized, but are a better approximation 2239 // are not equal sized, but are a better approximation
2233 // then the old algorithm, and then using a mapping 2240 // then the old algorithm, and then using a mapping
2234 // table to map it into a direction value. 2241 // table to map it into a direction value.
2242 // basically, it maps these comparisons to each bit
2243 // bit #3: x < 0
2244 // bit #2: y < 0
2245 // bit #1: x > y
2246 // bit #0: x > 2y
2235 2247
2236 static const uint8 dir[16] = { 2248 static const uint8 dir[16] = {
2237 4, 5, 4, 3, 2249 4, 5, 4, 3,
2238 2, 1, 2, 3, 2250 2, 1, 2, 3,
2239 6, 5, 6, 7, 2251 6, 5, 6, 7,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines