… | |
… | |
374 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
374 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
375 | * Some error messages. |
375 | * Some error messages. |
376 | * The result of the dump is stored in the static global errmsg array. |
376 | * The result of the dump is stored in the static global errmsg array. |
377 | */ |
377 | */ |
378 | |
378 | |
379 | void |
379 | char * |
380 | dump_object2 (object *op) |
|
|
381 | { |
|
|
382 | errmsg[0] = 0; |
|
|
383 | return; |
|
|
384 | //TODO//D#d# |
|
|
385 | #if 0 |
|
|
386 | char *cp; |
|
|
387 | |
|
|
388 | /* object *tmp;*/ |
|
|
389 | |
|
|
390 | if (op->arch != NULL) |
|
|
391 | { |
|
|
392 | strcat (errmsg, "arch "); |
|
|
393 | strcat (errmsg, op->arch->name ? op->arch->name : "(null)"); |
|
|
394 | strcat (errmsg, "\n"); |
|
|
395 | if ((cp = get_ob_diff (op, &empty_archetype->clone)) != NULL) |
|
|
396 | strcat (errmsg, cp); |
|
|
397 | # if 0 |
|
|
398 | /* Don't dump player diffs - they are too long, mostly meaningless, and |
|
|
399 | * will overflow the buffer. |
|
|
400 | * Changed so that we don't dump inventory either. This may |
|
|
401 | * also overflow the buffer. |
|
|
402 | */ |
|
|
403 | if (op->type != PLAYER && (cp = get_ob_diff (op, &empty_archetype->clone)) != NULL) |
|
|
404 | strcat (errmsg, cp); |
|
|
405 | for (tmp = op->inv; tmp; tmp = tmp->below) |
|
|
406 | dump_object2 (tmp); |
|
|
407 | # endif |
|
|
408 | strcat (errmsg, "end\n"); |
|
|
409 | } |
|
|
410 | else |
|
|
411 | { |
|
|
412 | strcat (errmsg, "Object "); |
|
|
413 | if (op->name == NULL) |
|
|
414 | strcat (errmsg, "(null)"); |
|
|
415 | else |
|
|
416 | strcat (errmsg, op->name); |
|
|
417 | strcat (errmsg, "\n"); |
|
|
418 | # if 0 |
|
|
419 | if ((cp = get_ob_diff (op, &empty_archetype->clone)) != NULL) |
|
|
420 | strcat (errmsg, cp); |
|
|
421 | for (tmp = op->inv; tmp; tmp = tmp->below) |
|
|
422 | dump_object2 (tmp); |
|
|
423 | # endif |
|
|
424 | strcat (errmsg, "end\n"); |
|
|
425 | } |
|
|
426 | #endif |
|
|
427 | } |
|
|
428 | |
|
|
429 | /* |
|
|
430 | * Dumps an object. Returns output in the static global errmsg array. |
|
|
431 | */ |
|
|
432 | |
|
|
433 | void |
|
|
434 | dump_object (object *op) |
380 | dump_object (object *op) |
435 | { |
381 | { |
436 | if (op == NULL) |
382 | if (!op) |
437 | { |
383 | return strdup ("[NULLOBJ]"); |
438 | strcpy (errmsg, "[NULL pointer]"); |
|
|
439 | return; |
|
|
440 | } |
|
|
441 | errmsg[0] = '\0'; |
|
|
442 | dump_object2 (op); |
|
|
443 | } |
|
|
444 | |
384 | |
445 | void |
385 | object_freezer freezer; |
446 | dump_all_objects (void) |
386 | save_object (freezer, op, 3); |
447 | { |
387 | return freezer.as_string (); |
448 | object *op; |
|
|
449 | |
|
|
450 | for (op = object::first; op != NULL; op = op->next) |
|
|
451 | { |
|
|
452 | dump_object (op); |
|
|
453 | fprintf (logfile, "Object %s\n", errmsg); |
|
|
454 | } |
|
|
455 | } |
388 | } |
456 | |
389 | |
457 | /* |
390 | /* |
458 | * get_nearest_part(multi-object, object 2) returns the part of the |
391 | * get_nearest_part(multi-object, object 2) returns the part of the |
459 | * multi-object 1 which is closest to the second object. |
392 | * multi-object 1 which is closest to the second object. |
… | |
… | |
479 | */ |
412 | */ |
480 | |
413 | |
481 | object * |
414 | object * |
482 | find_object (tag_t i) |
415 | find_object (tag_t i) |
483 | { |
416 | { |
484 | object *op; |
|
|
485 | |
|
|
486 | for (op = object::first; op != NULL; op = op->next) |
417 | for (object *op = object::first; op; op = op->next) |
487 | if (op->count == i) |
418 | if (op->count == i) |
488 | break; |
419 | return op; |
489 | |
420 | |
490 | return op; |
421 | return 0; |
491 | } |
422 | } |
492 | |
423 | |
493 | /* |
424 | /* |
494 | * Returns the first object which has a name equal to the argument. |
425 | * Returns the first object which has a name equal to the argument. |
495 | * Used only by the patch command, but not all that useful. |
426 | * Used only by the patch command, but not all that useful. |
… | |
… | |
911 | mortals.erase (i); |
842 | mortals.erase (i); |
912 | } |
843 | } |
913 | |
844 | |
914 | static int lastmortals = 0;//D |
845 | static int lastmortals = 0;//D |
915 | |
846 | |
916 | if (mortals.size() != lastmortals)//D |
847 | if (mortals.size() != lastmortals && lastmortals > 100)//D |
917 | { |
848 | { |
918 | lastmortals = mortals.size ();//D |
849 | lastmortals = mortals.size ();//D |
919 | LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D |
850 | LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D |
920 | } |
851 | } |
921 | } |
852 | } |
… | |
… | |
972 | * it from the list of used objects, and puts it on the list of |
903 | * it from the list of used objects, and puts it on the list of |
973 | * free objects. The IS_FREED() flag is set in the object. |
904 | * free objects. The IS_FREED() flag is set in the object. |
974 | * The object must have been removed by remove_ob() first for |
905 | * The object must have been removed by remove_ob() first for |
975 | * this function to succeed. |
906 | * this function to succeed. |
976 | * |
907 | * |
977 | * If free_inventory is set, free inventory as well. Else drop items in |
908 | * If destroy_inventory is set, free inventory as well. Else drop items in |
978 | * inventory to the ground. |
909 | * inventory to the ground. |
979 | */ |
910 | */ |
980 | void object::free (bool free_inventory) |
911 | void object::destroy (bool destroy_inventory) |
981 | { |
912 | { |
982 | if (QUERY_FLAG (this, FLAG_FREED)) |
913 | if (QUERY_FLAG (this, FLAG_FREED)) |
983 | return; |
914 | return; |
984 | |
915 | |
985 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
916 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
… | |
… | |
990 | |
921 | |
991 | SET_FLAG (this, FLAG_FREED); |
922 | SET_FLAG (this, FLAG_FREED); |
992 | |
923 | |
993 | if (more) |
924 | if (more) |
994 | { |
925 | { |
995 | more->free (free_inventory); |
926 | more->destroy (destroy_inventory); |
996 | more = 0; |
927 | more = 0; |
997 | } |
928 | } |
998 | |
929 | |
999 | if (inv) |
930 | if (inv) |
1000 | { |
931 | { |
1001 | /* Only if the space blocks everything do we not process - |
932 | /* Only if the space blocks everything do we not process - |
1002 | * if some form of movement is allowed, let objects |
933 | * if some form of movement is allowed, let objects |
1003 | * drop on that space. |
934 | * drop on that space. |
1004 | */ |
935 | */ |
1005 | if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) |
936 | if (destroy_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) |
1006 | { |
937 | { |
1007 | object *op = inv; |
938 | object *op = inv; |
1008 | |
939 | |
1009 | while (op) |
940 | while (op) |
1010 | { |
941 | { |
1011 | object *tmp = op->below; |
942 | object *tmp = op->below; |
1012 | op->free (free_inventory); |
943 | op->destroy (destroy_inventory); |
1013 | op = tmp; |
944 | op = tmp; |
1014 | } |
945 | } |
1015 | } |
946 | } |
1016 | else |
947 | else |
1017 | { /* Put objects in inventory onto this space */ |
948 | { /* Put objects in inventory onto this space */ |
… | |
… | |
1036 | op = tmp; |
967 | op = tmp; |
1037 | } |
968 | } |
1038 | } |
969 | } |
1039 | } |
970 | } |
1040 | |
971 | |
|
|
972 | // hack to ensure that freed objects still have a valid map |
|
|
973 | { |
|
|
974 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
975 | |
|
|
976 | if (!freed_map) |
|
|
977 | { |
|
|
978 | freed_map = new maptile; |
|
|
979 | |
|
|
980 | freed_map->name = "/internal/freed_objects_map"; |
|
|
981 | freed_map->width = 3; |
|
|
982 | freed_map->height = 3; |
|
|
983 | |
|
|
984 | freed_map->allocate (); |
|
|
985 | } |
|
|
986 | |
|
|
987 | map = freed_map; |
|
|
988 | x = 1; |
|
|
989 | y = 1; |
|
|
990 | } |
|
|
991 | |
1041 | // clear those pointers that likely might have circular references to us |
992 | // clear those pointers that likely might have circular references to us |
1042 | owner = 0; |
993 | owner = 0; |
1043 | enemy = 0; |
994 | enemy = 0; |
1044 | attacked_by = 0; |
995 | attacked_by = 0; |
|
|
996 | |
|
|
997 | // only relevant for players(?), but make sure of it anyways |
|
|
998 | contr = 0; |
1045 | |
999 | |
1046 | /* Remove object from the active list */ |
1000 | /* Remove object from the active list */ |
1047 | speed = 0; |
1001 | speed = 0; |
1048 | update_ob_speed (this); |
1002 | update_ob_speed (this); |
1049 | |
1003 | |
… | |
… | |
1173 | * use translated coordinates in case some oddness with map tiling is |
1127 | * use translated coordinates in case some oddness with map tiling is |
1174 | * evident |
1128 | * evident |
1175 | */ |
1129 | */ |
1176 | if (GET_MAP_OB (m, x, y) != op) |
1130 | if (GET_MAP_OB (m, x, y) != op) |
1177 | { |
1131 | { |
1178 | dump_object (op); |
1132 | char *dump = dump_object (op); |
1179 | LOG (llevError, |
1133 | LOG (llevError, |
1180 | "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", errmsg); |
1134 | "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", dump); |
|
|
1135 | free (dump); |
1181 | dump_object (GET_MAP_OB (m, x, y)); |
1136 | dump = dump_object (GET_MAP_OB (m, x, y)); |
1182 | LOG (llevError, "%s\n", errmsg); |
1137 | LOG (llevError, "%s\n", dump); |
|
|
1138 | free (dump); |
1183 | } |
1139 | } |
1184 | |
1140 | |
1185 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
1141 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
1186 | } |
1142 | } |
1187 | |
1143 | |
… | |
… | |
1342 | return NULL; |
1298 | return NULL; |
1343 | } |
1299 | } |
1344 | |
1300 | |
1345 | if (m == NULL) |
1301 | if (m == NULL) |
1346 | { |
1302 | { |
1347 | dump_object (op); |
1303 | char *dump = dump_object (op); |
1348 | LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); |
1304 | LOG (llevError, "Trying to insert in null-map!\n%s\n", dump); |
|
|
1305 | free (dump); |
1349 | return op; |
1306 | return op; |
1350 | } |
1307 | } |
1351 | |
1308 | |
1352 | if (out_of_map (m, op->x, op->y)) |
1309 | if (out_of_map (m, op->x, op->y)) |
1353 | { |
1310 | { |
1354 | dump_object (op); |
1311 | char *dump = dump_object (op); |
1355 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); |
1312 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", dump); |
1356 | #ifdef MANY_CORES |
1313 | #ifdef MANY_CORES |
1357 | /* Better to catch this here, as otherwise the next use of this object |
1314 | /* Better to catch this here, as otherwise the next use of this object |
1358 | * is likely to cause a crash. Better to find out where it is getting |
1315 | * is likely to cause a crash. Better to find out where it is getting |
1359 | * improperly inserted. |
1316 | * improperly inserted. |
1360 | */ |
1317 | */ |
1361 | abort (); |
1318 | abort (); |
1362 | #endif |
1319 | #endif |
|
|
1320 | free (dump); |
1363 | return op; |
1321 | return op; |
1364 | } |
1322 | } |
1365 | |
1323 | |
1366 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1324 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1367 | { |
1325 | { |
1368 | dump_object (op); |
1326 | char *dump = dump_object (op); |
1369 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); |
1327 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", dump); |
|
|
1328 | free (dump); |
1370 | return op; |
1329 | return op; |
1371 | } |
1330 | } |
1372 | |
1331 | |
1373 | if (op->more != NULL) |
1332 | if (op->more != NULL) |
1374 | { |
1333 | { |
… | |
… | |
1811 | tmp, * |
1770 | tmp, * |
1812 | otmp; |
1771 | otmp; |
1813 | |
1772 | |
1814 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1773 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1815 | { |
1774 | { |
1816 | dump_object (op); |
1775 | char *dump = dump_object (op); |
1817 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); |
1776 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", dump); |
|
|
1777 | free (dump); |
1818 | return op; |
1778 | return op; |
1819 | } |
1779 | } |
1820 | |
1780 | |
1821 | if (where == NULL) |
1781 | if (where == NULL) |
1822 | { |
1782 | { |
1823 | dump_object (op); |
1783 | char *dump = dump_object (op); |
1824 | LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); |
1784 | LOG (llevError, "Trying to put object in NULL.\n%s\n", dump); |
|
|
1785 | free (dump); |
1825 | return op; |
1786 | return op; |
1826 | } |
1787 | } |
1827 | |
1788 | |
1828 | if (where->head) |
1789 | if (where->head) |
1829 | { |
1790 | { |