… | |
… | |
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 |
|
|
336 | object * |
|
|
337 | object::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") |
337 | static sint32 |
372 | static sint32 |
338 | weight_adjust (object *op, sint32 weight) |
373 | weight_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 | */ |
… | |
… | |
866 | object::destroy_inv (bool drop_to_ground) |
918 | object::destroy_inv (bool drop_to_ground) |
867 | { |
919 | { |
868 | // need to check first, because the checks below might segfault |
920 | // need to check first, because the checks below might segfault |
869 | // as we might be on an invalid mapspace and crossfire code |
921 | // as we might be on an invalid mapspace and crossfire code |
870 | // is too buggy to ensure that the inventory is empty. |
922 | // is too buggy to ensure that the inventory is empty. |
871 | // corollary: if you create arrows etc. with stuff in tis inventory, |
923 | // corollary: if you create arrows etc. with stuff in its inventory, |
872 | // cf will crash below with off-map x and y |
924 | // cf will crash below with off-map x and y |
873 | if (!inv) |
925 | if (!inv) |
874 | return; |
926 | return; |
875 | |
927 | |
876 | /* Only if the space blocks everything do we not process - |
928 | /* Only if the space blocks everything do we not process - |
… | |
… | |
883 | || map->nodrop |
935 | || map->nodrop |
884 | || ms ().move_block == MOVE_ALL) |
936 | || ms ().move_block == MOVE_ALL) |
885 | { |
937 | { |
886 | while (inv) |
938 | while (inv) |
887 | { |
939 | { |
888 | inv->destroy_inv (drop_to_ground); |
940 | inv->destroy_inv (false); |
889 | inv->destroy (); |
941 | inv->destroy (); |
890 | } |
942 | } |
891 | } |
943 | } |
892 | else |
944 | else |
893 | { /* Put objects in inventory onto this space */ |
945 | { /* Put objects in inventory onto this space */ |
… | |
… | |
899 | || op->flag [FLAG_NO_DROP] |
951 | || op->flag [FLAG_NO_DROP] |
900 | || op->type == RUNE |
952 | || op->type == RUNE |
901 | || op->type == TRAP |
953 | || op->type == TRAP |
902 | || op->flag [FLAG_IS_A_TEMPLATE] |
954 | || op->flag [FLAG_IS_A_TEMPLATE] |
903 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
955 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
904 | op->destroy (); |
956 | op->destroy (true); |
905 | else |
957 | else |
906 | map->insert (op, x, y); |
958 | map->insert (op, x, y); |
907 | } |
959 | } |
908 | } |
960 | } |
909 | } |
961 | } |
… | |
… | |
916 | } |
968 | } |
917 | |
969 | |
918 | void |
970 | void |
919 | object::do_destroy () |
971 | object::do_destroy () |
920 | { |
972 | { |
921 | attachable::do_destroy (); |
|
|
922 | |
|
|
923 | if (flag [FLAG_IS_LINKED]) |
973 | if (flag [FLAG_IS_LINKED]) |
924 | remove_button_link (this); |
974 | remove_button_link (this); |
925 | |
975 | |
926 | if (flag [FLAG_FRIENDLY]) |
976 | if (flag [FLAG_FRIENDLY]) |
927 | remove_friendly_object (this); |
977 | remove_friendly_object (this); |
928 | |
978 | |
929 | if (!flag [FLAG_REMOVED]) |
|
|
930 | remove (); |
979 | remove (); |
931 | |
980 | |
932 | destroy_inv (true); |
981 | attachable::do_destroy (); |
933 | |
982 | |
934 | deactivate (); |
983 | deactivate (); |
935 | unlink (); |
984 | unlink (); |
936 | |
985 | |
937 | flag [FLAG_FREED] = 1; |
986 | flag [FLAG_FREED] = 1; |
… | |
… | |
978 | object::destroy (bool destroy_inventory) |
1027 | object::destroy (bool destroy_inventory) |
979 | { |
1028 | { |
980 | if (destroyed ()) |
1029 | if (destroyed ()) |
981 | return; |
1030 | return; |
982 | |
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 | |
983 | if (destroy_inventory) |
1038 | destroy_inv (!destroy_inventory); |
984 | destroy_inv (false); |
|
|
985 | |
1039 | |
986 | if (is_head ()) |
1040 | if (is_head ()) |
987 | if (sound_destroy) |
1041 | if (sound_destroy) |
988 | play_sound (sound_destroy); |
1042 | play_sound (sound_destroy); |
989 | else if (flag [FLAG_MONSTER]) |
1043 | else if (flag [FLAG_MONSTER]) |
… | |
… | |
1003 | object::do_remove () |
1057 | object::do_remove () |
1004 | { |
1058 | { |
1005 | object *tmp, *last = 0; |
1059 | object *tmp, *last = 0; |
1006 | object *otmp; |
1060 | object *otmp; |
1007 | |
1061 | |
1008 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
1062 | if (flag [FLAG_REMOVED]) |
1009 | return; |
1063 | return; |
1010 | |
1064 | |
1011 | SET_FLAG (this, FLAG_REMOVED); |
|
|
1012 | INVOKE_OBJECT (REMOVE, this); |
1065 | INVOKE_OBJECT (REMOVE, this); |
|
|
1066 | |
|
|
1067 | flag [FLAG_REMOVED] = true; |
1013 | |
1068 | |
1014 | if (more) |
1069 | if (more) |
1015 | more->remove (); |
1070 | more->remove (); |
1016 | |
1071 | |
1017 | /* |
1072 | /* |
1018 | * In this case, the object to be removed is in someones |
1073 | * In this case, the object to be removed is in someones |
1019 | * inventory. |
1074 | * inventory. |
1020 | */ |
1075 | */ |
1021 | if (env) |
1076 | if (env) |
1022 | { |
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 | |
1023 | adjust_weight (env, -total_weight ()); |
1083 | adjust_weight (env, -total_weight ()); |
1024 | |
1084 | |
1025 | *(above ? &above->below : &env->inv) = below; |
1085 | *(above ? &above->below : &env->inv) = below; |
1026 | |
1086 | |
1027 | if (below) |
1087 | if (below) |
… | |
… | |
1045 | 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)) |
1046 | otmp->update_stats (); |
1106 | otmp->update_stats (); |
1047 | } |
1107 | } |
1048 | else if (map) |
1108 | else if (map) |
1049 | { |
1109 | { |
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; |
1110 | map->dirty = true; |
1063 | 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 | } |
1064 | |
1134 | |
1065 | /* link the object above us */ |
1135 | /* link the object above us */ |
1066 | if (above) |
1136 | if (above) |
1067 | above->below = below; |
1137 | above->below = below; |
1068 | else |
1138 | else |
… | |
… | |
1098 | * removed (most likely destroyed), update the player view |
1168 | * removed (most likely destroyed), update the player view |
1099 | * appropriately. |
1169 | * appropriately. |
1100 | */ |
1170 | */ |
1101 | pl->close_container (); |
1171 | pl->close_container (); |
1102 | |
1172 | |
1103 | pl->contr->ns->floorbox_update (); |
1173 | //TODO: the floorbox prev/next might need updating |
|
|
1174 | esrv_del_item (pl->contr, count); |
1104 | } |
1175 | } |
1105 | |
1176 | |
1106 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1177 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1107 | { |
1178 | { |
1108 | /* 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 |
… | |
… | |
1152 | if (!top) |
1223 | if (!top) |
1153 | for (top = op; top && top->above; top = top->above) |
1224 | for (top = op; top && top->above; top = top->above) |
1154 | ; |
1225 | ; |
1155 | |
1226 | |
1156 | for (; top; top = top->below) |
1227 | for (; top; top = top->below) |
1157 | { |
|
|
1158 | if (top == op) |
|
|
1159 | continue; |
|
|
1160 | |
|
|
1161 | if (object::can_merge (op, top)) |
1228 | if (object::can_merge (op, top)) |
1162 | { |
1229 | { |
1163 | top->nrof += op->nrof; |
1230 | top->nrof += op->nrof; |
1164 | |
1231 | |
1165 | /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ |
1232 | if (object *pl = top->visible_to ()) |
1166 | op->weight = 0; /* Don't want any adjustements now */ |
1233 | esrv_update_item (UPD_NROF, pl, top); |
|
|
1234 | |
|
|
1235 | op->weight = 0; // cancel the addition above |
|
|
1236 | op->carrying = 0; // must be 0 already |
|
|
1237 | |
1167 | op->destroy (); |
1238 | op->destroy (1); |
|
|
1239 | |
1168 | return top; |
1240 | return top; |
1169 | } |
1241 | } |
1170 | } |
|
|
1171 | |
1242 | |
1172 | return 0; |
1243 | return 0; |
1173 | } |
1244 | } |
1174 | |
1245 | |
1175 | void |
1246 | void |
… | |
… | |
1234 | object * |
1305 | object * |
1235 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1306 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1236 | { |
1307 | { |
1237 | assert (!op->flag [FLAG_FREED]); |
1308 | assert (!op->flag [FLAG_FREED]); |
1238 | |
1309 | |
1239 | object *top, *floor = NULL; |
|
|
1240 | |
|
|
1241 | op->remove (); |
1310 | op->remove (); |
1242 | |
1311 | |
1243 | /* Ideally, the caller figures this out. However, it complicates a lot |
1312 | /* 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 |
1313 | * of areas of callers (eg, anything that uses find_free_spot would now |
1245 | * need extra work |
1314 | * need extra work |
1246 | */ |
1315 | */ |
1247 | if (!xy_normalise (m, op->x, op->y)) |
1316 | if (!xy_normalise (m, op->x, op->y)) |
1248 | { |
1317 | { |
1249 | op->destroy (); |
1318 | op->destroy (1); |
1250 | return 0; |
1319 | return 0; |
1251 | } |
1320 | } |
1252 | |
1321 | |
1253 | if (object *more = op->more) |
1322 | if (object *more = op->more) |
1254 | if (!insert_ob_in_map (more, m, originator, flag)) |
1323 | if (!insert_ob_in_map (more, m, originator, flag)) |
… | |
… | |
1263 | */ |
1332 | */ |
1264 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1333 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1265 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1334 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1266 | if (object::can_merge (op, tmp)) |
1335 | if (object::can_merge (op, tmp)) |
1267 | { |
1336 | { |
|
|
1337 | // TODO: we atcually want to update tmp, not op, |
|
|
1338 | // but some caller surely breaks when we return tmp |
|
|
1339 | // from here :/ |
1268 | op->nrof += tmp->nrof; |
1340 | op->nrof += tmp->nrof; |
1269 | tmp->destroy (1); |
1341 | tmp->destroy (1); |
1270 | } |
1342 | } |
1271 | |
1343 | |
1272 | 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 */ |
… | |
… | |
1294 | /* since *below* originator, no need to update top */ |
1366 | /* since *below* originator, no need to update top */ |
1295 | originator->below = op; |
1367 | originator->below = op; |
1296 | } |
1368 | } |
1297 | else |
1369 | else |
1298 | { |
1370 | { |
|
|
1371 | object *top, *floor = NULL; |
|
|
1372 | |
1299 | top = ms.bot; |
1373 | top = ms.bot; |
1300 | |
1374 | |
1301 | /* If there are other objects, then */ |
1375 | /* If there are other objects, then */ |
1302 | if (top) |
1376 | if (top) |
1303 | { |
1377 | { |
… | |
… | |
1402 | } |
1476 | } |
1403 | |
1477 | |
1404 | op->map->dirty = true; |
1478 | op->map->dirty = true; |
1405 | |
1479 | |
1406 | if (object *pl = ms.player ()) |
1480 | if (object *pl = ms.player ()) |
1407 | pl->contr->ns->floorbox_update (); |
1481 | //TODO: the floorbox prev/next might need updating |
|
|
1482 | esrv_send_item (pl, op); |
1408 | |
1483 | |
1409 | /* If this object glows, it may affect lighting conditions that are |
1484 | /* If this object glows, it may affect lighting conditions that are |
1410 | * 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 |
1411 | * 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 |
1412 | * on the map will get recalculated. The players could very well |
1487 | * on the map will get recalculated. The players could very well |
… | |
… | |
1477 | return where->env->insert (this); |
1552 | return where->env->insert (this); |
1478 | else |
1553 | else |
1479 | return where->map->insert (this, where->x, where->y, originator, flags); |
1554 | return where->map->insert (this, where->x, where->y, originator, flags); |
1480 | } |
1555 | } |
1481 | |
1556 | |
1482 | // find player who can see this object |
|
|
1483 | static object * |
|
|
1484 | visible_to (object *op) |
|
|
1485 | { |
|
|
1486 | if (!op->flag [FLAG_REMOVED]) |
|
|
1487 | { |
|
|
1488 | // see if we are in a container of sorts |
|
|
1489 | if (object *env = op->env) |
|
|
1490 | { |
|
|
1491 | // the player inventory itself is always visible |
|
|
1492 | if (env->type == PLAYER) |
|
|
1493 | return env; |
|
|
1494 | |
|
|
1495 | // else a player could have our env open |
|
|
1496 | env = env->outer_env (); |
|
|
1497 | |
|
|
1498 | // the player itself is always on a map, so we will find him here |
|
|
1499 | // even if our inv is in a player. |
|
|
1500 | if (env->is_on_map ()) |
|
|
1501 | if (object *pl = env->ms ().player ()) |
|
|
1502 | if (pl->container == op->env) |
|
|
1503 | return pl; |
|
|
1504 | } |
|
|
1505 | else |
|
|
1506 | { |
|
|
1507 | // maybe there is a player standing on the same mapspace |
|
|
1508 | if (object *pl = env->ms ().player ()) |
|
|
1509 | return pl; |
|
|
1510 | } |
|
|
1511 | } |
|
|
1512 | |
|
|
1513 | return 0; |
|
|
1514 | } |
|
|
1515 | |
|
|
1516 | /* |
1557 | /* |
1517 | * decrease(object, number) decreases a specified number from |
1558 | * decrease(object, number) decreases a specified number from |
1518 | * the amount of an object. If the amount reaches 0, the object |
1559 | * the amount of an object. If the amount reaches 0, the object |
1519 | * is subsequently removed and freed. |
1560 | * is subsequently removed and freed. |
1520 | * |
1561 | * |
1521 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1562 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1522 | */ |
1563 | */ |
1523 | bool |
1564 | bool |
1524 | object::decrease (sint32 nr) |
1565 | object::decrease (sint32 nr) |
1525 | { |
1566 | { |
|
|
1567 | if (!nr) |
|
|
1568 | return true; |
|
|
1569 | |
1526 | nr = min (nr, nrof); |
1570 | nr = min (nr, nrof); |
1527 | |
1571 | |
1528 | if (!nr) |
|
|
1529 | return 1; |
|
|
1530 | |
|
|
1531 | nrof -= nr; |
1572 | nrof -= nr; |
1532 | |
1573 | |
1533 | object *visible = visible_to (this); |
|
|
1534 | |
|
|
1535 | if (nrof) |
1574 | if (nrof) |
1536 | { |
1575 | { |
1537 | adjust_weight (env, -weight * nr); // carrying == 0 |
1576 | adjust_weight (env, -weight * nr); // carrying == 0 |
1538 | |
1577 | |
1539 | if (visible) |
1578 | if (object *pl = visible_to ()) |
1540 | esrv_send_item (visible, this); |
1579 | esrv_update_item (UPD_NROF, pl, this); |
1541 | |
1580 | |
1542 | return 1; |
1581 | return true; |
1543 | } |
1582 | } |
1544 | else |
1583 | else |
1545 | { |
1584 | { |
1546 | if (visible) |
|
|
1547 | esrv_del_item (visible->contr, count); |
|
|
1548 | |
|
|
1549 | this->destroy (1); |
1585 | destroy (1); |
1550 | return 0; |
1586 | return false; |
1551 | } |
1587 | } |
1552 | } |
1588 | } |
1553 | |
1589 | |
1554 | /* |
1590 | /* |
1555 | * split(ob,nr) splits up ob into two parts. The part which |
1591 | * split(ob,nr) splits up ob into two parts. The part which |
… | |
… | |
1558 | * On failure, NULL is returned. |
1594 | * On failure, NULL is returned. |
1559 | */ |
1595 | */ |
1560 | object * |
1596 | object * |
1561 | object::split (sint32 nr) |
1597 | object::split (sint32 nr) |
1562 | { |
1598 | { |
|
|
1599 | int have = number_of (); |
|
|
1600 | |
1563 | if (nrof < nr) |
1601 | if (have < nr) |
1564 | return 0; |
1602 | return 0; |
1565 | else if (nrof == nr) |
1603 | else if (have == nr) |
1566 | { |
1604 | { |
1567 | remove (); |
1605 | remove (); |
1568 | return this; |
1606 | return this; |
1569 | } |
1607 | } |
1570 | else |
1608 | else |
… | |
… | |
1623 | if (object::can_merge (tmp, op)) |
1661 | if (object::can_merge (tmp, op)) |
1624 | { |
1662 | { |
1625 | /* return the original object and remove inserted object |
1663 | /* return the original object and remove inserted object |
1626 | (client needs the original object) */ |
1664 | (client needs the original object) */ |
1627 | tmp->nrof += op->nrof; |
1665 | tmp->nrof += op->nrof; |
|
|
1666 | |
|
|
1667 | if (object *pl = tmp->visible_to ()) |
|
|
1668 | esrv_update_item (UPD_NROF, pl, tmp); |
|
|
1669 | |
1628 | adjust_weight (this, op->total_weight ()); |
1670 | adjust_weight (this, op->total_weight ()); |
1629 | |
1671 | |
1630 | op->destroy (1); |
1672 | op->destroy (1); |
1631 | op = tmp; |
1673 | op = tmp; |
1632 | goto inserted; |
1674 | goto inserted; |
… | |
… | |
1646 | |
1688 | |
1647 | inv = op; |
1689 | inv = op; |
1648 | |
1690 | |
1649 | op->flag [FLAG_REMOVED] = 0; |
1691 | op->flag [FLAG_REMOVED] = 0; |
1650 | |
1692 | |
|
|
1693 | if (object *pl = op->visible_to ()) |
|
|
1694 | esrv_send_item (pl, op); |
|
|
1695 | |
1651 | adjust_weight (this, op->total_weight ()); |
1696 | adjust_weight (this, op->total_weight ()); |
1652 | |
1697 | |
1653 | inserted: |
1698 | inserted: |
1654 | /* reset the light list and los of the players on the map */ |
1699 | /* reset the light list and los of the players on the map */ |
1655 | if (op->glow_radius && map && map->darkness) |
1700 | if (op->glow_radius && map && map->darkness) |
1656 | update_all_los (map, x, y); |
1701 | update_all_los (map, x, y); |
1657 | |
1702 | |
1658 | if (object *otmp = in_player ()) |
1703 | // if this is a player's inventory, update stats |
1659 | if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1704 | if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER]) |
1660 | otmp->update_stats (); |
1705 | update_stats (); |
1661 | |
1706 | |
1662 | INVOKE_OBJECT (INSERT, this); |
1707 | INVOKE_OBJECT (INSERT, this); |
1663 | |
1708 | |
1664 | return op; |
1709 | return op; |
1665 | } |
1710 | } |
… | |
… | |
2543 | &name, |
2588 | &name, |
2544 | title ? "\",title:\"" : "", |
2589 | title ? "\",title:\"" : "", |
2545 | title ? (const char *)title : "", |
2590 | title ? (const char *)title : "", |
2546 | flag_desc (flagdesc, 512), type); |
2591 | flag_desc (flagdesc, 512), type); |
2547 | |
2592 | |
2548 | if (!this->flag[FLAG_REMOVED] && env) |
2593 | if (!flag[FLAG_REMOVED] && env) |
2549 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2594 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2550 | |
2595 | |
2551 | if (map) |
2596 | if (map) |
2552 | 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); |
2553 | |
2598 | |
… | |
… | |
2583 | object::open_container (object *new_container) |
2628 | object::open_container (object *new_container) |
2584 | { |
2629 | { |
2585 | if (container == new_container) |
2630 | if (container == new_container) |
2586 | return; |
2631 | return; |
2587 | |
2632 | |
2588 | if (object *old_container = container) |
2633 | object *old_container = container; |
|
|
2634 | |
|
|
2635 | if (old_container) |
2589 | { |
2636 | { |
2590 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2637 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2591 | return; |
2638 | return; |
2592 | |
2639 | |
2593 | #if 0 |
2640 | #if 0 |
… | |
… | |
2595 | if (object *closer = old_container->inv) |
2642 | if (object *closer = old_container->inv) |
2596 | if (closer->type == CLOSE_CON) |
2643 | if (closer->type == CLOSE_CON) |
2597 | closer->destroy (); |
2644 | closer->destroy (); |
2598 | #endif |
2645 | #endif |
2599 | |
2646 | |
|
|
2647 | // make sure the container is available |
|
|
2648 | esrv_send_item (this, old_container); |
|
|
2649 | |
2600 | old_container->flag [FLAG_APPLIED] = 0; |
2650 | old_container->flag [FLAG_APPLIED] = false; |
2601 | container = 0; |
2651 | container = 0; |
2602 | |
2652 | |
|
|
2653 | // client needs item update to make it work, client bug requires this to be separate |
2603 | esrv_update_item (UPD_FLAGS, this, old_container); |
2654 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2655 | |
2604 | 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)); |
2605 | play_sound (sound_find ("chest_close")); |
2657 | play_sound (sound_find ("chest_close")); |
2606 | } |
2658 | } |
2607 | |
2659 | |
2608 | if (new_container) |
2660 | if (new_container) |
… | |
… | |
2621 | } |
2673 | } |
2622 | #endif |
2674 | #endif |
2623 | |
2675 | |
2624 | 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)); |
2625 | |
2677 | |
|
|
2678 | // make sure the container is available, client bug requires this to be separate |
|
|
2679 | esrv_send_item (this, new_container); |
|
|
2680 | |
2626 | new_container->flag [FLAG_APPLIED] = 1; |
2681 | new_container->flag [FLAG_APPLIED] = true; |
2627 | container = new_container; |
2682 | container = new_container; |
2628 | |
2683 | |
|
|
2684 | // client needs flag change |
2629 | esrv_update_item (UPD_FLAGS, this, new_container); |
2685 | esrv_update_item (UPD_FLAGS, this, new_container); |
2630 | esrv_send_inventory (this, new_container); |
2686 | esrv_send_inventory (this, new_container); |
2631 | play_sound (sound_find ("chest_open")); |
2687 | play_sound (sound_find ("chest_open")); |
2632 | } |
2688 | } |
|
|
2689 | // else if (!old_container->env && contr && contr->ns) |
|
|
2690 | // contr->ns->floorbox_reset (); |
2633 | } |
2691 | } |
2634 | |
2692 | |
2635 | object * |
2693 | object * |
2636 | object::force_find (const shstr name) |
2694 | object::force_find (const shstr name) |
2637 | { |
2695 | { |