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.208 by root, Mon Apr 21 06:16:01 2008 UTC vs.
Revision 1.224 by root, Fri May 2 20:16:24 2008 UTC

24#include <global.h> 24#include <global.h>
25#include <stdio.h> 25#include <stdio.h>
26#include <sys/types.h> 26#include <sys/types.h>
27#include <sys/uio.h> 27#include <sys/uio.h>
28#include <object.h> 28#include <object.h>
29#include <funcpoint.h>
30#include <sproto.h> 29#include <sproto.h>
31#include <loader.h> 30#include <loader.h>
32 31
33#include <bitset> 32#include <bitset>
34 33
331 330
332 /* Everything passes, must be OK. */ 331 /* Everything passes, must be OK. */
333 return 1; 332 return 1;
334} 333}
335 334
335// find player who can see this object
336object *
337object::visible_to () const
338{
339 if (client_visible () && !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 if (!pl->container || this == pl->container)
364 return pl;
365 }
366 }
367
368 return 0;
369}
370
336// adjust weight per container type ("of holding") 371// adjust weight per container type ("of holding")
337static sint32 372static sint32
338weight_adjust (object *op, sint32 weight) 373weight_adjust (object *op, sint32 weight)
339{ 374{
340 return op->type == CONTAINER 375 return op->type == CONTAINER
351{ 386{
352 while (op) 387 while (op)
353 { 388 {
354 weight = weight_adjust (op, weight); 389 weight = weight_adjust (op, weight);
355 390
391 if (!weight)
392 return;
393
356 op->carrying += weight; 394 op->carrying += weight;
395
396 if (object *pl = op->visible_to ())
397 if (pl != op) // player is handled lazily
398 esrv_update_item (UPD_WEIGHT, pl, op);
399
357 op = op->env; 400 op = op->env;
358 } 401 }
359} 402}
360 403
361/* 404/*
374 op->update_weight (); 417 op->update_weight ();
375 418
376 sum += op->total_weight (); 419 sum += op->total_weight ();
377 } 420 }
378 421
379 carrying = weight_adjust (this, sum); 422 sum = weight_adjust (this, sum);
423
424 if (sum != carrying)
425 {
426 carrying = sum;
427
428 if (object *pl = visible_to ())
429 if (pl != this) // player is handled lazily
430 esrv_update_item (UPD_WEIGHT, pl, this);
431 }
380} 432}
381 433
382/* 434/*
383 * Used by: Server DM commands: dumpbelow, dump. Some error messages. 435 * Used by: Server DM commands: dumpbelow, dump. Some error messages.
384 */ 436 */
554} 606}
555 607
556object & 608object &
557object::operator =(const object &src) 609object::operator =(const object &src)
558{ 610{
559 bool is_freed = flag [FLAG_FREED]; 611 remove ();
560 bool is_removed = flag [FLAG_REMOVED];
561 612
562 *(object_copy *)this = src; 613 *(object_copy *)this = src;
563 614
564 flag [FLAG_FREED] = is_freed;
565 flag [FLAG_REMOVED] = is_removed; 615 flag [FLAG_REMOVED] = true;
566 616
567 /* Copy over key_values, if any. */ 617 /* Copy over key_values, if any. */
568 if (src.key_values) 618 if (src.key_values)
569 { 619 {
570 key_value *tail = 0; 620 key_value *tail = 0;
694 * UP_OBJ_FACE: only the objects face has changed. 744 * UP_OBJ_FACE: only the objects face has changed.
695 */ 745 */
696void 746void
697update_object (object *op, int action) 747update_object (object *op, int action)
698{ 748{
699 if (op == NULL) 749 if (!op)
700 { 750 {
701 /* this should never happen */ 751 /* this should never happen */
702 LOG (llevDebug, "update_object() called for NULL object.\n"); 752 LOG (llevError | logBacktrace, "update_object() called for NULL object.\n");
703 return; 753 return;
704 } 754 }
705 755
706 if (op->env) 756 if (!op->is_on_map ())
707 { 757 {
708 /* Animation is currently handled by client, so nothing 758 /* Animation is currently handled by client, so nothing
709 * to do in this case. 759 * to do in this case.
710 */ 760 */
711 return; 761 return;
712 } 762 }
713
714 /* If the map is saving, don't do anything as everything is
715 * going to get freed anyways.
716 */
717 if (!op->map || op->map->in_memory == MAP_SAVING)
718 return;
719 763
720 /* make sure the object is within map boundaries */ 764 /* make sure the object is within map boundaries */
721 if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) 765 if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height)
722 { 766 {
723 LOG (llevError, "update_object() called for object out of map!\n"); 767 LOG (llevError, "update_object() called for object out of map!\n");
866object::destroy_inv (bool drop_to_ground) 910object::destroy_inv (bool drop_to_ground)
867{ 911{
868 // need to check first, because the checks below might segfault 912 // need to check first, because the checks below might segfault
869 // as we might be on an invalid mapspace and crossfire code 913 // as we might be on an invalid mapspace and crossfire code
870 // is too buggy to ensure that the inventory is empty. 914 // is too buggy to ensure that the inventory is empty.
871 // corollary: if you create arrows etc. with stuff in tis inventory, 915 // corollary: if you create arrows etc. with stuff in its inventory,
872 // cf will crash below with off-map x and y 916 // cf will crash below with off-map x and y
873 if (!inv) 917 if (!inv)
874 return; 918 return;
875 919
876 /* Only if the space blocks everything do we not process - 920 /* Only if the space blocks everything do we not process -
883 || map->nodrop 927 || map->nodrop
884 || ms ().move_block == MOVE_ALL) 928 || ms ().move_block == MOVE_ALL)
885 { 929 {
886 while (inv) 930 while (inv)
887 { 931 {
888 inv->destroy_inv (drop_to_ground); 932 inv->destroy_inv (false);
889 inv->destroy (); 933 inv->destroy ();
890 } 934 }
891 } 935 }
892 else 936 else
893 { /* Put objects in inventory onto this space */ 937 { /* Put objects in inventory onto this space */
899 || op->flag [FLAG_NO_DROP] 943 || op->flag [FLAG_NO_DROP]
900 || op->type == RUNE 944 || op->type == RUNE
901 || op->type == TRAP 945 || op->type == TRAP
902 || op->flag [FLAG_IS_A_TEMPLATE] 946 || op->flag [FLAG_IS_A_TEMPLATE]
903 || op->flag [FLAG_DESTROY_ON_DEATH]) 947 || op->flag [FLAG_DESTROY_ON_DEATH])
904 op->destroy (); 948 op->destroy (true);
905 else 949 else
906 map->insert (op, x, y); 950 map->insert (op, x, y);
907 } 951 }
908 } 952 }
909} 953}
913 object *op = new object; 957 object *op = new object;
914 op->link (); 958 op->link ();
915 return op; 959 return op;
916} 960}
917 961
962static struct freed_map : maptile
963{
964 freed_map ()
965 {
966 path = "<freed objects map>";
967 name = "/internal/freed_objects_map";
968 width = 3;
969 height = 3;
970 nodrop = 1;
971
972 alloc ();
973 in_memory = MAP_ACTIVE;
974 }
975} freed_map; // freed objects are moved here to avoid crashes
976
918void 977void
919object::do_destroy () 978object::do_destroy ()
920{ 979{
921 attachable::do_destroy ();
922
923 if (flag [FLAG_IS_LINKED]) 980 if (flag [FLAG_IS_LINKED])
924 remove_button_link (this); 981 remove_button_link (this);
925 982
926 if (flag [FLAG_FRIENDLY]) 983 if (flag [FLAG_FRIENDLY])
927 remove_friendly_object (this); 984 remove_friendly_object (this);
928 985
929 if (!flag [FLAG_REMOVED])
930 remove (); 986 remove ();
931 987
932 destroy_inv (true); 988 attachable::do_destroy ();
933 989
934 deactivate (); 990 deactivate ();
935 unlink (); 991 unlink ();
936 992
937 flag [FLAG_FREED] = 1; 993 flag [FLAG_FREED] = 1;
938 994
939 // hack to ensure that freed objects still have a valid map 995 // hack to ensure that freed objects still have a valid map
940 {
941 static maptile *freed_map; // freed objects are moved here to avoid crashes
942
943 if (!freed_map)
944 {
945 freed_map = new maptile;
946
947 freed_map->path = "<freed objects map>";
948 freed_map->name = "/internal/freed_objects_map";
949 freed_map->width = 3;
950 freed_map->height = 3;
951 freed_map->nodrop = 1;
952
953 freed_map->alloc ();
954 freed_map->in_memory = MAP_ACTIVE;
955 }
956
957 map = freed_map; 996 map = &freed_map;
958 x = 1; 997 x = 1;
959 y = 1; 998 y = 1;
960 }
961 999
962 if (more) 1000 if (more)
963 { 1001 {
964 more->destroy (); 1002 more->destroy ();
965 more = 0; 1003 more = 0;
978object::destroy (bool destroy_inventory) 1016object::destroy (bool destroy_inventory)
979{ 1017{
980 if (destroyed ()) 1018 if (destroyed ())
981 return; 1019 return;
982 1020
1021 if (!is_head () && !head->destroyed ())
1022 {
1023 LOG (llevError | logBacktrace, "tried to destroy the tail of an object");
1024 head->destroy (destroy_inventory);
1025 return;
1026 }
1027
983 if (destroy_inventory) 1028 destroy_inv (!destroy_inventory);
984 destroy_inv (false);
985 1029
986 if (is_head ()) 1030 if (is_head ())
987 if (sound_destroy) 1031 if (sound_destroy)
988 play_sound (sound_destroy); 1032 play_sound (sound_destroy);
989 else if (flag [FLAG_MONSTER]) 1033 else if (flag [FLAG_MONSTER])
1003object::do_remove () 1047object::do_remove ()
1004{ 1048{
1005 object *tmp, *last = 0; 1049 object *tmp, *last = 0;
1006 object *otmp; 1050 object *otmp;
1007 1051
1008 if (QUERY_FLAG (this, FLAG_REMOVED)) 1052 if (flag [FLAG_REMOVED])
1009 return; 1053 return;
1010 1054
1011 SET_FLAG (this, FLAG_REMOVED);
1012 INVOKE_OBJECT (REMOVE, this); 1055 INVOKE_OBJECT (REMOVE, this);
1056
1057 flag [FLAG_REMOVED] = true;
1013 1058
1014 if (more) 1059 if (more)
1015 more->remove (); 1060 more->remove ();
1016 1061
1017 /* 1062 /*
1018 * In this case, the object to be removed is in someones 1063 * In this case, the object to be removed is in someones
1019 * inventory. 1064 * inventory.
1020 */ 1065 */
1021 if (env) 1066 if (env)
1022 { 1067 {
1068 flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed
1069 if (object *pl = visible_to ())
1070 esrv_del_item (pl->contr, count);
1071 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1072
1023 adjust_weight (env, -total_weight ()); 1073 adjust_weight (env, -total_weight ());
1024 1074
1025 *(above ? &above->below : &env->inv) = below; 1075 *(above ? &above->below : &env->inv) = below;
1026 1076
1027 if (below) 1077 if (below)
1045 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1095 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER))
1046 otmp->update_stats (); 1096 otmp->update_stats ();
1047 } 1097 }
1048 else if (map) 1098 else if (map)
1049 { 1099 {
1050 if (type == PLAYER)
1051 {
1052 // leaving a spot always closes any open container on the ground
1053 if (container && !container->env)
1054 // this causes spurious floorbox updates, but it ensures
1055 // that the CLOSE event is being sent.
1056 close_container ();
1057
1058 --map->players;
1059 map->touch ();
1060 }
1061
1062 map->dirty = true; 1100 map->dirty = true;
1063 mapspace &ms = this->ms (); 1101 mapspace &ms = this->ms ();
1102
1103 if (object *pl = ms.player ())
1104 {
1105 if (type == PLAYER) // this == pl(!)
1106 {
1107 // leaving a spot always closes any open container on the ground
1108 if (container && !container->env)
1109 // this causes spurious floorbox updates, but it ensures
1110 // that the CLOSE event is being sent.
1111 close_container ();
1112
1113 --map->players;
1114 map->touch ();
1115 }
1116 else if (pl->container == this)
1117 {
1118 // removing a container should close it
1119 close_container ();
1120 }
1121
1122 esrv_del_item (pl->contr, count);
1123 }
1064 1124
1065 /* link the object above us */ 1125 /* link the object above us */
1066 if (above) 1126 if (above)
1067 above->below = below; 1127 above->below = below;
1068 else 1128 else
1098 * removed (most likely destroyed), update the player view 1158 * removed (most likely destroyed), update the player view
1099 * appropriately. 1159 * appropriately.
1100 */ 1160 */
1101 pl->close_container (); 1161 pl->close_container ();
1102 1162
1103 pl->contr->ns->floorbox_update (); 1163 //TODO: the floorbox prev/next might need updating
1164 esrv_del_item (pl->contr, count);
1104 } 1165 }
1105 1166
1106 for (tmp = ms.bot; tmp; tmp = tmp->above) 1167 for (tmp = ms.bot; tmp; tmp = tmp->above)
1107 { 1168 {
1108 /* No point updating the players look faces if he is the object 1169 /* No point updating the players look faces if he is the object
1152 if (!top) 1213 if (!top)
1153 for (top = op; top && top->above; top = top->above) 1214 for (top = op; top && top->above; top = top->above)
1154 ; 1215 ;
1155 1216
1156 for (; top; top = top->below) 1217 for (; top; top = top->below)
1157 {
1158 if (top == op)
1159 continue;
1160
1161 if (object::can_merge (op, top)) 1218 if (object::can_merge (op, top))
1162 { 1219 {
1163 top->nrof += op->nrof; 1220 top->nrof += op->nrof;
1164 1221
1165/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ 1222 if (object *pl = top->visible_to ())
1166 op->weight = 0; /* Don't want any adjustements now */ 1223 esrv_update_item (UPD_NROF, pl, top);
1224
1225 op->weight = 0; // cancel the addition above
1226 op->carrying = 0; // must be 0 already
1227
1167 op->destroy (); 1228 op->destroy (1);
1229
1168 return top; 1230 return top;
1169 } 1231 }
1170 }
1171 1232
1172 return 0; 1233 return 0;
1173} 1234}
1174 1235
1175void 1236void
1234object * 1295object *
1235insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1296insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1236{ 1297{
1237 assert (!op->flag [FLAG_FREED]); 1298 assert (!op->flag [FLAG_FREED]);
1238 1299
1239 object *top, *floor = NULL;
1240
1241 op->remove (); 1300 op->remove ();
1242 1301
1243 /* Ideally, the caller figures this out. However, it complicates a lot 1302 /* Ideally, the caller figures this out. However, it complicates a lot
1244 * of areas of callers (eg, anything that uses find_free_spot would now 1303 * of areas of callers (eg, anything that uses find_free_spot would now
1245 * need extra work 1304 * need extra work
1246 */ 1305 */
1247 if (!xy_normalise (m, op->x, op->y)) 1306 if (!xy_normalise (m, op->x, op->y))
1248 { 1307 {
1249 op->destroy (); 1308 op->destroy (1);
1250 return 0; 1309 return 0;
1251 } 1310 }
1252 1311
1253 if (object *more = op->more) 1312 if (object *more = op->more)
1254 if (!insert_ob_in_map (more, m, originator, flag)) 1313 if (!insert_ob_in_map (more, m, originator, flag))
1263 */ 1322 */
1264 if (op->nrof && !(flag & INS_NO_MERGE)) 1323 if (op->nrof && !(flag & INS_NO_MERGE))
1265 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 1324 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1266 if (object::can_merge (op, tmp)) 1325 if (object::can_merge (op, tmp))
1267 { 1326 {
1327 // TODO: we atcually want to update tmp, not op,
1328 // but some caller surely breaks when we return tmp
1329 // from here :/
1268 op->nrof += tmp->nrof; 1330 op->nrof += tmp->nrof;
1269 tmp->destroy (1); 1331 tmp->destroy (1);
1270 } 1332 }
1271 1333
1272 CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ 1334 CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */
1294 /* since *below* originator, no need to update top */ 1356 /* since *below* originator, no need to update top */
1295 originator->below = op; 1357 originator->below = op;
1296 } 1358 }
1297 else 1359 else
1298 { 1360 {
1361 object *top, *floor = NULL;
1362
1299 top = ms.bot; 1363 top = ms.bot;
1300 1364
1301 /* If there are other objects, then */ 1365 /* If there are other objects, then */
1302 if (top) 1366 if (top)
1303 { 1367 {
1402 } 1466 }
1403 1467
1404 op->map->dirty = true; 1468 op->map->dirty = true;
1405 1469
1406 if (object *pl = ms.player ()) 1470 if (object *pl = ms.player ())
1407 pl->contr->ns->floorbox_update (); 1471 //TODO: the floorbox prev/next might need updating
1472 esrv_send_item (pl, op);
1408 1473
1409 /* If this object glows, it may affect lighting conditions that are 1474 /* If this object glows, it may affect lighting conditions that are
1410 * visible to others on this map. But update_all_los is really 1475 * visible to others on this map. But update_all_los is really
1411 * an inefficient way to do this, as it means los for all players 1476 * an inefficient way to do this, as it means los for all players
1412 * on the map will get recalculated. The players could very well 1477 * on the map will get recalculated. The players could very well
1478 else 1543 else
1479 return where->map->insert (this, where->x, where->y, originator, flags); 1544 return where->map->insert (this, where->x, where->y, originator, flags);
1480} 1545}
1481 1546
1482/* 1547/*
1483 * get_split_ob(ob,nr) splits up ob into two parts. The part which
1484 * is returned contains nr objects, and the remaining parts contains
1485 * the rest (or is removed and freed if that number is 0).
1486 * On failure, NULL is returned, and the reason put into the
1487 * global static errmsg array.
1488 */
1489object *
1490object::split_nr (sint32 nr)
1491{
1492 if (nrof < nr)
1493 return 0;
1494 else if (nrof == nr)
1495 {
1496 remove ();
1497 return this;
1498 }
1499 else
1500 {
1501 decrease_nr (nr);
1502
1503 object *op = object_create_clone (this);
1504 op->nrof = nr;
1505 return op;
1506 }
1507}
1508
1509//TODO: remove, but semantics differs from split_nr
1510object *
1511get_split_ob (object *orig_ob, uint32 nr)
1512{
1513 if (orig_ob->nrof < nr)
1514 {
1515 sprintf (errmsg, "There are only %d %ss.", orig_ob->nrof ? orig_ob->nrof : 1, &orig_ob->name);
1516 return 0;
1517 }
1518
1519 return orig_ob->split_nr (nr);
1520}
1521
1522// find player who can see this object
1523static object *
1524visible_to (object *op)
1525{
1526 if (!op->flag [FLAG_REMOVED])
1527 {
1528 // see if we are in a container of sorts
1529 if (object *env = op->env)
1530 {
1531 // the player inventory itself is always visible
1532 if (env->type == PLAYER)
1533 return env;
1534
1535 // else a player could have our env open
1536 env = env->outer_env ();
1537
1538 // the player itself is always on a map, so we will find him here
1539 // even if our inv is in a player.
1540 if (env->is_on_map ())
1541 if (object *pl = env->ms ().player ())
1542 if (pl->container == op->env)
1543 return pl;
1544 }
1545 else
1546 {
1547 // maybe there is a player standing on the same mapspace
1548 if (object *pl = env->ms ().player ())
1549 return pl;
1550 }
1551 }
1552
1553 return 0;
1554}
1555
1556/*
1557 * decrease_ob_nr(object, number) decreases a specified number from 1548 * decrease(object, number) decreases a specified number from
1558 * the amount of an object. If the amount reaches 0, the object 1549 * the amount of an object. If the amount reaches 0, the object
1559 * is subsequently removed and freed. 1550 * is subsequently removed and freed.
1560 * 1551 *
1561 * Return value: 'op' if something is left, NULL if the amount reached 0 1552 * Return value: 'op' if something is left, NULL if the amount reached 0
1562 */ 1553 */
1563bool 1554bool
1564object::decrease_nr (sint32 nr) 1555object::decrease (sint32 nr)
1565{ 1556{
1557 if (!nr)
1558 return true;
1559
1566 nr = min (nr, nrof); 1560 nr = min (nr, nrof);
1567 1561
1568 if (!nr)
1569 return 1;
1570
1571 nrof -= nr; 1562 nrof -= nr;
1572 1563
1573 object *visible = visible_to (this);
1574
1575 if (nrof) 1564 if (nrof)
1576 { 1565 {
1577 adjust_weight (env, -weight * nr); // carrying == 0 1566 adjust_weight (env, -weight * nr); // carrying == 0
1578 1567
1579 if (visible) 1568 if (object *pl = visible_to ())
1580 esrv_send_item (visible, this); 1569 esrv_update_item (UPD_NROF, pl, this);
1581 1570
1582 return 1; 1571 return true;
1583 } 1572 }
1584 else 1573 else
1585 { 1574 {
1586 if (visible)
1587 esrv_del_item (visible->contr, count);
1588
1589 this->destroy (1); 1575 destroy (1);
1590 return 0; 1576 return false;
1591 } 1577 }
1592} 1578}
1593 1579
1594//TODO: remove 1580/*
1581 * split(ob,nr) splits up ob into two parts. The part which
1582 * is returned contains nr objects, and the remaining parts contains
1583 * the rest (or is removed and returned if that number is 0).
1584 * On failure, NULL is returned.
1585 */
1595object * 1586object *
1596decrease_ob_nr (object *op, uint32 i) 1587object::split (sint32 nr)
1597{ 1588{
1598 return op->decrease_nr (i) ? op : 0; 1589 int have = number_of ();
1590
1591 if (have < nr)
1592 return 0;
1593 else if (have == nr)
1594 {
1595 remove ();
1596 return this;
1597 }
1598 else
1599 {
1600 decrease (nr);
1601
1602 object *op = object_create_clone (this);
1603 op->nrof = nr;
1604 return op;
1605 }
1599} 1606}
1600 1607
1601object * 1608object *
1602insert_ob_in_ob (object *op, object *where) 1609insert_ob_in_ob (object *op, object *where)
1603{ 1610{
1644 if (object::can_merge (tmp, op)) 1651 if (object::can_merge (tmp, op))
1645 { 1652 {
1646 /* return the original object and remove inserted object 1653 /* return the original object and remove inserted object
1647 (client needs the original object) */ 1654 (client needs the original object) */
1648 tmp->nrof += op->nrof; 1655 tmp->nrof += op->nrof;
1656
1657 if (object *pl = tmp->visible_to ())
1658 esrv_update_item (UPD_NROF, pl, tmp);
1659
1660 adjust_weight (this, op->total_weight ());
1661
1649 op->destroy (1); 1662 op->destroy (1);
1650 op = tmp; 1663 op = tmp;
1651 goto inserted; 1664 goto inserted;
1652 } 1665 }
1653 1666
1665 1678
1666 inv = op; 1679 inv = op;
1667 1680
1668 op->flag [FLAG_REMOVED] = 0; 1681 op->flag [FLAG_REMOVED] = 0;
1669 1682
1683 if (object *pl = op->visible_to ())
1684 esrv_send_item (pl, op);
1685
1670 adjust_weight (this, op->total_weight ()); 1686 adjust_weight (this, op->total_weight ());
1671 1687
1672inserted: 1688inserted:
1673 /* reset the light list and los of the players on the map */ 1689 /* reset the light list and los of the players on the map */
1674 if (op->glow_radius && map && map->darkness) 1690 if (op->glow_radius && map && map->darkness)
1675 update_all_los (map, x, y); 1691 update_all_los (map, x, y);
1676 1692
1677 if (object *otmp = in_player ()) 1693 // if this is a player's inventory, update stats
1678 if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1694 if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER])
1679 otmp->update_stats (); 1695 update_stats ();
1680 1696
1681 INVOKE_OBJECT (INSERT, this); 1697 INVOKE_OBJECT (INSERT, this);
1682 1698
1683 return op; 1699 return op;
1684} 1700}
2308 * create clone from object to another 2324 * create clone from object to another
2309 */ 2325 */
2310object * 2326object *
2311object_create_clone (object *asrc) 2327object_create_clone (object *asrc)
2312{ 2328{
2313 object *dst = 0, *tmp, *src, *prev, *item; 2329 object *dst = 0;
2314 2330
2315 if (!asrc) 2331 if (!asrc)
2316 return 0; 2332 return 0;
2317 2333
2318 src = asrc->head_ (); 2334 object *src = asrc->head_ ();
2319 2335
2320 prev = 0; 2336 object *prev = 0;
2321 for (object *part = src; part; part = part->more) 2337 for (object *part = src; part; part = part->more)
2322 { 2338 {
2323 tmp = part->clone (); 2339 object *tmp = part->clone ();
2340
2324 tmp->x -= src->x; 2341 tmp->x -= src->x;
2325 tmp->y -= src->y; 2342 tmp->y -= src->y;
2326 2343
2327 if (!part->head) 2344 if (!part->head)
2328 { 2345 {
2338 prev->more = tmp; 2355 prev->more = tmp;
2339 2356
2340 prev = tmp; 2357 prev = tmp;
2341 } 2358 }
2342 2359
2343 for (item = src->inv; item; item = item->below) 2360 for (object *item = src->inv; item; item = item->below)
2344 insert_ob_in_ob (object_create_clone (item), dst); 2361 insert_ob_in_ob (object_create_clone (item), dst);
2345 2362
2346 return dst; 2363 return dst;
2347} 2364}
2348 2365
2562 &name, 2579 &name,
2563 title ? "\",title:\"" : "", 2580 title ? "\",title:\"" : "",
2564 title ? (const char *)title : "", 2581 title ? (const char *)title : "",
2565 flag_desc (flagdesc, 512), type); 2582 flag_desc (flagdesc, 512), type);
2566 2583
2567 if (!this->flag[FLAG_REMOVED] && env) 2584 if (!flag[FLAG_REMOVED] && env)
2568 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); 2585 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2569 2586
2570 if (map) 2587 if (map)
2571 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); 2588 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y);
2572 2589
2602object::open_container (object *new_container) 2619object::open_container (object *new_container)
2603{ 2620{
2604 if (container == new_container) 2621 if (container == new_container)
2605 return; 2622 return;
2606 2623
2607 if (object *old_container = container) 2624 object *old_container = container;
2625
2626 if (old_container)
2608 { 2627 {
2609 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) 2628 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this)))
2610 return; 2629 return;
2611 2630
2612#if 0 2631#if 0
2614 if (object *closer = old_container->inv) 2633 if (object *closer = old_container->inv)
2615 if (closer->type == CLOSE_CON) 2634 if (closer->type == CLOSE_CON)
2616 closer->destroy (); 2635 closer->destroy ();
2617#endif 2636#endif
2618 2637
2638 // make sure the container is available
2639 esrv_send_item (this, old_container);
2640
2619 old_container->flag [FLAG_APPLIED] = 0; 2641 old_container->flag [FLAG_APPLIED] = false;
2620 container = 0; 2642 container = 0;
2621 2643
2644 // client needs item update to make it work, client bug requires this to be separate
2622 esrv_update_item (UPD_FLAGS, this, old_container); 2645 esrv_update_item (UPD_FLAGS, this, old_container);
2646
2623 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2647 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container));
2624 play_sound (sound_find ("chest_close")); 2648 play_sound (sound_find ("chest_close"));
2625 } 2649 }
2626 2650
2627 if (new_container) 2651 if (new_container)
2640 } 2664 }
2641#endif 2665#endif
2642 2666
2643 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2667 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container));
2644 2668
2669 // make sure the container is available, client bug requires this to be separate
2670 esrv_send_item (this, new_container);
2671
2645 new_container->flag [FLAG_APPLIED] = 1; 2672 new_container->flag [FLAG_APPLIED] = true;
2646 container = new_container; 2673 container = new_container;
2647 2674
2675 // client needs flag change
2648 esrv_update_item (UPD_FLAGS, this, new_container); 2676 esrv_update_item (UPD_FLAGS, this, new_container);
2649 esrv_send_inventory (this, new_container); 2677 esrv_send_inventory (this, new_container);
2650 play_sound (sound_find ("chest_open")); 2678 play_sound (sound_find ("chest_open"));
2651 } 2679 }
2680// else if (!old_container->env && contr && contr->ns)
2681// contr->ns->floorbox_reset ();
2652} 2682}
2653 2683
2654object * 2684object *
2655object::force_find (const shstr name) 2685object::force_find (const shstr name)
2656{ 2686{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines