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.220 by root, Thu Apr 24 00:30:52 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 if (object *pl = visible_to ())
1079 esrv_del_item (pl->contr, count);
1080
1077 adjust_weight (env, -total_weight ()); 1081 adjust_weight (env, -total_weight ());
1078 1082
1079 *(above ? &above->below : &env->inv) = below; 1083 *(above ? &above->below : &env->inv) = below;
1080 1084
1081 if (below) 1085 if (below)
1099 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1103 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER))
1100 otmp->update_stats (); 1104 otmp->update_stats ();
1101 } 1105 }
1102 else if (map) 1106 else if (map)
1103 { 1107 {
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; 1108 map->dirty = true;
1117 mapspace &ms = this->ms (); 1109 mapspace &ms = this->ms ();
1110
1111 if (object *pl = ms.player ())
1112 {
1113 if (type == PLAYER) // this == pl(!)
1114 {
1115 // leaving a spot always closes any open container on the ground
1116 if (container && !container->env)
1117 // this causes spurious floorbox updates, but it ensures
1118 // that the CLOSE event is being sent.
1119 close_container ();
1120
1121 --map->players;
1122 map->touch ();
1123 }
1124 else if (pl->container == this)
1125 {
1126 // removing a container should close it
1127 close_container ();
1128 }
1129
1130 esrv_del_item (pl->contr, count);
1131 }
1118 1132
1119 /* link the object above us */ 1133 /* link the object above us */
1120 if (above) 1134 if (above)
1121 above->below = below; 1135 above->below = below;
1122 else 1136 else
1152 * removed (most likely destroyed), update the player view 1166 * removed (most likely destroyed), update the player view
1153 * appropriately. 1167 * appropriately.
1154 */ 1168 */
1155 pl->close_container (); 1169 pl->close_container ();
1156 1170
1157 pl->contr->ns->floorbox_update (); 1171 //TODO: the floorbox prev/next might need updating
1172 esrv_del_item (pl->contr, count);
1158 } 1173 }
1159 1174
1160 for (tmp = ms.bot; tmp; tmp = tmp->above) 1175 for (tmp = ms.bot; tmp; tmp = tmp->above)
1161 { 1176 {
1162 /* No point updating the players look faces if he is the object 1177 /* No point updating the players look faces if he is the object
1288object * 1303object *
1289insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1304insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1290{ 1305{
1291 assert (!op->flag [FLAG_FREED]); 1306 assert (!op->flag [FLAG_FREED]);
1292 1307
1293 object *top, *floor = NULL;
1294
1295 op->remove (); 1308 op->remove ();
1296 1309
1297 /* Ideally, the caller figures this out. However, it complicates a lot 1310 /* 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 1311 * of areas of callers (eg, anything that uses find_free_spot would now
1299 * need extra work 1312 * need extra work
1300 */ 1313 */
1301 if (!xy_normalise (m, op->x, op->y)) 1314 if (!xy_normalise (m, op->x, op->y))
1302 { 1315 {
1303 op->destroy (); 1316 op->destroy (1);
1304 return 0; 1317 return 0;
1305 } 1318 }
1306 1319
1307 if (object *more = op->more) 1320 if (object *more = op->more)
1308 if (!insert_ob_in_map (more, m, originator, flag)) 1321 if (!insert_ob_in_map (more, m, originator, flag))
1317 */ 1330 */
1318 if (op->nrof && !(flag & INS_NO_MERGE)) 1331 if (op->nrof && !(flag & INS_NO_MERGE))
1319 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 1332 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1320 if (object::can_merge (op, tmp)) 1333 if (object::can_merge (op, tmp))
1321 { 1334 {
1335 // TODO: we atcually want to update tmp, not op,
1336 // but some caller surely breaks when we return tmp
1337 // from here :/
1322 op->nrof += tmp->nrof; 1338 op->nrof += tmp->nrof;
1323 tmp->destroy (1); 1339 tmp->destroy (1);
1324 } 1340 }
1325 1341
1326 CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ 1342 CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */
1348 /* since *below* originator, no need to update top */ 1364 /* since *below* originator, no need to update top */
1349 originator->below = op; 1365 originator->below = op;
1350 } 1366 }
1351 else 1367 else
1352 { 1368 {
1369 object *top, *floor = NULL;
1370
1353 top = ms.bot; 1371 top = ms.bot;
1354 1372
1355 /* If there are other objects, then */ 1373 /* If there are other objects, then */
1356 if (top) 1374 if (top)
1357 { 1375 {
1456 } 1474 }
1457 1475
1458 op->map->dirty = true; 1476 op->map->dirty = true;
1459 1477
1460 if (object *pl = ms.player ()) 1478 if (object *pl = ms.player ())
1461 pl->contr->ns->floorbox_update (); 1479 //TODO: the floorbox prev/next might need updating
1480 esrv_send_item (pl, op);
1462 1481
1463 /* If this object glows, it may affect lighting conditions that are 1482 /* If this object glows, it may affect lighting conditions that are
1464 * visible to others on this map. But update_all_los is really 1483 * 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 1484 * 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 1485 * on the map will get recalculated. The players could very well
2567 &name, 2586 &name,
2568 title ? "\",title:\"" : "", 2587 title ? "\",title:\"" : "",
2569 title ? (const char *)title : "", 2588 title ? (const char *)title : "",
2570 flag_desc (flagdesc, 512), type); 2589 flag_desc (flagdesc, 512), type);
2571 2590
2572 if (!this->flag[FLAG_REMOVED] && env) 2591 if (!flag[FLAG_REMOVED] && env)
2573 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); 2592 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2574 2593
2575 if (map) 2594 if (map)
2576 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); 2595 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y);
2577 2596
2607object::open_container (object *new_container) 2626object::open_container (object *new_container)
2608{ 2627{
2609 if (container == new_container) 2628 if (container == new_container)
2610 return; 2629 return;
2611 2630
2612 if (object *old_container = container) 2631 object *old_container = container;
2632
2633 if (old_container)
2613 { 2634 {
2614 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) 2635 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this)))
2615 return; 2636 return;
2616 2637
2617#if 0 2638#if 0
2619 if (object *closer = old_container->inv) 2640 if (object *closer = old_container->inv)
2620 if (closer->type == CLOSE_CON) 2641 if (closer->type == CLOSE_CON)
2621 closer->destroy (); 2642 closer->destroy ();
2622#endif 2643#endif
2623 2644
2645 // make sure the container is available
2646 esrv_send_item (this, old_container);
2647
2624 old_container->flag [FLAG_APPLIED] = 0; 2648 old_container->flag [FLAG_APPLIED] = false;
2625 container = 0; 2649 container = 0;
2626 2650
2651 // client needs item update to make it work, client bug requires this to be separate
2627 esrv_update_item (UPD_FLAGS, this, old_container); 2652 esrv_update_item (UPD_FLAGS, this, old_container);
2653
2628 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2654 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container));
2629 play_sound (sound_find ("chest_close")); 2655 play_sound (sound_find ("chest_close"));
2630 } 2656 }
2631 2657
2632 if (new_container) 2658 if (new_container)
2645 } 2671 }
2646#endif 2672#endif
2647 2673
2648 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2674 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container));
2649 2675
2676 // make sure the container is available, client bug requires this to be separate
2677 esrv_send_item (this, new_container);
2678
2650 new_container->flag [FLAG_APPLIED] = 1; 2679 new_container->flag [FLAG_APPLIED] = true;
2651 container = new_container; 2680 container = new_container;
2652 2681
2682 // client needs flag change
2653 esrv_update_item (UPD_FLAGS, this, new_container); 2683 esrv_update_item (UPD_FLAGS, this, new_container);
2654 esrv_send_inventory (this, new_container); 2684 esrv_send_inventory (this, new_container);
2655 play_sound (sound_find ("chest_open")); 2685 play_sound (sound_find ("chest_open"));
2656 } 2686 }
2687// else if (!old_container->env && contr && contr->ns)
2688// contr->ns->floorbox_reset ();
2657} 2689}
2658 2690
2659object * 2691object *
2660object::force_find (const shstr name) 2692object::force_find (const shstr name)
2661{ 2693{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines