… | |
… | |
330 | |
330 | |
331 | /* Everything passes, must be OK. */ |
331 | /* Everything passes, must be OK. */ |
332 | return 1; |
332 | return 1; |
333 | } |
333 | } |
334 | |
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 | |
335 | // adjust weight per container type ("of holding") |
371 | // adjust weight per container type ("of holding") |
336 | static sint32 |
372 | static sint32 |
337 | weight_adjust (object *op, sint32 weight) |
373 | weight_adjust (object *op, sint32 weight) |
338 | { |
374 | { |
339 | return op->type == CONTAINER |
375 | return op->type == CONTAINER |
… | |
… | |
356 | return; |
392 | return; |
357 | |
393 | |
358 | op->carrying += weight; |
394 | op->carrying += weight; |
359 | |
395 | |
360 | if (object *pl = op->visible_to ()) |
396 | if (object *pl = op->visible_to ()) |
|
|
397 | if (pl != op) // player is handled lazily |
361 | esrv_update_item (UPD_WEIGHT, pl, op); |
398 | esrv_update_item (UPD_WEIGHT, pl, op); |
362 | |
399 | |
363 | op = op->env; |
400 | op = op->env; |
364 | } |
401 | } |
365 | } |
402 | } |
366 | |
403 | |
… | |
… | |
387 | if (sum != carrying) |
424 | if (sum != carrying) |
388 | { |
425 | { |
389 | carrying = sum; |
426 | carrying = sum; |
390 | |
427 | |
391 | if (object *pl = visible_to ()) |
428 | if (object *pl = visible_to ()) |
|
|
429 | if (pl != this) // player is handled lazily |
392 | esrv_update_item (UPD_WEIGHT, pl, this); |
430 | esrv_update_item (UPD_WEIGHT, pl, this); |
393 | } |
431 | } |
394 | } |
432 | } |
395 | |
433 | |
396 | /* |
434 | /* |
397 | * Used by: Server DM commands: dumpbelow, dump. Some error messages. |
435 | * Used by: Server DM commands: dumpbelow, dump. Some error messages. |
… | |
… | |
708 | * UP_OBJ_FACE: only the objects face has changed. |
746 | * UP_OBJ_FACE: only the objects face has changed. |
709 | */ |
747 | */ |
710 | void |
748 | void |
711 | update_object (object *op, int action) |
749 | update_object (object *op, int action) |
712 | { |
750 | { |
713 | if (op == NULL) |
751 | if (!op) |
714 | { |
752 | { |
715 | /* this should never happen */ |
753 | /* this should never happen */ |
716 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
754 | LOG (llevError | logBacktrace, "update_object() called for NULL object.\n"); |
717 | return; |
755 | return; |
718 | } |
756 | } |
719 | |
757 | |
720 | if (op->env) |
758 | if (!op->is_on_map ()) |
721 | { |
759 | { |
722 | /* Animation is currently handled by client, so nothing |
760 | /* Animation is currently handled by client, so nothing |
723 | * to do in this case. |
761 | * to do in this case. |
724 | */ |
762 | */ |
725 | return; |
763 | return; |
726 | } |
764 | } |
727 | |
|
|
728 | /* If the map is saving, don't do anything as everything is |
|
|
729 | * going to get freed anyways. |
|
|
730 | */ |
|
|
731 | if (!op->map || op->map->in_memory == MAP_SAVING) |
|
|
732 | return; |
|
|
733 | |
765 | |
734 | /* make sure the object is within map boundaries */ |
766 | /* make sure the object is within map boundaries */ |
735 | if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) |
767 | if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) |
736 | { |
768 | { |
737 | LOG (llevError, "update_object() called for object out of map!\n"); |
769 | LOG (llevError, "update_object() called for object out of map!\n"); |
… | |
… | |
880 | object::destroy_inv (bool drop_to_ground) |
912 | object::destroy_inv (bool drop_to_ground) |
881 | { |
913 | { |
882 | // need to check first, because the checks below might segfault |
914 | // need to check first, because the checks below might segfault |
883 | // as we might be on an invalid mapspace and crossfire code |
915 | // as we might be on an invalid mapspace and crossfire code |
884 | // is too buggy to ensure that the inventory is empty. |
916 | // is too buggy to ensure that the inventory is empty. |
885 | // corollary: if you create arrows etc. with stuff in tis inventory, |
917 | // corollary: if you create arrows etc. with stuff in its inventory, |
886 | // cf will crash below with off-map x and y |
918 | // cf will crash below with off-map x and y |
887 | if (!inv) |
919 | if (!inv) |
888 | return; |
920 | return; |
889 | |
921 | |
890 | /* Only if the space blocks everything do we not process - |
922 | /* Only if the space blocks everything do we not process - |
… | |
… | |
897 | || map->nodrop |
929 | || map->nodrop |
898 | || ms ().move_block == MOVE_ALL) |
930 | || ms ().move_block == MOVE_ALL) |
899 | { |
931 | { |
900 | while (inv) |
932 | while (inv) |
901 | { |
933 | { |
902 | inv->destroy_inv (drop_to_ground); |
934 | inv->destroy_inv (false); |
903 | inv->destroy (); |
935 | inv->destroy (); |
904 | } |
936 | } |
905 | } |
937 | } |
906 | else |
938 | else |
907 | { /* Put objects in inventory onto this space */ |
939 | { /* Put objects in inventory onto this space */ |
… | |
… | |
913 | || op->flag [FLAG_NO_DROP] |
945 | || op->flag [FLAG_NO_DROP] |
914 | || op->type == RUNE |
946 | || op->type == RUNE |
915 | || op->type == TRAP |
947 | || op->type == TRAP |
916 | || op->flag [FLAG_IS_A_TEMPLATE] |
948 | || op->flag [FLAG_IS_A_TEMPLATE] |
917 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
949 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
918 | op->destroy (); |
950 | op->destroy (true); |
919 | else |
951 | else |
920 | map->insert (op, x, y); |
952 | map->insert (op, x, y); |
921 | } |
953 | } |
922 | } |
954 | } |
923 | } |
955 | } |
… | |
… | |
927 | object *op = new object; |
959 | object *op = new object; |
928 | op->link (); |
960 | op->link (); |
929 | return op; |
961 | return op; |
930 | } |
962 | } |
931 | |
963 | |
|
|
964 | static struct freed_map : maptile |
|
|
965 | { |
|
|
966 | freed_map () |
|
|
967 | { |
|
|
968 | path = "<freed objects map>"; |
|
|
969 | name = "/internal/freed_objects_map"; |
|
|
970 | width = 3; |
|
|
971 | height = 3; |
|
|
972 | nodrop = 1; |
|
|
973 | |
|
|
974 | alloc (); |
|
|
975 | in_memory = MAP_ACTIVE; |
|
|
976 | } |
|
|
977 | } freed_map; // freed objects are moved here to avoid crashes |
|
|
978 | |
932 | void |
979 | void |
933 | object::do_destroy () |
980 | object::do_destroy () |
934 | { |
981 | { |
935 | if (object *pl = visible_to ()) |
|
|
936 | esrv_del_item (pl->contr, count); |
|
|
937 | |
|
|
938 | attachable::do_destroy (); |
|
|
939 | |
|
|
940 | if (flag [FLAG_IS_LINKED]) |
982 | if (flag [FLAG_IS_LINKED]) |
941 | remove_button_link (this); |
983 | remove_button_link (this); |
942 | |
984 | |
943 | if (flag [FLAG_FRIENDLY]) |
985 | if (flag [FLAG_FRIENDLY]) |
944 | remove_friendly_object (this); |
986 | remove_friendly_object (this); |
945 | |
987 | |
946 | if (!flag [FLAG_REMOVED]) |
|
|
947 | remove (); |
988 | remove (); |
948 | |
989 | |
949 | destroy_inv (true); |
990 | attachable::do_destroy (); |
950 | |
991 | |
951 | deactivate (); |
992 | deactivate (); |
952 | unlink (); |
993 | unlink (); |
953 | |
994 | |
954 | flag [FLAG_FREED] = 1; |
995 | flag [FLAG_FREED] = 1; |
955 | |
996 | |
956 | // hack to ensure that freed objects still have a valid map |
997 | // hack to ensure that freed objects still have a valid map |
957 | { |
|
|
958 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
959 | |
|
|
960 | if (!freed_map) |
|
|
961 | { |
|
|
962 | freed_map = new maptile; |
|
|
963 | |
|
|
964 | freed_map->path = "<freed objects map>"; |
|
|
965 | freed_map->name = "/internal/freed_objects_map"; |
|
|
966 | freed_map->width = 3; |
|
|
967 | freed_map->height = 3; |
|
|
968 | freed_map->nodrop = 1; |
|
|
969 | |
|
|
970 | freed_map->alloc (); |
|
|
971 | freed_map->in_memory = MAP_ACTIVE; |
|
|
972 | } |
|
|
973 | |
|
|
974 | map = freed_map; |
998 | map = &freed_map; |
975 | x = 1; |
999 | x = 1; |
976 | y = 1; |
1000 | y = 1; |
977 | } |
|
|
978 | |
1001 | |
979 | if (more) |
1002 | if (more) |
980 | { |
1003 | { |
981 | more->destroy (); |
1004 | more->destroy (); |
982 | more = 0; |
1005 | more = 0; |
… | |
… | |
995 | object::destroy (bool destroy_inventory) |
1018 | object::destroy (bool destroy_inventory) |
996 | { |
1019 | { |
997 | if (destroyed ()) |
1020 | if (destroyed ()) |
998 | return; |
1021 | return; |
999 | |
1022 | |
|
|
1023 | if (!is_head () && !head->destroyed ()) |
|
|
1024 | { |
|
|
1025 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
|
|
1026 | head->destroy (destroy_inventory); |
|
|
1027 | return; |
|
|
1028 | } |
|
|
1029 | |
1000 | if (destroy_inventory) |
1030 | destroy_inv (!destroy_inventory); |
1001 | destroy_inv (false); |
|
|
1002 | |
1031 | |
1003 | if (is_head ()) |
1032 | if (is_head ()) |
1004 | if (sound_destroy) |
1033 | if (sound_destroy) |
1005 | play_sound (sound_destroy); |
1034 | play_sound (sound_destroy); |
1006 | else if (flag [FLAG_MONSTER]) |
1035 | else if (flag [FLAG_MONSTER]) |
… | |
… | |
1020 | object::do_remove () |
1049 | object::do_remove () |
1021 | { |
1050 | { |
1022 | object *tmp, *last = 0; |
1051 | object *tmp, *last = 0; |
1023 | object *otmp; |
1052 | object *otmp; |
1024 | |
1053 | |
1025 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
1054 | if (flag [FLAG_REMOVED]) |
1026 | return; |
1055 | return; |
1027 | |
1056 | |
1028 | SET_FLAG (this, FLAG_REMOVED); |
|
|
1029 | INVOKE_OBJECT (REMOVE, this); |
1057 | INVOKE_OBJECT (REMOVE, this); |
|
|
1058 | |
|
|
1059 | flag [FLAG_REMOVED] = true; |
1030 | |
1060 | |
1031 | if (more) |
1061 | if (more) |
1032 | more->remove (); |
1062 | more->remove (); |
1033 | |
1063 | |
1034 | /* |
1064 | /* |
1035 | * In this case, the object to be removed is in someones |
1065 | * In this case, the object to be removed is in someones |
1036 | * inventory. |
1066 | * inventory. |
1037 | */ |
1067 | */ |
1038 | if (env) |
1068 | if (env) |
1039 | { |
1069 | { |
|
|
1070 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
|
|
1071 | if (object *pl = visible_to ()) |
|
|
1072 | esrv_del_item (pl->contr, count); |
|
|
1073 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
|
|
1074 | |
1040 | adjust_weight (env, -total_weight ()); |
1075 | adjust_weight (env, -total_weight ()); |
1041 | |
1076 | |
1042 | *(above ? &above->below : &env->inv) = below; |
1077 | *(above ? &above->below : &env->inv) = below; |
1043 | |
1078 | |
1044 | if (below) |
1079 | if (below) |
… | |
… | |
1062 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1097 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1063 | otmp->update_stats (); |
1098 | otmp->update_stats (); |
1064 | } |
1099 | } |
1065 | else if (map) |
1100 | else if (map) |
1066 | { |
1101 | { |
1067 | if (type == PLAYER) |
|
|
1068 | { |
|
|
1069 | // leaving a spot always closes any open container on the ground |
|
|
1070 | if (container && !container->env) |
|
|
1071 | // this causes spurious floorbox updates, but it ensures |
|
|
1072 | // that the CLOSE event is being sent. |
|
|
1073 | close_container (); |
|
|
1074 | |
|
|
1075 | --map->players; |
|
|
1076 | map->touch (); |
|
|
1077 | } |
|
|
1078 | |
|
|
1079 | map->dirty = true; |
1102 | map->dirty = true; |
1080 | mapspace &ms = this->ms (); |
1103 | mapspace &ms = this->ms (); |
|
|
1104 | |
|
|
1105 | if (object *pl = ms.player ()) |
|
|
1106 | { |
|
|
1107 | if (type == PLAYER) // this == pl(!) |
|
|
1108 | { |
|
|
1109 | // leaving a spot always closes any open container on the ground |
|
|
1110 | if (container && !container->env) |
|
|
1111 | // this causes spurious floorbox updates, but it ensures |
|
|
1112 | // that the CLOSE event is being sent. |
|
|
1113 | close_container (); |
|
|
1114 | |
|
|
1115 | --map->players; |
|
|
1116 | map->touch (); |
|
|
1117 | } |
|
|
1118 | else if (pl->container == this) |
|
|
1119 | { |
|
|
1120 | // removing a container should close it |
|
|
1121 | close_container (); |
|
|
1122 | } |
|
|
1123 | |
|
|
1124 | esrv_del_item (pl->contr, count); |
|
|
1125 | } |
1081 | |
1126 | |
1082 | /* link the object above us */ |
1127 | /* link the object above us */ |
1083 | if (above) |
1128 | if (above) |
1084 | above->below = below; |
1129 | above->below = below; |
1085 | else |
1130 | else |
… | |
… | |
1115 | * removed (most likely destroyed), update the player view |
1160 | * removed (most likely destroyed), update the player view |
1116 | * appropriately. |
1161 | * appropriately. |
1117 | */ |
1162 | */ |
1118 | pl->close_container (); |
1163 | pl->close_container (); |
1119 | |
1164 | |
1120 | pl->contr->ns->floorbox_update (); |
1165 | //TODO: the floorbox prev/next might need updating |
|
|
1166 | esrv_del_item (pl->contr, count); |
1121 | } |
1167 | } |
1122 | |
1168 | |
1123 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1169 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1124 | { |
1170 | { |
1125 | /* No point updating the players look faces if he is the object |
1171 | /* No point updating the players look faces if he is the object |
… | |
… | |
1169 | if (!top) |
1215 | if (!top) |
1170 | for (top = op; top && top->above; top = top->above) |
1216 | for (top = op; top && top->above; top = top->above) |
1171 | ; |
1217 | ; |
1172 | |
1218 | |
1173 | for (; top; top = top->below) |
1219 | for (; top; top = top->below) |
1174 | { |
|
|
1175 | if (top == op) |
|
|
1176 | continue; |
|
|
1177 | |
|
|
1178 | if (object::can_merge (op, top)) |
1220 | if (object::can_merge (op, top)) |
1179 | { |
1221 | { |
1180 | top->nrof += op->nrof; |
1222 | top->nrof += op->nrof; |
1181 | |
1223 | |
1182 | /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ |
1224 | if (object *pl = top->visible_to ()) |
1183 | op->weight = 0; /* Don't want any adjustements now */ |
1225 | esrv_update_item (UPD_NROF, pl, top); |
|
|
1226 | |
|
|
1227 | op->weight = 0; // cancel the addition above |
|
|
1228 | op->carrying = 0; // must be 0 already |
|
|
1229 | |
1184 | op->destroy (); |
1230 | op->destroy (1); |
|
|
1231 | |
1185 | return top; |
1232 | return top; |
1186 | } |
1233 | } |
1187 | } |
|
|
1188 | |
1234 | |
1189 | return 0; |
1235 | return 0; |
1190 | } |
1236 | } |
1191 | |
1237 | |
1192 | void |
1238 | void |
… | |
… | |
1251 | object * |
1297 | object * |
1252 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1298 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1253 | { |
1299 | { |
1254 | assert (!op->flag [FLAG_FREED]); |
1300 | assert (!op->flag [FLAG_FREED]); |
1255 | |
1301 | |
1256 | object *top, *floor = NULL; |
|
|
1257 | |
|
|
1258 | op->remove (); |
1302 | op->remove (); |
1259 | |
1303 | |
1260 | /* Ideally, the caller figures this out. However, it complicates a lot |
1304 | /* Ideally, the caller figures this out. However, it complicates a lot |
1261 | * of areas of callers (eg, anything that uses find_free_spot would now |
1305 | * of areas of callers (eg, anything that uses find_free_spot would now |
1262 | * need extra work |
1306 | * need extra work |
1263 | */ |
1307 | */ |
1264 | if (!xy_normalise (m, op->x, op->y)) |
1308 | if (!xy_normalise (m, op->x, op->y)) |
1265 | { |
1309 | { |
1266 | op->destroy (); |
1310 | op->destroy (1); |
1267 | return 0; |
1311 | return 0; |
1268 | } |
1312 | } |
1269 | |
1313 | |
1270 | if (object *more = op->more) |
1314 | if (object *more = op->more) |
1271 | if (!insert_ob_in_map (more, m, originator, flag)) |
1315 | if (!insert_ob_in_map (more, m, originator, flag)) |
… | |
… | |
1280 | */ |
1324 | */ |
1281 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1325 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1282 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1326 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1283 | if (object::can_merge (op, tmp)) |
1327 | if (object::can_merge (op, tmp)) |
1284 | { |
1328 | { |
|
|
1329 | // TODO: we atcually want to update tmp, not op, |
|
|
1330 | // but some caller surely breaks when we return tmp |
|
|
1331 | // from here :/ |
1285 | op->nrof += tmp->nrof; |
1332 | op->nrof += tmp->nrof; |
1286 | tmp->destroy (1); |
1333 | tmp->destroy (1); |
1287 | } |
1334 | } |
1288 | |
1335 | |
1289 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1336 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
… | |
… | |
1311 | /* since *below* originator, no need to update top */ |
1358 | /* since *below* originator, no need to update top */ |
1312 | originator->below = op; |
1359 | originator->below = op; |
1313 | } |
1360 | } |
1314 | else |
1361 | else |
1315 | { |
1362 | { |
|
|
1363 | object *top, *floor = NULL; |
|
|
1364 | |
1316 | top = ms.bot; |
1365 | top = ms.bot; |
1317 | |
1366 | |
1318 | /* If there are other objects, then */ |
1367 | /* If there are other objects, then */ |
1319 | if (top) |
1368 | if (top) |
1320 | { |
1369 | { |
… | |
… | |
1419 | } |
1468 | } |
1420 | |
1469 | |
1421 | op->map->dirty = true; |
1470 | op->map->dirty = true; |
1422 | |
1471 | |
1423 | if (object *pl = ms.player ()) |
1472 | if (object *pl = ms.player ()) |
1424 | pl->contr->ns->floorbox_update (); |
1473 | //TODO: the floorbox prev/next might need updating |
|
|
1474 | esrv_send_item (pl, op); |
1425 | |
1475 | |
1426 | /* If this object glows, it may affect lighting conditions that are |
1476 | /* If this object glows, it may affect lighting conditions that are |
1427 | * visible to others on this map. But update_all_los is really |
1477 | * visible to others on this map. But update_all_los is really |
1428 | * an inefficient way to do this, as it means los for all players |
1478 | * an inefficient way to do this, as it means los for all players |
1429 | * on the map will get recalculated. The players could very well |
1479 | * on the map will get recalculated. The players could very well |
… | |
… | |
1494 | return where->env->insert (this); |
1544 | return where->env->insert (this); |
1495 | else |
1545 | else |
1496 | return where->map->insert (this, where->x, where->y, originator, flags); |
1546 | return where->map->insert (this, where->x, where->y, originator, flags); |
1497 | } |
1547 | } |
1498 | |
1548 | |
1499 | // find player who can see this object |
|
|
1500 | object * |
|
|
1501 | object::visible_to () const |
|
|
1502 | { |
|
|
1503 | if (!flag [FLAG_REMOVED]) |
|
|
1504 | { |
|
|
1505 | // see if we are in a container of sorts |
|
|
1506 | if (env) |
|
|
1507 | { |
|
|
1508 | // the player inventory itself is always visible |
|
|
1509 | if (env->type == PLAYER) |
|
|
1510 | return env; |
|
|
1511 | |
|
|
1512 | // else a player could have our env open |
|
|
1513 | object *envest = env->outer_env (); |
|
|
1514 | |
|
|
1515 | // the player itself is always on a map, so we will find him here |
|
|
1516 | // even if our inv is in a player. |
|
|
1517 | if (envest->is_on_map ()) |
|
|
1518 | if (object *pl = envest->ms ().player ()) |
|
|
1519 | if (pl->container == env) |
|
|
1520 | return pl; |
|
|
1521 | } |
|
|
1522 | else |
|
|
1523 | { |
|
|
1524 | // maybe there is a player standing on the same mapspace |
|
|
1525 | // this will catch the case where "this" is a player |
|
|
1526 | if (object *pl = ms ().player ()) |
|
|
1527 | return pl; |
|
|
1528 | } |
|
|
1529 | } |
|
|
1530 | |
|
|
1531 | return 0; |
|
|
1532 | } |
|
|
1533 | |
|
|
1534 | /* |
1549 | /* |
1535 | * decrease(object, number) decreases a specified number from |
1550 | * decrease(object, number) decreases a specified number from |
1536 | * the amount of an object. If the amount reaches 0, the object |
1551 | * the amount of an object. If the amount reaches 0, the object |
1537 | * is subsequently removed and freed. |
1552 | * is subsequently removed and freed. |
1538 | * |
1553 | * |
… | |
… | |
1638 | if (object::can_merge (tmp, op)) |
1653 | if (object::can_merge (tmp, op)) |
1639 | { |
1654 | { |
1640 | /* return the original object and remove inserted object |
1655 | /* return the original object and remove inserted object |
1641 | (client needs the original object) */ |
1656 | (client needs the original object) */ |
1642 | tmp->nrof += op->nrof; |
1657 | tmp->nrof += op->nrof; |
|
|
1658 | |
|
|
1659 | if (object *pl = tmp->visible_to ()) |
|
|
1660 | esrv_update_item (UPD_NROF, pl, tmp); |
|
|
1661 | |
1643 | adjust_weight (this, op->total_weight ()); |
1662 | adjust_weight (this, op->total_weight ()); |
1644 | |
1663 | |
1645 | op->destroy (1); |
1664 | op->destroy (1); |
1646 | op = tmp; |
1665 | op = tmp; |
1647 | goto inserted; |
1666 | goto inserted; |
… | |
… | |
1661 | |
1680 | |
1662 | inv = op; |
1681 | inv = op; |
1663 | |
1682 | |
1664 | op->flag [FLAG_REMOVED] = 0; |
1683 | op->flag [FLAG_REMOVED] = 0; |
1665 | |
1684 | |
|
|
1685 | if (object *pl = op->visible_to ()) |
|
|
1686 | esrv_send_item (pl, op); |
|
|
1687 | |
1666 | adjust_weight (this, op->total_weight ()); |
1688 | adjust_weight (this, op->total_weight ()); |
1667 | |
1689 | |
1668 | inserted: |
1690 | inserted: |
1669 | /* reset the light list and los of the players on the map */ |
1691 | /* reset the light list and los of the players on the map */ |
1670 | if (op->glow_radius && map && map->darkness) |
1692 | if (op->glow_radius && map && map->darkness) |
1671 | update_all_los (map, x, y); |
1693 | update_all_los (map, x, y); |
1672 | |
1694 | |
1673 | if (object *otmp = in_player ()) |
1695 | // if this is a player's inventory, update stats |
1674 | if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1696 | if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER]) |
1675 | otmp->update_stats (); |
1697 | update_stats (); |
1676 | |
1698 | |
1677 | INVOKE_OBJECT (INSERT, this); |
1699 | INVOKE_OBJECT (INSERT, this); |
1678 | |
1700 | |
1679 | return op; |
1701 | return op; |
1680 | } |
1702 | } |
… | |
… | |
2558 | &name, |
2580 | &name, |
2559 | title ? "\",title:\"" : "", |
2581 | title ? "\",title:\"" : "", |
2560 | title ? (const char *)title : "", |
2582 | title ? (const char *)title : "", |
2561 | flag_desc (flagdesc, 512), type); |
2583 | flag_desc (flagdesc, 512), type); |
2562 | |
2584 | |
2563 | if (!this->flag[FLAG_REMOVED] && env) |
2585 | if (!flag[FLAG_REMOVED] && env) |
2564 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2586 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2565 | |
2587 | |
2566 | if (map) |
2588 | if (map) |
2567 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2589 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2568 | |
2590 | |
… | |
… | |
2598 | object::open_container (object *new_container) |
2620 | object::open_container (object *new_container) |
2599 | { |
2621 | { |
2600 | if (container == new_container) |
2622 | if (container == new_container) |
2601 | return; |
2623 | return; |
2602 | |
2624 | |
2603 | if (object *old_container = container) |
2625 | object *old_container = container; |
|
|
2626 | |
|
|
2627 | if (old_container) |
2604 | { |
2628 | { |
2605 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2629 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2606 | return; |
2630 | return; |
2607 | |
2631 | |
2608 | #if 0 |
2632 | #if 0 |
… | |
… | |
2610 | if (object *closer = old_container->inv) |
2634 | if (object *closer = old_container->inv) |
2611 | if (closer->type == CLOSE_CON) |
2635 | if (closer->type == CLOSE_CON) |
2612 | closer->destroy (); |
2636 | closer->destroy (); |
2613 | #endif |
2637 | #endif |
2614 | |
2638 | |
|
|
2639 | // make sure the container is available |
|
|
2640 | esrv_send_item (this, old_container); |
|
|
2641 | |
2615 | old_container->flag [FLAG_APPLIED] = 0; |
2642 | old_container->flag [FLAG_APPLIED] = false; |
2616 | container = 0; |
2643 | container = 0; |
2617 | |
2644 | |
|
|
2645 | // client needs item update to make it work, client bug requires this to be separate |
2618 | esrv_update_item (UPD_FLAGS, this, old_container); |
2646 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2647 | |
2619 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2648 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2620 | play_sound (sound_find ("chest_close")); |
2649 | play_sound (sound_find ("chest_close")); |
2621 | } |
2650 | } |
2622 | |
2651 | |
2623 | if (new_container) |
2652 | if (new_container) |
… | |
… | |
2636 | } |
2665 | } |
2637 | #endif |
2666 | #endif |
2638 | |
2667 | |
2639 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2668 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2640 | |
2669 | |
|
|
2670 | // make sure the container is available, client bug requires this to be separate |
|
|
2671 | esrv_send_item (this, new_container); |
|
|
2672 | |
2641 | new_container->flag [FLAG_APPLIED] = 1; |
2673 | new_container->flag [FLAG_APPLIED] = true; |
2642 | container = new_container; |
2674 | container = new_container; |
2643 | |
2675 | |
|
|
2676 | // client needs flag change |
2644 | esrv_update_item (UPD_FLAGS, this, new_container); |
2677 | esrv_update_item (UPD_FLAGS, this, new_container); |
2645 | esrv_send_inventory (this, new_container); |
2678 | esrv_send_inventory (this, new_container); |
2646 | play_sound (sound_find ("chest_open")); |
2679 | play_sound (sound_find ("chest_open")); |
2647 | } |
2680 | } |
|
|
2681 | // else if (!old_container->env && contr && contr->ns) |
|
|
2682 | // contr->ns->floorbox_reset (); |
2648 | } |
2683 | } |
2649 | |
2684 | |
2650 | object * |
2685 | object * |
2651 | object::force_find (const shstr name) |
2686 | object::force_find (const shstr name) |
2652 | { |
2687 | { |