… | |
… | |
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 | */ |
… | |
… | |
694 | * UP_OBJ_FACE: only the objects face has changed. |
746 | * UP_OBJ_FACE: only the objects face has changed. |
695 | */ |
747 | */ |
696 | void |
748 | void |
697 | update_object (object *op, int action) |
749 | update_object (object *op, int action) |
698 | { |
750 | { |
699 | if (op == NULL) |
751 | if (!op) |
700 | { |
752 | { |
701 | /* this should never happen */ |
753 | /* this should never happen */ |
702 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
754 | LOG (llevError | logBacktrace, "update_object() called for NULL object.\n"); |
703 | return; |
755 | return; |
704 | } |
756 | } |
705 | |
757 | |
706 | if (op->env) |
758 | if (!op->is_on_map ()) |
707 | { |
759 | { |
708 | /* Animation is currently handled by client, so nothing |
760 | /* Animation is currently handled by client, so nothing |
709 | * to do in this case. |
761 | * to do in this case. |
710 | */ |
762 | */ |
711 | return; |
763 | return; |
712 | } |
764 | } |
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 | |
765 | |
720 | /* make sure the object is within map boundaries */ |
766 | /* 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) |
767 | if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) |
722 | { |
768 | { |
723 | LOG (llevError, "update_object() called for object out of map!\n"); |
769 | LOG (llevError, "update_object() called for object out of map!\n"); |
… | |
… | |
866 | object::destroy_inv (bool drop_to_ground) |
912 | object::destroy_inv (bool drop_to_ground) |
867 | { |
913 | { |
868 | // need to check first, because the checks below might segfault |
914 | // need to check first, because the checks below might segfault |
869 | // as we might be on an invalid mapspace and crossfire code |
915 | // as we might be on an invalid mapspace and crossfire code |
870 | // is too buggy to ensure that the inventory is empty. |
916 | // is too buggy to ensure that the inventory is empty. |
871 | // corollary: if you create arrows etc. with stuff in tis inventory, |
917 | // corollary: if you create arrows etc. with stuff in its inventory, |
872 | // cf will crash below with off-map x and y |
918 | // cf will crash below with off-map x and y |
873 | if (!inv) |
919 | if (!inv) |
874 | return; |
920 | return; |
875 | |
921 | |
876 | /* Only if the space blocks everything do we not process - |
922 | /* Only if the space blocks everything do we not process - |
… | |
… | |
883 | || map->nodrop |
929 | || map->nodrop |
884 | || ms ().move_block == MOVE_ALL) |
930 | || ms ().move_block == MOVE_ALL) |
885 | { |
931 | { |
886 | while (inv) |
932 | while (inv) |
887 | { |
933 | { |
888 | inv->destroy_inv (drop_to_ground); |
934 | inv->destroy_inv (false); |
889 | inv->destroy (); |
935 | inv->destroy (); |
890 | } |
936 | } |
891 | } |
937 | } |
892 | else |
938 | else |
893 | { /* Put objects in inventory onto this space */ |
939 | { /* Put objects in inventory onto this space */ |
… | |
… | |
899 | || op->flag [FLAG_NO_DROP] |
945 | || op->flag [FLAG_NO_DROP] |
900 | || op->type == RUNE |
946 | || op->type == RUNE |
901 | || op->type == TRAP |
947 | || op->type == TRAP |
902 | || op->flag [FLAG_IS_A_TEMPLATE] |
948 | || op->flag [FLAG_IS_A_TEMPLATE] |
903 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
949 | || op->flag [FLAG_DESTROY_ON_DEATH]) |
904 | op->destroy (); |
950 | op->destroy (true); |
905 | else |
951 | else |
906 | map->insert (op, x, y); |
952 | map->insert (op, x, y); |
907 | } |
953 | } |
908 | } |
954 | } |
909 | } |
955 | } |
… | |
… | |
916 | } |
962 | } |
917 | |
963 | |
918 | void |
964 | void |
919 | object::do_destroy () |
965 | object::do_destroy () |
920 | { |
966 | { |
921 | attachable::do_destroy (); |
|
|
922 | |
|
|
923 | if (flag [FLAG_IS_LINKED]) |
967 | if (flag [FLAG_IS_LINKED]) |
924 | remove_button_link (this); |
968 | remove_button_link (this); |
925 | |
969 | |
926 | if (flag [FLAG_FRIENDLY]) |
970 | if (flag [FLAG_FRIENDLY]) |
927 | remove_friendly_object (this); |
971 | remove_friendly_object (this); |
928 | |
972 | |
929 | if (!flag [FLAG_REMOVED]) |
|
|
930 | remove (); |
973 | remove (); |
931 | |
974 | |
932 | destroy_inv (true); |
975 | attachable::do_destroy (); |
933 | |
976 | |
934 | deactivate (); |
977 | deactivate (); |
935 | unlink (); |
978 | unlink (); |
936 | |
979 | |
937 | flag [FLAG_FREED] = 1; |
980 | flag [FLAG_FREED] = 1; |
… | |
… | |
978 | object::destroy (bool destroy_inventory) |
1021 | object::destroy (bool destroy_inventory) |
979 | { |
1022 | { |
980 | if (destroyed ()) |
1023 | if (destroyed ()) |
981 | return; |
1024 | return; |
982 | |
1025 | |
|
|
1026 | if (!is_head () && !head->destroyed ()) |
|
|
1027 | { |
|
|
1028 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
|
|
1029 | head->destroy (destroy_inventory); |
|
|
1030 | } |
|
|
1031 | |
983 | if (destroy_inventory) |
1032 | destroy_inv (!destroy_inventory); |
984 | destroy_inv (false); |
|
|
985 | |
1033 | |
986 | if (is_head ()) |
1034 | if (is_head ()) |
987 | if (sound_destroy) |
1035 | if (sound_destroy) |
988 | play_sound (sound_destroy); |
1036 | play_sound (sound_destroy); |
989 | else if (flag [FLAG_MONSTER]) |
1037 | else if (flag [FLAG_MONSTER]) |
… | |
… | |
1003 | object::do_remove () |
1051 | object::do_remove () |
1004 | { |
1052 | { |
1005 | object *tmp, *last = 0; |
1053 | object *tmp, *last = 0; |
1006 | object *otmp; |
1054 | object *otmp; |
1007 | |
1055 | |
1008 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
1056 | if (flag [FLAG_REMOVED]) |
1009 | return; |
1057 | return; |
1010 | |
1058 | |
1011 | SET_FLAG (this, FLAG_REMOVED); |
|
|
1012 | INVOKE_OBJECT (REMOVE, this); |
1059 | INVOKE_OBJECT (REMOVE, this); |
|
|
1060 | |
|
|
1061 | flag [FLAG_REMOVED] = true; |
1013 | |
1062 | |
1014 | if (more) |
1063 | if (more) |
1015 | more->remove (); |
1064 | more->remove (); |
1016 | |
1065 | |
1017 | /* |
1066 | /* |
1018 | * In this case, the object to be removed is in someones |
1067 | * In this case, the object to be removed is in someones |
1019 | * inventory. |
1068 | * inventory. |
1020 | */ |
1069 | */ |
1021 | if (env) |
1070 | if (env) |
1022 | { |
1071 | { |
|
|
1072 | flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed |
|
|
1073 | if (object *pl = visible_to ()) |
|
|
1074 | esrv_del_item (pl->contr, count); |
|
|
1075 | flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed |
|
|
1076 | |
1023 | adjust_weight (env, -total_weight ()); |
1077 | adjust_weight (env, -total_weight ()); |
1024 | |
1078 | |
1025 | *(above ? &above->below : &env->inv) = below; |
1079 | *(above ? &above->below : &env->inv) = below; |
1026 | |
1080 | |
1027 | if (below) |
1081 | if (below) |
… | |
… | |
1045 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1099 | if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1046 | otmp->update_stats (); |
1100 | otmp->update_stats (); |
1047 | } |
1101 | } |
1048 | else if (map) |
1102 | else if (map) |
1049 | { |
1103 | { |
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; |
1104 | map->dirty = true; |
1063 | mapspace &ms = this->ms (); |
1105 | mapspace &ms = this->ms (); |
|
|
1106 | |
|
|
1107 | if (object *pl = ms.player ()) |
|
|
1108 | { |
|
|
1109 | if (type == PLAYER) // this == pl(!) |
|
|
1110 | { |
|
|
1111 | // leaving a spot always closes any open container on the ground |
|
|
1112 | if (container && !container->env) |
|
|
1113 | // this causes spurious floorbox updates, but it ensures |
|
|
1114 | // that the CLOSE event is being sent. |
|
|
1115 | close_container (); |
|
|
1116 | |
|
|
1117 | --map->players; |
|
|
1118 | map->touch (); |
|
|
1119 | } |
|
|
1120 | else if (pl->container == this) |
|
|
1121 | { |
|
|
1122 | // removing a container should close it |
|
|
1123 | close_container (); |
|
|
1124 | } |
|
|
1125 | |
|
|
1126 | esrv_del_item (pl->contr, count); |
|
|
1127 | } |
1064 | |
1128 | |
1065 | /* link the object above us */ |
1129 | /* link the object above us */ |
1066 | if (above) |
1130 | if (above) |
1067 | above->below = below; |
1131 | above->below = below; |
1068 | else |
1132 | else |
… | |
… | |
1098 | * removed (most likely destroyed), update the player view |
1162 | * removed (most likely destroyed), update the player view |
1099 | * appropriately. |
1163 | * appropriately. |
1100 | */ |
1164 | */ |
1101 | pl->close_container (); |
1165 | pl->close_container (); |
1102 | |
1166 | |
1103 | pl->contr->ns->floorbox_update (); |
1167 | //TODO: the floorbox prev/next might need updating |
|
|
1168 | esrv_del_item (pl->contr, count); |
1104 | } |
1169 | } |
1105 | |
1170 | |
1106 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1171 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1107 | { |
1172 | { |
1108 | /* No point updating the players look faces if he is the object |
1173 | /* No point updating the players look faces if he is the object |
… | |
… | |
1152 | if (!top) |
1217 | if (!top) |
1153 | for (top = op; top && top->above; top = top->above) |
1218 | for (top = op; top && top->above; top = top->above) |
1154 | ; |
1219 | ; |
1155 | |
1220 | |
1156 | for (; top; top = top->below) |
1221 | for (; top; top = top->below) |
1157 | { |
|
|
1158 | if (top == op) |
|
|
1159 | continue; |
|
|
1160 | |
|
|
1161 | if (object::can_merge (op, top)) |
1222 | if (object::can_merge (op, top)) |
1162 | { |
1223 | { |
1163 | top->nrof += op->nrof; |
1224 | top->nrof += op->nrof; |
1164 | |
1225 | |
1165 | /* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ |
1226 | if (object *pl = top->visible_to ()) |
1166 | op->weight = 0; /* Don't want any adjustements now */ |
1227 | esrv_update_item (UPD_NROF, pl, top); |
|
|
1228 | |
|
|
1229 | op->weight = 0; // cancel the addition above |
|
|
1230 | op->carrying = 0; // must be 0 already |
|
|
1231 | |
1167 | op->destroy (); |
1232 | op->destroy (1); |
|
|
1233 | |
1168 | return top; |
1234 | return top; |
1169 | } |
1235 | } |
1170 | } |
|
|
1171 | |
1236 | |
1172 | return 0; |
1237 | return 0; |
1173 | } |
1238 | } |
1174 | |
1239 | |
1175 | void |
1240 | void |
… | |
… | |
1234 | object * |
1299 | object * |
1235 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1300 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1236 | { |
1301 | { |
1237 | assert (!op->flag [FLAG_FREED]); |
1302 | assert (!op->flag [FLAG_FREED]); |
1238 | |
1303 | |
1239 | object *top, *floor = NULL; |
|
|
1240 | |
|
|
1241 | op->remove (); |
1304 | op->remove (); |
1242 | |
1305 | |
1243 | /* Ideally, the caller figures this out. However, it complicates a lot |
1306 | /* 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 |
1307 | * of areas of callers (eg, anything that uses find_free_spot would now |
1245 | * need extra work |
1308 | * need extra work |
1246 | */ |
1309 | */ |
1247 | if (!xy_normalise (m, op->x, op->y)) |
1310 | if (!xy_normalise (m, op->x, op->y)) |
1248 | { |
1311 | { |
1249 | op->destroy (); |
1312 | op->destroy (1); |
1250 | return 0; |
1313 | return 0; |
1251 | } |
1314 | } |
1252 | |
1315 | |
1253 | if (object *more = op->more) |
1316 | if (object *more = op->more) |
1254 | if (!insert_ob_in_map (more, m, originator, flag)) |
1317 | if (!insert_ob_in_map (more, m, originator, flag)) |
… | |
… | |
1263 | */ |
1326 | */ |
1264 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1327 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1265 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1328 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
1266 | if (object::can_merge (op, tmp)) |
1329 | if (object::can_merge (op, tmp)) |
1267 | { |
1330 | { |
|
|
1331 | // TODO: we atcually want to update tmp, not op, |
|
|
1332 | // but some caller surely breaks when we return tmp |
|
|
1333 | // from here :/ |
1268 | op->nrof += tmp->nrof; |
1334 | op->nrof += tmp->nrof; |
1269 | tmp->destroy (1); |
1335 | tmp->destroy (1); |
1270 | } |
1336 | } |
1271 | |
1337 | |
1272 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1338 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
… | |
… | |
1294 | /* since *below* originator, no need to update top */ |
1360 | /* since *below* originator, no need to update top */ |
1295 | originator->below = op; |
1361 | originator->below = op; |
1296 | } |
1362 | } |
1297 | else |
1363 | else |
1298 | { |
1364 | { |
|
|
1365 | object *top, *floor = NULL; |
|
|
1366 | |
1299 | top = ms.bot; |
1367 | top = ms.bot; |
1300 | |
1368 | |
1301 | /* If there are other objects, then */ |
1369 | /* If there are other objects, then */ |
1302 | if (top) |
1370 | if (top) |
1303 | { |
1371 | { |
… | |
… | |
1402 | } |
1470 | } |
1403 | |
1471 | |
1404 | op->map->dirty = true; |
1472 | op->map->dirty = true; |
1405 | |
1473 | |
1406 | if (object *pl = ms.player ()) |
1474 | if (object *pl = ms.player ()) |
1407 | pl->contr->ns->floorbox_update (); |
1475 | //TODO: the floorbox prev/next might need updating |
|
|
1476 | esrv_send_item (pl, op); |
1408 | |
1477 | |
1409 | /* If this object glows, it may affect lighting conditions that are |
1478 | /* If this object glows, it may affect lighting conditions that are |
1410 | * visible to others on this map. But update_all_los is really |
1479 | * 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 |
1480 | * 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 |
1481 | * on the map will get recalculated. The players could very well |
… | |
… | |
1477 | return where->env->insert (this); |
1546 | return where->env->insert (this); |
1478 | else |
1547 | else |
1479 | return where->map->insert (this, where->x, where->y, originator, flags); |
1548 | return where->map->insert (this, where->x, where->y, originator, flags); |
1480 | } |
1549 | } |
1481 | |
1550 | |
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 | /* |
1551 | /* |
1517 | * decrease(object, number) decreases a specified number from |
1552 | * decrease(object, number) decreases a specified number from |
1518 | * the amount of an object. If the amount reaches 0, the object |
1553 | * the amount of an object. If the amount reaches 0, the object |
1519 | * is subsequently removed and freed. |
1554 | * is subsequently removed and freed. |
1520 | * |
1555 | * |
1521 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1556 | * Return value: 'op' if something is left, NULL if the amount reached 0 |
1522 | */ |
1557 | */ |
1523 | bool |
1558 | bool |
1524 | object::decrease (sint32 nr) |
1559 | object::decrease (sint32 nr) |
1525 | { |
1560 | { |
|
|
1561 | if (!nr) |
|
|
1562 | return true; |
|
|
1563 | |
1526 | nr = min (nr, nrof); |
1564 | nr = min (nr, nrof); |
1527 | |
1565 | |
1528 | if (!nr) |
|
|
1529 | return 1; |
|
|
1530 | |
|
|
1531 | nrof -= nr; |
1566 | nrof -= nr; |
1532 | |
1567 | |
1533 | object *visible = visible_to (this); |
|
|
1534 | |
|
|
1535 | if (nrof) |
1568 | if (nrof) |
1536 | { |
1569 | { |
1537 | adjust_weight (env, -weight * nr); // carrying == 0 |
1570 | adjust_weight (env, -weight * nr); // carrying == 0 |
1538 | |
1571 | |
1539 | if (visible) |
1572 | if (object *pl = visible_to ()) |
1540 | esrv_send_item (visible, this); |
1573 | esrv_update_item (UPD_NROF, pl, this); |
1541 | |
1574 | |
1542 | return 1; |
1575 | return true; |
1543 | } |
1576 | } |
1544 | else |
1577 | else |
1545 | { |
1578 | { |
1546 | if (visible) |
|
|
1547 | esrv_del_item (visible->contr, count); |
|
|
1548 | |
|
|
1549 | this->destroy (1); |
1579 | destroy (1); |
1550 | return 0; |
1580 | return false; |
1551 | } |
1581 | } |
1552 | } |
1582 | } |
1553 | |
1583 | |
1554 | /* |
1584 | /* |
1555 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
1585 | * split(ob,nr) splits up ob into two parts. The part which |
1556 | * is returned contains nr objects, and the remaining parts contains |
1586 | * is returned contains nr objects, and the remaining parts contains |
1557 | * the rest (or is removed and freed if that number is 0). |
1587 | * the rest (or is removed and returned if that number is 0). |
1558 | * On failure, NULL is returned, and the reason put into the |
1588 | * On failure, NULL is returned. |
1559 | * global static errmsg array. |
|
|
1560 | */ |
1589 | */ |
1561 | object * |
1590 | object * |
1562 | object::split (sint32 nr) |
1591 | object::split (sint32 nr) |
1563 | { |
1592 | { |
|
|
1593 | int have = number_of (); |
|
|
1594 | |
1564 | if (nrof < nr) |
1595 | if (have < nr) |
1565 | return 0; |
1596 | return 0; |
1566 | else if (nrof == nr) |
1597 | else if (have == nr) |
1567 | { |
1598 | { |
1568 | remove (); |
1599 | remove (); |
1569 | return this; |
1600 | return this; |
1570 | } |
1601 | } |
1571 | else |
1602 | else |
… | |
… | |
1574 | |
1605 | |
1575 | object *op = object_create_clone (this); |
1606 | object *op = object_create_clone (this); |
1576 | op->nrof = nr; |
1607 | op->nrof = nr; |
1577 | return op; |
1608 | return op; |
1578 | } |
1609 | } |
1579 | } |
|
|
1580 | |
|
|
1581 | //TODO: remove, but semantics differs from split_nr |
|
|
1582 | object * |
|
|
1583 | get_split_ob (object *orig_ob, uint32 nr) |
|
|
1584 | { |
|
|
1585 | if (orig_ob->nrof < nr) |
|
|
1586 | { |
|
|
1587 | sprintf (errmsg, "There are only %d %ss.", orig_ob->nrof ? orig_ob->nrof : 1, &orig_ob->name); |
|
|
1588 | return 0; |
|
|
1589 | } |
|
|
1590 | |
|
|
1591 | return orig_ob->split (nr); |
|
|
1592 | } |
1610 | } |
1593 | |
1611 | |
1594 | object * |
1612 | object * |
1595 | insert_ob_in_ob (object *op, object *where) |
1613 | insert_ob_in_ob (object *op, object *where) |
1596 | { |
1614 | { |
… | |
… | |
1637 | if (object::can_merge (tmp, op)) |
1655 | if (object::can_merge (tmp, op)) |
1638 | { |
1656 | { |
1639 | /* return the original object and remove inserted object |
1657 | /* return the original object and remove inserted object |
1640 | (client needs the original object) */ |
1658 | (client needs the original object) */ |
1641 | tmp->nrof += op->nrof; |
1659 | tmp->nrof += op->nrof; |
|
|
1660 | |
|
|
1661 | if (object *pl = tmp->visible_to ()) |
|
|
1662 | esrv_update_item (UPD_NROF, pl, tmp); |
|
|
1663 | |
|
|
1664 | adjust_weight (this, op->total_weight ()); |
|
|
1665 | |
1642 | op->destroy (1); |
1666 | op->destroy (1); |
1643 | op = tmp; |
1667 | op = tmp; |
1644 | goto inserted; |
1668 | goto inserted; |
1645 | } |
1669 | } |
1646 | |
1670 | |
… | |
… | |
1658 | |
1682 | |
1659 | inv = op; |
1683 | inv = op; |
1660 | |
1684 | |
1661 | op->flag [FLAG_REMOVED] = 0; |
1685 | op->flag [FLAG_REMOVED] = 0; |
1662 | |
1686 | |
|
|
1687 | if (object *pl = op->visible_to ()) |
|
|
1688 | esrv_send_item (pl, op); |
|
|
1689 | |
1663 | adjust_weight (this, op->total_weight ()); |
1690 | adjust_weight (this, op->total_weight ()); |
1664 | |
1691 | |
1665 | inserted: |
1692 | inserted: |
1666 | /* reset the light list and los of the players on the map */ |
1693 | /* reset the light list and los of the players on the map */ |
1667 | if (op->glow_radius && map && map->darkness) |
1694 | if (op->glow_radius && map && map->darkness) |
1668 | update_all_los (map, x, y); |
1695 | update_all_los (map, x, y); |
1669 | |
1696 | |
1670 | if (object *otmp = in_player ()) |
1697 | // if this is a player's inventory, update stats |
1671 | if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) |
1698 | if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER]) |
1672 | otmp->update_stats (); |
1699 | update_stats (); |
1673 | |
1700 | |
1674 | INVOKE_OBJECT (INSERT, this); |
1701 | INVOKE_OBJECT (INSERT, this); |
1675 | |
1702 | |
1676 | return op; |
1703 | return op; |
1677 | } |
1704 | } |
… | |
… | |
2555 | &name, |
2582 | &name, |
2556 | title ? "\",title:\"" : "", |
2583 | title ? "\",title:\"" : "", |
2557 | title ? (const char *)title : "", |
2584 | title ? (const char *)title : "", |
2558 | flag_desc (flagdesc, 512), type); |
2585 | flag_desc (flagdesc, 512), type); |
2559 | |
2586 | |
2560 | if (!this->flag[FLAG_REMOVED] && env) |
2587 | if (!flag[FLAG_REMOVED] && env) |
2561 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2588 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2562 | |
2589 | |
2563 | if (map) |
2590 | if (map) |
2564 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2591 | p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y); |
2565 | |
2592 | |
… | |
… | |
2595 | object::open_container (object *new_container) |
2622 | object::open_container (object *new_container) |
2596 | { |
2623 | { |
2597 | if (container == new_container) |
2624 | if (container == new_container) |
2598 | return; |
2625 | return; |
2599 | |
2626 | |
2600 | if (object *old_container = container) |
2627 | object *old_container = container; |
|
|
2628 | |
|
|
2629 | if (old_container) |
2601 | { |
2630 | { |
2602 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2631 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
2603 | return; |
2632 | return; |
2604 | |
2633 | |
2605 | #if 0 |
2634 | #if 0 |
… | |
… | |
2607 | if (object *closer = old_container->inv) |
2636 | if (object *closer = old_container->inv) |
2608 | if (closer->type == CLOSE_CON) |
2637 | if (closer->type == CLOSE_CON) |
2609 | closer->destroy (); |
2638 | closer->destroy (); |
2610 | #endif |
2639 | #endif |
2611 | |
2640 | |
|
|
2641 | // make sure the container is available |
|
|
2642 | esrv_send_item (this, old_container); |
|
|
2643 | |
2612 | old_container->flag [FLAG_APPLIED] = 0; |
2644 | old_container->flag [FLAG_APPLIED] = false; |
2613 | container = 0; |
2645 | container = 0; |
2614 | |
2646 | |
|
|
2647 | // client needs item update to make it work, client bug requires this to be separate |
2615 | esrv_update_item (UPD_FLAGS, this, old_container); |
2648 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2649 | |
2616 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2650 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
2617 | play_sound (sound_find ("chest_close")); |
2651 | play_sound (sound_find ("chest_close")); |
2618 | } |
2652 | } |
2619 | |
2653 | |
2620 | if (new_container) |
2654 | if (new_container) |
… | |
… | |
2633 | } |
2667 | } |
2634 | #endif |
2668 | #endif |
2635 | |
2669 | |
2636 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2670 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
2637 | |
2671 | |
|
|
2672 | // make sure the container is available, client bug requires this to be separate |
|
|
2673 | esrv_send_item (this, new_container); |
|
|
2674 | |
2638 | new_container->flag [FLAG_APPLIED] = 1; |
2675 | new_container->flag [FLAG_APPLIED] = true; |
2639 | container = new_container; |
2676 | container = new_container; |
2640 | |
2677 | |
|
|
2678 | // client needs flag change |
2641 | esrv_update_item (UPD_FLAGS, this, new_container); |
2679 | esrv_update_item (UPD_FLAGS, this, new_container); |
2642 | esrv_send_inventory (this, new_container); |
2680 | esrv_send_inventory (this, new_container); |
2643 | play_sound (sound_find ("chest_open")); |
2681 | play_sound (sound_find ("chest_open")); |
2644 | } |
2682 | } |
|
|
2683 | // else if (!old_container->env && contr && contr->ns) |
|
|
2684 | // contr->ns->floorbox_reset (); |
2645 | } |
2685 | } |
2646 | |
2686 | |
2647 | object * |
2687 | object * |
2648 | object::force_find (const shstr name) |
2688 | object::force_find (const shstr name) |
2649 | { |
2689 | { |