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.215 by root, Tue Apr 22 07:28:05 2008 UTC vs.
Revision 1.221 by root, Thu Apr 24 12:06:01 2008 UTC

334 334
335// find player who can see this object 335// find player who can see this object
336object * 336object *
337object::visible_to () const 337object::visible_to () const
338{ 338{
339 if (!flag [FLAG_REMOVED]) 339 if (client_visible () && !flag [FLAG_REMOVED])
340 { 340 {
341 // see if we are in a container of sorts 341 // see if we are in a container of sorts
342 if (env) 342 if (env)
343 { 343 {
344 // the player inventory itself is always visible 344 // the player inventory itself is always visible
358 else 358 else
359 { 359 {
360 // maybe there is a player standing on the same mapspace 360 // maybe there is a player standing on the same mapspace
361 // this will catch the case where "this" is a player 361 // this will catch the case where "this" is a player
362 if (object *pl = ms ().player ()) 362 if (object *pl = ms ().player ())
363 if (!pl->container || this == pl->container)
363 return pl; 364 return pl;
364 } 365 }
365 } 366 }
366 367
367 return 0; 368 return 0;
368} 369}
917object::destroy_inv (bool drop_to_ground) 918object::destroy_inv (bool drop_to_ground)
918{ 919{
919 // need to check first, because the checks below might segfault 920 // need to check first, because the checks below might segfault
920 // as we might be on an invalid mapspace and crossfire code 921 // as we might be on an invalid mapspace and crossfire code
921 // is too buggy to ensure that the inventory is empty. 922 // is too buggy to ensure that the inventory is empty.
922 // corollary: if you create arrows etc. with stuff in tis inventory, 923 // corollary: if you create arrows etc. with stuff in its inventory,
923 // cf will crash below with off-map x and y 924 // cf will crash below with off-map x and y
924 if (!inv) 925 if (!inv)
925 return; 926 return;
926 927
927 /* Only if the space blocks everything do we not process - 928 /* Only if the space blocks everything do we not process -
934 || map->nodrop 935 || map->nodrop
935 || ms ().move_block == MOVE_ALL) 936 || ms ().move_block == MOVE_ALL)
936 { 937 {
937 while (inv) 938 while (inv)
938 { 939 {
939 inv->destroy_inv (drop_to_ground); 940 inv->destroy_inv (false);
940 inv->destroy (); 941 inv->destroy ();
941 } 942 }
942 } 943 }
943 else 944 else
944 { /* Put objects in inventory onto this space */ 945 { /* Put objects in inventory onto this space */
950 || op->flag [FLAG_NO_DROP] 951 || op->flag [FLAG_NO_DROP]
951 || op->type == RUNE 952 || op->type == RUNE
952 || op->type == TRAP 953 || op->type == TRAP
953 || op->flag [FLAG_IS_A_TEMPLATE] 954 || op->flag [FLAG_IS_A_TEMPLATE]
954 || op->flag [FLAG_DESTROY_ON_DEATH]) 955 || op->flag [FLAG_DESTROY_ON_DEATH])
955 op->destroy (); 956 op->destroy (true);
956 else 957 else
957 map->insert (op, x, y); 958 map->insert (op, x, y);
958 } 959 }
959 } 960 }
960} 961}
976 remove_friendly_object (this); 977 remove_friendly_object (this);
977 978
978 remove (); 979 remove ();
979 980
980 attachable::do_destroy (); 981 attachable::do_destroy ();
981
982 destroy_inv (true);
983 982
984 deactivate (); 983 deactivate ();
985 unlink (); 984 unlink ();
986 985
987 flag [FLAG_FREED] = 1; 986 flag [FLAG_FREED] = 1;
1028object::destroy (bool destroy_inventory) 1027object::destroy (bool destroy_inventory)
1029{ 1028{
1030 if (destroyed ()) 1029 if (destroyed ())
1031 return; 1030 return;
1032 1031
1032 if (!is_head () && !head->destroyed ())
1033 {
1034 LOG (llevError | logBacktrace, "tried to destroy the tail of an object");
1035 head->destroy (destroy_inventory);
1036 }
1037
1033 if (destroy_inventory) 1038 destroy_inv (!destroy_inventory);
1034 destroy_inv (false);
1035 1039
1036 if (is_head ()) 1040 if (is_head ())
1037 if (sound_destroy) 1041 if (sound_destroy)
1038 play_sound (sound_destroy); 1042 play_sound (sound_destroy);
1039 else if (flag [FLAG_MONSTER]) 1043 else if (flag [FLAG_MONSTER])
1058 if (flag [FLAG_REMOVED]) 1062 if (flag [FLAG_REMOVED])
1059 return; 1063 return;
1060 1064
1061 INVOKE_OBJECT (REMOVE, this); 1065 INVOKE_OBJECT (REMOVE, this);
1062 1066
1063 if (object *pl = visible_to ())
1064 esrv_del_item (pl->contr, count);
1065
1066 flag [FLAG_REMOVED] = true; 1067 flag [FLAG_REMOVED] = true;
1067 1068
1068 if (more) 1069 if (more)
1069 more->remove (); 1070 more->remove ();
1070 1071
1072 * In this case, the object to be removed is in someones 1073 * In this case, the object to be removed is in someones
1073 * inventory. 1074 * inventory.
1074 */ 1075 */
1075 if (env) 1076 if (env)
1076 { 1077 {
1078 flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed
1079 if (object *pl = visible_to ())
1080 esrv_del_item (pl->contr, count);
1081 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1082
1077 adjust_weight (env, -total_weight ()); 1083 adjust_weight (env, -total_weight ());
1078 1084
1079 *(above ? &above->below : &env->inv) = below; 1085 *(above ? &above->below : &env->inv) = below;
1080 1086
1081 if (below) 1087 if (below)
1099 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1105 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER))
1100 otmp->update_stats (); 1106 otmp->update_stats ();
1101 } 1107 }
1102 else if (map) 1108 else if (map)
1103 { 1109 {
1104 if (type == PLAYER)
1105 {
1106 // leaving a spot always closes any open container on the ground
1107 if (container && !container->env)
1108 // this causes spurious floorbox updates, but it ensures
1109 // that the CLOSE event is being sent.
1110 close_container ();
1111
1112 --map->players;
1113 map->touch ();
1114 }
1115
1116 map->dirty = true; 1110 map->dirty = true;
1117 mapspace &ms = this->ms (); 1111 mapspace &ms = this->ms ();
1112
1113 if (object *pl = ms.player ())
1114 {
1115 if (type == PLAYER) // this == pl(!)
1116 {
1117 // leaving a spot always closes any open container on the ground
1118 if (container && !container->env)
1119 // this causes spurious floorbox updates, but it ensures
1120 // that the CLOSE event is being sent.
1121 close_container ();
1122
1123 --map->players;
1124 map->touch ();
1125 }
1126 else if (pl->container == this)
1127 {
1128 // removing a container should close it
1129 close_container ();
1130 }
1131
1132 esrv_del_item (pl->contr, count);
1133 }
1118 1134
1119 /* link the object above us */ 1135 /* link the object above us */
1120 if (above) 1136 if (above)
1121 above->below = below; 1137 above->below = below;
1122 else 1138 else
1152 * removed (most likely destroyed), update the player view 1168 * removed (most likely destroyed), update the player view
1153 * appropriately. 1169 * appropriately.
1154 */ 1170 */
1155 pl->close_container (); 1171 pl->close_container ();
1156 1172
1157 pl->contr->ns->floorbox_update (); 1173 //TODO: the floorbox prev/next might need updating
1174 esrv_del_item (pl->contr, count);
1158 } 1175 }
1159 1176
1160 for (tmp = ms.bot; tmp; tmp = tmp->above) 1177 for (tmp = ms.bot; tmp; tmp = tmp->above)
1161 { 1178 {
1162 /* No point updating the players look faces if he is the object 1179 /* No point updating the players look faces if he is the object
1288object * 1305object *
1289insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1306insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1290{ 1307{
1291 assert (!op->flag [FLAG_FREED]); 1308 assert (!op->flag [FLAG_FREED]);
1292 1309
1293 object *top, *floor = NULL;
1294
1295 op->remove (); 1310 op->remove ();
1296 1311
1297 /* Ideally, the caller figures this out. However, it complicates a lot 1312 /* Ideally, the caller figures this out. However, it complicates a lot
1298 * of areas of callers (eg, anything that uses find_free_spot would now 1313 * of areas of callers (eg, anything that uses find_free_spot would now
1299 * need extra work 1314 * need extra work
1300 */ 1315 */
1301 if (!xy_normalise (m, op->x, op->y)) 1316 if (!xy_normalise (m, op->x, op->y))
1302 { 1317 {
1303 op->destroy (); 1318 op->destroy (1);
1304 return 0; 1319 return 0;
1305 } 1320 }
1306 1321
1307 if (object *more = op->more) 1322 if (object *more = op->more)
1308 if (!insert_ob_in_map (more, m, originator, flag)) 1323 if (!insert_ob_in_map (more, m, originator, flag))
1317 */ 1332 */
1318 if (op->nrof && !(flag & INS_NO_MERGE)) 1333 if (op->nrof && !(flag & INS_NO_MERGE))
1319 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 1334 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1320 if (object::can_merge (op, tmp)) 1335 if (object::can_merge (op, tmp))
1321 { 1336 {
1337 // TODO: we atcually want to update tmp, not op,
1338 // but some caller surely breaks when we return tmp
1339 // from here :/
1322 op->nrof += tmp->nrof; 1340 op->nrof += tmp->nrof;
1323 tmp->destroy (1); 1341 tmp->destroy (1);
1324 } 1342 }
1325 1343
1326 CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ 1344 CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */
1348 /* since *below* originator, no need to update top */ 1366 /* since *below* originator, no need to update top */
1349 originator->below = op; 1367 originator->below = op;
1350 } 1368 }
1351 else 1369 else
1352 { 1370 {
1371 object *top, *floor = NULL;
1372
1353 top = ms.bot; 1373 top = ms.bot;
1354 1374
1355 /* If there are other objects, then */ 1375 /* If there are other objects, then */
1356 if (top) 1376 if (top)
1357 { 1377 {
1456 } 1476 }
1457 1477
1458 op->map->dirty = true; 1478 op->map->dirty = true;
1459 1479
1460 if (object *pl = ms.player ()) 1480 if (object *pl = ms.player ())
1461 pl->contr->ns->floorbox_update (); 1481 //TODO: the floorbox prev/next might need updating
1482 esrv_send_item (pl, op);
1462 1483
1463 /* If this object glows, it may affect lighting conditions that are 1484 /* If this object glows, it may affect lighting conditions that are
1464 * visible to others on this map. But update_all_los is really 1485 * visible to others on this map. But update_all_los is really
1465 * an inefficient way to do this, as it means los for all players 1486 * an inefficient way to do this, as it means los for all players
1466 * on the map will get recalculated. The players could very well 1487 * on the map will get recalculated. The players could very well
2567 &name, 2588 &name,
2568 title ? "\",title:\"" : "", 2589 title ? "\",title:\"" : "",
2569 title ? (const char *)title : "", 2590 title ? (const char *)title : "",
2570 flag_desc (flagdesc, 512), type); 2591 flag_desc (flagdesc, 512), type);
2571 2592
2572 if (!this->flag[FLAG_REMOVED] && env) 2593 if (!flag[FLAG_REMOVED] && env)
2573 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); 2594 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2574 2595
2575 if (map) 2596 if (map)
2576 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); 2597 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y);
2577 2598
2607object::open_container (object *new_container) 2628object::open_container (object *new_container)
2608{ 2629{
2609 if (container == new_container) 2630 if (container == new_container)
2610 return; 2631 return;
2611 2632
2612 if (object *old_container = container) 2633 object *old_container = container;
2634
2635 if (old_container)
2613 { 2636 {
2614 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) 2637 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this)))
2615 return; 2638 return;
2616 2639
2617#if 0 2640#if 0
2619 if (object *closer = old_container->inv) 2642 if (object *closer = old_container->inv)
2620 if (closer->type == CLOSE_CON) 2643 if (closer->type == CLOSE_CON)
2621 closer->destroy (); 2644 closer->destroy ();
2622#endif 2645#endif
2623 2646
2647 // make sure the container is available
2648 esrv_send_item (this, old_container);
2649
2624 old_container->flag [FLAG_APPLIED] = 0; 2650 old_container->flag [FLAG_APPLIED] = false;
2625 container = 0; 2651 container = 0;
2626 2652
2653 // client needs item update to make it work, client bug requires this to be separate
2627 esrv_update_item (UPD_FLAGS, this, old_container); 2654 esrv_update_item (UPD_FLAGS, this, old_container);
2655
2628 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2656 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container));
2629 play_sound (sound_find ("chest_close")); 2657 play_sound (sound_find ("chest_close"));
2630 } 2658 }
2631 2659
2632 if (new_container) 2660 if (new_container)
2645 } 2673 }
2646#endif 2674#endif
2647 2675
2648 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2676 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container));
2649 2677
2678 // make sure the container is available, client bug requires this to be separate
2679 esrv_send_item (this, new_container);
2680
2650 new_container->flag [FLAG_APPLIED] = 1; 2681 new_container->flag [FLAG_APPLIED] = true;
2651 container = new_container; 2682 container = new_container;
2652 2683
2684 // client needs flag change
2653 esrv_update_item (UPD_FLAGS, this, new_container); 2685 esrv_update_item (UPD_FLAGS, this, new_container);
2654 esrv_send_inventory (this, new_container); 2686 esrv_send_inventory (this, new_container);
2655 play_sound (sound_find ("chest_open")); 2687 play_sound (sound_find ("chest_open"));
2656 } 2688 }
2689// else if (!old_container->env && contr && contr->ns)
2690// contr->ns->floorbox_reset ();
2657} 2691}
2658 2692
2659object * 2693object *
2660object::force_find (const shstr name) 2694object::force_find (const shstr name)
2661{ 2695{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines