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.211 by root, Mon Apr 21 21:32:32 2008 UTC vs.
Revision 1.212 by root, Mon Apr 21 23:35:24 2008 UTC

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
918void 932void
919object::do_destroy () 933object::do_destroy ()
920{ 934{
935 if (object *pl = visible_to ())
936 esrv_del_item (pl->contr, count);
937
921 attachable::do_destroy (); 938 attachable::do_destroy ();
922 939
923 if (flag [FLAG_IS_LINKED]) 940 if (flag [FLAG_IS_LINKED])
924 remove_button_link (this); 941 remove_button_link (this);
925 942
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
1483static object * 1500object *
1484visible_to (object *op) 1501object::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 = op->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 */
1523bool 1541bool
1524object::decrease (sint32 nr) 1542object::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 * split(ob,nr) splits up ob into two parts. The part which 1568 * split(ob,nr) splits up ob into two parts. The part which
1558 * On failure, NULL is returned. 1571 * On failure, NULL is returned.
1559 */ 1572 */
1560object * 1573object *
1561object::split (sint32 nr) 1574object::split (sint32 nr)
1562{ 1575{
1576 int have = number_of ();
1577
1563 if (nrof < nr) 1578 if (have < nr)
1564 return 0; 1579 return 0;
1565 else if (nrof == nr) 1580 else if (have == nr)
1566 { 1581 {
1567 remove (); 1582 remove ();
1568 return this; 1583 return this;
1569 } 1584 }
1570 else 1585 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines