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.214 by root, Tue Apr 22 07:01:46 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}
391 return; 392 return;
392 393
393 op->carrying += weight; 394 op->carrying += weight;
394 395
395 if (object *pl = op->visible_to ()) 396 if (object *pl = op->visible_to ())
397 if (pl != op) // player is handled lazily
396 esrv_update_item (UPD_WEIGHT, pl, op); 398 esrv_update_item (UPD_WEIGHT, pl, op);
397 399
398 op = op->env; 400 op = op->env;
399 } 401 }
400} 402}
401 403
422 if (sum != carrying) 424 if (sum != carrying)
423 { 425 {
424 carrying = sum; 426 carrying = sum;
425 427
426 if (object *pl = visible_to ()) 428 if (object *pl = visible_to ())
429 if (pl != this) // player is handled lazily
427 esrv_update_item (UPD_WEIGHT, pl, this); 430 esrv_update_item (UPD_WEIGHT, pl, this);
428 } 431 }
429} 432}
430 433
431/* 434/*
432 * Used by: Server DM commands: dumpbelow, dump. Some error messages. 435 * Used by: Server DM commands: dumpbelow, dump. Some error messages.
915object::destroy_inv (bool drop_to_ground) 918object::destroy_inv (bool drop_to_ground)
916{ 919{
917 // need to check first, because the checks below might segfault 920 // need to check first, because the checks below might segfault
918 // as we might be on an invalid mapspace and crossfire code 921 // as we might be on an invalid mapspace and crossfire code
919 // is too buggy to ensure that the inventory is empty. 922 // is too buggy to ensure that the inventory is empty.
920 // corollary: if you create arrows etc. with stuff in tis inventory, 923 // corollary: if you create arrows etc. with stuff in its inventory,
921 // cf will crash below with off-map x and y 924 // cf will crash below with off-map x and y
922 if (!inv) 925 if (!inv)
923 return; 926 return;
924 927
925 /* Only if the space blocks everything do we not process - 928 /* Only if the space blocks everything do we not process -
932 || map->nodrop 935 || map->nodrop
933 || ms ().move_block == MOVE_ALL) 936 || ms ().move_block == MOVE_ALL)
934 { 937 {
935 while (inv) 938 while (inv)
936 { 939 {
937 inv->destroy_inv (drop_to_ground); 940 inv->destroy_inv (false);
938 inv->destroy (); 941 inv->destroy ();
939 } 942 }
940 } 943 }
941 else 944 else
942 { /* Put objects in inventory onto this space */ 945 { /* Put objects in inventory onto this space */
948 || op->flag [FLAG_NO_DROP] 951 || op->flag [FLAG_NO_DROP]
949 || op->type == RUNE 952 || op->type == RUNE
950 || op->type == TRAP 953 || op->type == TRAP
951 || op->flag [FLAG_IS_A_TEMPLATE] 954 || op->flag [FLAG_IS_A_TEMPLATE]
952 || op->flag [FLAG_DESTROY_ON_DEATH]) 955 || op->flag [FLAG_DESTROY_ON_DEATH])
953 op->destroy (); 956 op->destroy (true);
954 else 957 else
955 map->insert (op, x, y); 958 map->insert (op, x, y);
956 } 959 }
957 } 960 }
958} 961}
974 remove_friendly_object (this); 977 remove_friendly_object (this);
975 978
976 remove (); 979 remove ();
977 980
978 attachable::do_destroy (); 981 attachable::do_destroy ();
979
980 destroy_inv (true);
981 982
982 deactivate (); 983 deactivate ();
983 unlink (); 984 unlink ();
984 985
985 flag [FLAG_FREED] = 1; 986 flag [FLAG_FREED] = 1;
1026object::destroy (bool destroy_inventory) 1027object::destroy (bool destroy_inventory)
1027{ 1028{
1028 if (destroyed ()) 1029 if (destroyed ())
1029 return; 1030 return;
1030 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
1031 if (destroy_inventory) 1038 destroy_inv (!destroy_inventory);
1032 destroy_inv (false);
1033 1039
1034 if (is_head ()) 1040 if (is_head ())
1035 if (sound_destroy) 1041 if (sound_destroy)
1036 play_sound (sound_destroy); 1042 play_sound (sound_destroy);
1037 else if (flag [FLAG_MONSTER]) 1043 else if (flag [FLAG_MONSTER])
1056 if (flag [FLAG_REMOVED]) 1062 if (flag [FLAG_REMOVED])
1057 return; 1063 return;
1058 1064
1059 INVOKE_OBJECT (REMOVE, this); 1065 INVOKE_OBJECT (REMOVE, this);
1060 1066
1061 if (object *pl = visible_to ())
1062 esrv_del_item (pl->contr, count);
1063
1064 flag [FLAG_REMOVED] = true; 1067 flag [FLAG_REMOVED] = true;
1065 1068
1066 if (more) 1069 if (more)
1067 more->remove (); 1070 more->remove ();
1068 1071
1070 * In this case, the object to be removed is in someones 1073 * In this case, the object to be removed is in someones
1071 * inventory. 1074 * inventory.
1072 */ 1075 */
1073 if (env) 1076 if (env)
1074 { 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
1075 adjust_weight (env, -total_weight ()); 1083 adjust_weight (env, -total_weight ());
1076 1084
1077 *(above ? &above->below : &env->inv) = below; 1085 *(above ? &above->below : &env->inv) = below;
1078 1086
1079 if (below) 1087 if (below)
1097 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))
1098 otmp->update_stats (); 1106 otmp->update_stats ();
1099 } 1107 }
1100 else if (map) 1108 else if (map)
1101 { 1109 {
1102 if (type == PLAYER)
1103 {
1104 // leaving a spot always closes any open container on the ground
1105 if (container && !container->env)
1106 // this causes spurious floorbox updates, but it ensures
1107 // that the CLOSE event is being sent.
1108 close_container ();
1109
1110 --map->players;
1111 map->touch ();
1112 }
1113
1114 map->dirty = true; 1110 map->dirty = true;
1115 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 }
1116 1134
1117 /* link the object above us */ 1135 /* link the object above us */
1118 if (above) 1136 if (above)
1119 above->below = below; 1137 above->below = below;
1120 else 1138 else
1150 * removed (most likely destroyed), update the player view 1168 * removed (most likely destroyed), update the player view
1151 * appropriately. 1169 * appropriately.
1152 */ 1170 */
1153 pl->close_container (); 1171 pl->close_container ();
1154 1172
1155 pl->contr->ns->floorbox_update (); 1173 //TODO: the floorbox prev/next might need updating
1174 esrv_del_item (pl->contr, count);
1156 } 1175 }
1157 1176
1158 for (tmp = ms.bot; tmp; tmp = tmp->above) 1177 for (tmp = ms.bot; tmp; tmp = tmp->above)
1159 { 1178 {
1160 /* 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
1286object * 1305object *
1287insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1306insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1288{ 1307{
1289 assert (!op->flag [FLAG_FREED]); 1308 assert (!op->flag [FLAG_FREED]);
1290 1309
1291 object *top, *floor = NULL;
1292
1293 op->remove (); 1310 op->remove ();
1294 1311
1295 /* Ideally, the caller figures this out. However, it complicates a lot 1312 /* Ideally, the caller figures this out. However, it complicates a lot
1296 * 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
1297 * need extra work 1314 * need extra work
1298 */ 1315 */
1299 if (!xy_normalise (m, op->x, op->y)) 1316 if (!xy_normalise (m, op->x, op->y))
1300 { 1317 {
1301 op->destroy (); 1318 op->destroy (1);
1302 return 0; 1319 return 0;
1303 } 1320 }
1304 1321
1305 if (object *more = op->more) 1322 if (object *more = op->more)
1306 if (!insert_ob_in_map (more, m, originator, flag)) 1323 if (!insert_ob_in_map (more, m, originator, flag))
1315 */ 1332 */
1316 if (op->nrof && !(flag & INS_NO_MERGE)) 1333 if (op->nrof && !(flag & INS_NO_MERGE))
1317 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 1334 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1318 if (object::can_merge (op, tmp)) 1335 if (object::can_merge (op, tmp))
1319 { 1336 {
1337 // TODO: we atcually want to update tmp, not op,
1338 // but some caller surely breaks when we return tmp
1339 // from here :/
1320 op->nrof += tmp->nrof; 1340 op->nrof += tmp->nrof;
1321 tmp->destroy (1); 1341 tmp->destroy (1);
1322 } 1342 }
1323 1343
1324 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 */
1346 /* since *below* originator, no need to update top */ 1366 /* since *below* originator, no need to update top */
1347 originator->below = op; 1367 originator->below = op;
1348 } 1368 }
1349 else 1369 else
1350 { 1370 {
1371 object *top, *floor = NULL;
1372
1351 top = ms.bot; 1373 top = ms.bot;
1352 1374
1353 /* If there are other objects, then */ 1375 /* If there are other objects, then */
1354 if (top) 1376 if (top)
1355 { 1377 {
1454 } 1476 }
1455 1477
1456 op->map->dirty = true; 1478 op->map->dirty = true;
1457 1479
1458 if (object *pl = ms.player ()) 1480 if (object *pl = ms.player ())
1459 pl->contr->ns->floorbox_update (); 1481 //TODO: the floorbox prev/next might need updating
1482 esrv_send_item (pl, op);
1460 1483
1461 /* If this object glows, it may affect lighting conditions that are 1484 /* If this object glows, it may affect lighting conditions that are
1462 * 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
1463 * 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
1464 * on the map will get recalculated. The players could very well 1487 * on the map will get recalculated. The players could very well
2565 &name, 2588 &name,
2566 title ? "\",title:\"" : "", 2589 title ? "\",title:\"" : "",
2567 title ? (const char *)title : "", 2590 title ? (const char *)title : "",
2568 flag_desc (flagdesc, 512), type); 2591 flag_desc (flagdesc, 512), type);
2569 2592
2570 if (!this->flag[FLAG_REMOVED] && env) 2593 if (!flag[FLAG_REMOVED] && env)
2571 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); 2594 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2572 2595
2573 if (map) 2596 if (map)
2574 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);
2575 2598
2605object::open_container (object *new_container) 2628object::open_container (object *new_container)
2606{ 2629{
2607 if (container == new_container) 2630 if (container == new_container)
2608 return; 2631 return;
2609 2632
2610 if (object *old_container = container) 2633 object *old_container = container;
2634
2635 if (old_container)
2611 { 2636 {
2612 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) 2637 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this)))
2613 return; 2638 return;
2614 2639
2615#if 0 2640#if 0
2617 if (object *closer = old_container->inv) 2642 if (object *closer = old_container->inv)
2618 if (closer->type == CLOSE_CON) 2643 if (closer->type == CLOSE_CON)
2619 closer->destroy (); 2644 closer->destroy ();
2620#endif 2645#endif
2621 2646
2647 // make sure the container is available
2648 esrv_send_item (this, old_container);
2649
2622 old_container->flag [FLAG_APPLIED] = 0; 2650 old_container->flag [FLAG_APPLIED] = false;
2623 container = 0; 2651 container = 0;
2624 2652
2653 // client needs item update to make it work, client bug requires this to be separate
2625 esrv_update_item (UPD_FLAGS, this, old_container); 2654 esrv_update_item (UPD_FLAGS, this, old_container);
2655
2626 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));
2627 play_sound (sound_find ("chest_close")); 2657 play_sound (sound_find ("chest_close"));
2628 } 2658 }
2629 2659
2630 if (new_container) 2660 if (new_container)
2643 } 2673 }
2644#endif 2674#endif
2645 2675
2646 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));
2647 2677
2678 // make sure the container is available, client bug requires this to be separate
2679 esrv_send_item (this, new_container);
2680
2648 new_container->flag [FLAG_APPLIED] = 1; 2681 new_container->flag [FLAG_APPLIED] = true;
2649 container = new_container; 2682 container = new_container;
2650 2683
2684 // client needs flag change
2651 esrv_update_item (UPD_FLAGS, this, new_container); 2685 esrv_update_item (UPD_FLAGS, this, new_container);
2652 esrv_send_inventory (this, new_container); 2686 esrv_send_inventory (this, new_container);
2653 play_sound (sound_find ("chest_open")); 2687 play_sound (sound_find ("chest_open"));
2654 } 2688 }
2689// else if (!old_container->env && contr && contr->ns)
2690// contr->ns->floorbox_reset ();
2655} 2691}
2656 2692
2657object * 2693object *
2658object::force_find (const shstr name) 2694object::force_find (const shstr name)
2659{ 2695{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines