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.213 by root, Tue Apr 22 01:18:10 2008 UTC vs.
Revision 1.214 by root, Tue Apr 22 07:01:46 2008 UTC

330 330
331 /* Everything passes, must be OK. */ 331 /* Everything passes, must be OK. */
332 return 1; 332 return 1;
333} 333}
334 334
335// find player who can see this object
336object *
337object::visible_to () const
338{
339 if (!flag [FLAG_REMOVED])
340 {
341 // see if we are in a container of sorts
342 if (env)
343 {
344 // the player inventory itself is always visible
345 if (env->type == PLAYER)
346 return env;
347
348 // else a player could have our env open
349 object *envest = env->outer_env ();
350
351 // the player itself is always on a map, so we will find him here
352 // even if our inv is in a player.
353 if (envest->is_on_map ())
354 if (object *pl = envest->ms ().player ())
355 if (pl->container == env)
356 return pl;
357 }
358 else
359 {
360 // maybe there is a player standing on the same mapspace
361 // this will catch the case where "this" is a player
362 if (object *pl = ms ().player ())
363 return pl;
364 }
365 }
366
367 return 0;
368}
369
335// adjust weight per container type ("of holding") 370// adjust weight per container type ("of holding")
336static sint32 371static sint32
337weight_adjust (object *op, sint32 weight) 372weight_adjust (object *op, sint32 weight)
338{ 373{
339 return op->type == CONTAINER 374 return op->type == CONTAINER
1169 if (!top) 1204 if (!top)
1170 for (top = op; top && top->above; top = top->above) 1205 for (top = op; top && top->above; top = top->above)
1171 ; 1206 ;
1172 1207
1173 for (; top; top = top->below) 1208 for (; top; top = top->below)
1174 {
1175 if (top == op)
1176 continue;
1177
1178 if (object::can_merge (op, top)) 1209 if (object::can_merge (op, top))
1179 { 1210 {
1180 top->nrof += op->nrof; 1211 top->nrof += op->nrof;
1181 1212
1182/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ 1213 if (object *pl = top->visible_to ())
1183 op->weight = 0; /* Don't want any adjustements now */ 1214 esrv_update_item (UPD_NROF, pl, top);
1215
1216 op->weight = 0; // cancel the addition above
1217 op->carrying = 0; // must be 0 already
1218
1184 op->destroy (); 1219 op->destroy (1);
1220
1185 return top; 1221 return top;
1186 } 1222 }
1187 }
1188 1223
1189 return 0; 1224 return 0;
1190} 1225}
1191 1226
1192void 1227void
1494 return where->env->insert (this); 1529 return where->env->insert (this);
1495 else 1530 else
1496 return where->map->insert (this, where->x, where->y, originator, flags); 1531 return where->map->insert (this, where->x, where->y, originator, flags);
1497} 1532}
1498 1533
1499// find player who can see this object
1500object *
1501object::visible_to () const
1502{
1503 if (!flag [FLAG_REMOVED])
1504 {
1505 // see if we are in a container of sorts
1506 if (env)
1507 {
1508 // the player inventory itself is always visible
1509 if (env->type == PLAYER)
1510 return env;
1511
1512 // else a player could have our env open
1513 object *envest = env->outer_env ();
1514
1515 // the player itself is always on a map, so we will find him here
1516 // even if our inv is in a player.
1517 if (envest->is_on_map ())
1518 if (object *pl = envest->ms ().player ())
1519 if (pl->container == env)
1520 return pl;
1521 }
1522 else
1523 {
1524 // maybe there is a player standing on the same mapspace
1525 // this will catch the case where "this" is a player
1526 if (object *pl = ms ().player ())
1527 return pl;
1528 }
1529 }
1530
1531 return 0;
1532}
1533
1534/* 1534/*
1535 * decrease(object, number) decreases a specified number from 1535 * decrease(object, number) decreases a specified number from
1536 * the amount of an object. If the amount reaches 0, the object 1536 * the amount of an object. If the amount reaches 0, the object
1537 * is subsequently removed and freed. 1537 * is subsequently removed and freed.
1538 * 1538 *
1638 if (object::can_merge (tmp, op)) 1638 if (object::can_merge (tmp, op))
1639 { 1639 {
1640 /* return the original object and remove inserted object 1640 /* return the original object and remove inserted object
1641 (client needs the original object) */ 1641 (client needs the original object) */
1642 tmp->nrof += op->nrof; 1642 tmp->nrof += op->nrof;
1643
1644 if (object *pl = tmp->visible_to ())
1645 esrv_update_item (UPD_NROF, pl, tmp);
1646
1643 adjust_weight (this, op->total_weight ()); 1647 adjust_weight (this, op->total_weight ());
1644 1648
1645 op->destroy (1); 1649 op->destroy (1);
1646 op = tmp; 1650 op = tmp;
1647 goto inserted; 1651 goto inserted;
1661 1665
1662 inv = op; 1666 inv = op;
1663 1667
1664 op->flag [FLAG_REMOVED] = 0; 1668 op->flag [FLAG_REMOVED] = 0;
1665 1669
1670 if (object *pl = op->visible_to ())
1671 esrv_send_item (pl, op);
1672
1666 adjust_weight (this, op->total_weight ()); 1673 adjust_weight (this, op->total_weight ());
1667 1674
1668inserted: 1675inserted:
1669 /* reset the light list and los of the players on the map */ 1676 /* reset the light list and los of the players on the map */
1670 if (op->glow_radius && map && map->darkness) 1677 if (op->glow_radius && map && map->darkness)
1671 update_all_los (map, x, y); 1678 update_all_los (map, x, y);
1672 1679
1673 if (object *otmp = in_player ()) 1680 // if this is a player's inventory, update stats
1674 if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1681 if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER])
1675 otmp->update_stats (); 1682 update_stats ();
1676 1683
1677 INVOKE_OBJECT (INSERT, this); 1684 INVOKE_OBJECT (INSERT, this);
1678 1685
1679 return op; 1686 return op;
1680} 1687}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines