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.212 by root, Mon Apr 21 23:35:24 2008 UTC vs.
Revision 1.217 by root, Wed Apr 23 07:13:23 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
356 return; 391 return;
357 392
358 op->carrying += weight; 393 op->carrying += weight;
359 394
360 if (object *pl = op->visible_to ()) 395 if (object *pl = op->visible_to ())
396 if (pl != op) // player is handled lazily
361 esrv_update_item (UPD_WEIGHT, pl, op); 397 esrv_update_item (UPD_WEIGHT, pl, op);
362 398
363 op = op->env; 399 op = op->env;
364 } 400 }
365} 401}
366 402
387 if (sum != carrying) 423 if (sum != carrying)
388 { 424 {
389 carrying = sum; 425 carrying = sum;
390 426
391 if (object *pl = visible_to ()) 427 if (object *pl = visible_to ())
428 if (pl != this) // player is handled lazily
392 esrv_update_item (UPD_WEIGHT, pl, this); 429 esrv_update_item (UPD_WEIGHT, pl, this);
393 } 430 }
394} 431}
395 432
396/* 433/*
397 * Used by: Server DM commands: dumpbelow, dump. Some error messages. 434 * Used by: Server DM commands: dumpbelow, dump. Some error messages.
880object::destroy_inv (bool drop_to_ground) 917object::destroy_inv (bool drop_to_ground)
881{ 918{
882 // need to check first, because the checks below might segfault 919 // need to check first, because the checks below might segfault
883 // as we might be on an invalid mapspace and crossfire code 920 // as we might be on an invalid mapspace and crossfire code
884 // is too buggy to ensure that the inventory is empty. 921 // is too buggy to ensure that the inventory is empty.
885 // corollary: if you create arrows etc. with stuff in tis inventory, 922 // corollary: if you create arrows etc. with stuff in its inventory,
886 // cf will crash below with off-map x and y 923 // cf will crash below with off-map x and y
887 if (!inv) 924 if (!inv)
888 return; 925 return;
889 926
890 /* Only if the space blocks everything do we not process - 927 /* Only if the space blocks everything do we not process -
897 || map->nodrop 934 || map->nodrop
898 || ms ().move_block == MOVE_ALL) 935 || ms ().move_block == MOVE_ALL)
899 { 936 {
900 while (inv) 937 while (inv)
901 { 938 {
902 inv->destroy_inv (drop_to_ground); 939 inv->destroy_inv (false);
903 inv->destroy (); 940 inv->destroy ();
904 } 941 }
905 } 942 }
906 else 943 else
907 { /* Put objects in inventory onto this space */ 944 { /* Put objects in inventory onto this space */
913 || op->flag [FLAG_NO_DROP] 950 || op->flag [FLAG_NO_DROP]
914 || op->type == RUNE 951 || op->type == RUNE
915 || op->type == TRAP 952 || op->type == TRAP
916 || op->flag [FLAG_IS_A_TEMPLATE] 953 || op->flag [FLAG_IS_A_TEMPLATE]
917 || op->flag [FLAG_DESTROY_ON_DEATH]) 954 || op->flag [FLAG_DESTROY_ON_DEATH])
918 op->destroy (); 955 op->destroy (true);
919 else 956 else
920 map->insert (op, x, y); 957 map->insert (op, x, y);
921 } 958 }
922 } 959 }
923} 960}
930} 967}
931 968
932void 969void
933object::do_destroy () 970object::do_destroy ()
934{ 971{
935 if (object *pl = visible_to ())
936 esrv_del_item (pl->contr, count);
937
938 attachable::do_destroy ();
939
940 if (flag [FLAG_IS_LINKED]) 972 if (flag [FLAG_IS_LINKED])
941 remove_button_link (this); 973 remove_button_link (this);
942 974
943 if (flag [FLAG_FRIENDLY]) 975 if (flag [FLAG_FRIENDLY])
944 remove_friendly_object (this); 976 remove_friendly_object (this);
945 977
946 if (!flag [FLAG_REMOVED])
947 remove (); 978 remove ();
948 979
949 destroy_inv (true); 980 attachable::do_destroy ();
950 981
951 deactivate (); 982 deactivate ();
952 unlink (); 983 unlink ();
953 984
954 flag [FLAG_FREED] = 1; 985 flag [FLAG_FREED] = 1;
995object::destroy (bool destroy_inventory) 1026object::destroy (bool destroy_inventory)
996{ 1027{
997 if (destroyed ()) 1028 if (destroyed ())
998 return; 1029 return;
999 1030
1000 if (destroy_inventory) 1031 destroy_inv (!destroy_inventory);
1001 destroy_inv (false);
1002 1032
1003 if (is_head ()) 1033 if (is_head ())
1004 if (sound_destroy) 1034 if (sound_destroy)
1005 play_sound (sound_destroy); 1035 play_sound (sound_destroy);
1006 else if (flag [FLAG_MONSTER]) 1036 else if (flag [FLAG_MONSTER])
1020object::do_remove () 1050object::do_remove ()
1021{ 1051{
1022 object *tmp, *last = 0; 1052 object *tmp, *last = 0;
1023 object *otmp; 1053 object *otmp;
1024 1054
1025 if (QUERY_FLAG (this, FLAG_REMOVED)) 1055 if (flag [FLAG_REMOVED])
1026 return; 1056 return;
1027 1057
1028 SET_FLAG (this, FLAG_REMOVED);
1029 INVOKE_OBJECT (REMOVE, this); 1058 INVOKE_OBJECT (REMOVE, this);
1059
1060 if (object *pl = visible_to ())
1061 esrv_del_item (pl->contr, count);
1062
1063 flag [FLAG_REMOVED] = true;
1030 1064
1031 if (more) 1065 if (more)
1032 more->remove (); 1066 more->remove ();
1033 1067
1034 /* 1068 /*
1115 * removed (most likely destroyed), update the player view 1149 * removed (most likely destroyed), update the player view
1116 * appropriately. 1150 * appropriately.
1117 */ 1151 */
1118 pl->close_container (); 1152 pl->close_container ();
1119 1153
1120 pl->contr->ns->floorbox_update (); 1154 esrv_del_item (pl, count);
1121 } 1155 }
1122 1156
1123 for (tmp = ms.bot; tmp; tmp = tmp->above) 1157 for (tmp = ms.bot; tmp; tmp = tmp->above)
1124 { 1158 {
1125 /* No point updating the players look faces if he is the object 1159 /* No point updating the players look faces if he is the object
1169 if (!top) 1203 if (!top)
1170 for (top = op; top && top->above; top = top->above) 1204 for (top = op; top && top->above; top = top->above)
1171 ; 1205 ;
1172 1206
1173 for (; top; top = top->below) 1207 for (; top; top = top->below)
1174 {
1175 if (top == op)
1176 continue;
1177
1178 if (object::can_merge (op, top)) 1208 if (object::can_merge (op, top))
1179 { 1209 {
1180 top->nrof += op->nrof; 1210 top->nrof += op->nrof;
1181 1211
1182/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ 1212 if (object *pl = top->visible_to ())
1183 op->weight = 0; /* Don't want any adjustements now */ 1213 esrv_update_item (UPD_NROF, pl, top);
1214
1215 op->weight = 0; // cancel the addition above
1216 op->carrying = 0; // must be 0 already
1217
1184 op->destroy (); 1218 op->destroy (1);
1219
1185 return top; 1220 return top;
1186 } 1221 }
1187 }
1188 1222
1189 return 0; 1223 return 0;
1190} 1224}
1191 1225
1192void 1226void
1261 * of areas of callers (eg, anything that uses find_free_spot would now 1295 * of areas of callers (eg, anything that uses find_free_spot would now
1262 * need extra work 1296 * need extra work
1263 */ 1297 */
1264 if (!xy_normalise (m, op->x, op->y)) 1298 if (!xy_normalise (m, op->x, op->y))
1265 { 1299 {
1266 op->destroy (); 1300 op->destroy (1);
1267 return 0; 1301 return 0;
1268 } 1302 }
1269 1303
1270 if (object *more = op->more) 1304 if (object *more = op->more)
1271 if (!insert_ob_in_map (more, m, originator, flag)) 1305 if (!insert_ob_in_map (more, m, originator, flag))
1419 } 1453 }
1420 1454
1421 op->map->dirty = true; 1455 op->map->dirty = true;
1422 1456
1423 if (object *pl = ms.player ()) 1457 if (object *pl = ms.player ())
1424 pl->contr->ns->floorbox_update (); 1458 esrv_send_item (pl, op);
1425 1459
1426 /* If this object glows, it may affect lighting conditions that are 1460 /* If this object glows, it may affect lighting conditions that are
1427 * visible to others on this map. But update_all_los is really 1461 * visible to others on this map. But update_all_los is really
1428 * an inefficient way to do this, as it means los for all players 1462 * an inefficient way to do this, as it means los for all players
1429 * on the map will get recalculated. The players could very well 1463 * on the map will get recalculated. The players could very well
1494 return where->env->insert (this); 1528 return where->env->insert (this);
1495 else 1529 else
1496 return where->map->insert (this, where->x, where->y, originator, flags); 1530 return where->map->insert (this, where->x, where->y, originator, flags);
1497} 1531}
1498 1532
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/* 1533/*
1535 * decrease(object, number) decreases a specified number from 1534 * decrease(object, number) decreases a specified number from
1536 * the amount of an object. If the amount reaches 0, the object 1535 * the amount of an object. If the amount reaches 0, the object
1537 * is subsequently removed and freed. 1536 * is subsequently removed and freed.
1538 * 1537 *
1638 if (object::can_merge (tmp, op)) 1637 if (object::can_merge (tmp, op))
1639 { 1638 {
1640 /* return the original object and remove inserted object 1639 /* return the original object and remove inserted object
1641 (client needs the original object) */ 1640 (client needs the original object) */
1642 tmp->nrof += op->nrof; 1641 tmp->nrof += op->nrof;
1642
1643 if (object *pl = tmp->visible_to ())
1644 esrv_update_item (UPD_NROF, pl, tmp);
1645
1643 adjust_weight (this, op->total_weight ()); 1646 adjust_weight (this, op->total_weight ());
1644 1647
1645 op->destroy (1); 1648 op->destroy (1);
1646 op = tmp; 1649 op = tmp;
1647 goto inserted; 1650 goto inserted;
1661 1664
1662 inv = op; 1665 inv = op;
1663 1666
1664 op->flag [FLAG_REMOVED] = 0; 1667 op->flag [FLAG_REMOVED] = 0;
1665 1668
1669 if (object *pl = op->visible_to ())
1670 esrv_send_item (pl, op);
1671
1666 adjust_weight (this, op->total_weight ()); 1672 adjust_weight (this, op->total_weight ());
1667 1673
1668inserted: 1674inserted:
1669 /* reset the light list and los of the players on the map */ 1675 /* reset the light list and los of the players on the map */
1670 if (op->glow_radius && map && map->darkness) 1676 if (op->glow_radius && map && map->darkness)
1671 update_all_los (map, x, y); 1677 update_all_los (map, x, y);
1672 1678
1673 if (object *otmp = in_player ()) 1679 // if this is a player's inventory, update stats
1674 if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1680 if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER])
1675 otmp->update_stats (); 1681 update_stats ();
1676 1682
1677 INVOKE_OBJECT (INSERT, this); 1683 INVOKE_OBJECT (INSERT, this);
1678 1684
1679 return op; 1685 return op;
1680} 1686}
2558 &name, 2564 &name,
2559 title ? "\",title:\"" : "", 2565 title ? "\",title:\"" : "",
2560 title ? (const char *)title : "", 2566 title ? (const char *)title : "",
2561 flag_desc (flagdesc, 512), type); 2567 flag_desc (flagdesc, 512), type);
2562 2568
2563 if (!this->flag[FLAG_REMOVED] && env) 2569 if (!flag[FLAG_REMOVED] && env)
2564 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); 2570 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2565 2571
2566 if (map) 2572 if (map)
2567 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); 2573 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y);
2568 2574
2610 if (object *closer = old_container->inv) 2616 if (object *closer = old_container->inv)
2611 if (closer->type == CLOSE_CON) 2617 if (closer->type == CLOSE_CON)
2612 closer->destroy (); 2618 closer->destroy ();
2613#endif 2619#endif
2614 2620
2615 old_container->flag [FLAG_APPLIED] = 0; 2621 old_container->flag [FLAG_APPLIED] = false;
2616 container = 0; 2622 container = 0;
2617 2623
2618 esrv_update_item (UPD_FLAGS, this, old_container); 2624 esrv_update_item (UPD_FLAGS, this, old_container);
2619 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2625 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container));
2620 play_sound (sound_find ("chest_close")); 2626 play_sound (sound_find ("chest_close"));
2636 } 2642 }
2637#endif 2643#endif
2638 2644
2639 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2645 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container));
2640 2646
2641 new_container->flag [FLAG_APPLIED] = 1; 2647 new_container->flag [FLAG_APPLIED] = true;
2642 container = new_container; 2648 container = new_container;
2643 2649
2644 esrv_update_item (UPD_FLAGS, this, new_container); 2650 esrv_update_item (UPD_FLAGS, this, new_container);
2645 esrv_send_inventory (this, new_container); 2651 esrv_send_inventory (this, new_container);
2646 play_sound (sound_find ("chest_open")); 2652 play_sound (sound_find ("chest_open"));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines