… | |
… | |
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. |
… | |
… | |
908 | else |
839 | else |
909 | { |
840 | { |
910 | delete *i; |
841 | delete *i; |
911 | mortals.erase (i); |
842 | mortals.erase (i); |
912 | } |
843 | } |
913 | |
|
|
914 | static int lastmortals = 0;//D |
|
|
915 | |
|
|
916 | if (mortals.size() != lastmortals && lastmortals > 100)//D |
|
|
917 | { |
|
|
918 | lastmortals = mortals.size ();//D |
|
|
919 | LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D |
|
|
920 | } |
|
|
921 | } |
844 | } |
922 | |
845 | |
923 | object::object () |
846 | object::object () |
924 | { |
847 | { |
925 | SET_FLAG (this, FLAG_REMOVED); |
848 | SET_FLAG (this, FLAG_REMOVED); |
… | |
… | |
1036 | op = tmp; |
959 | op = tmp; |
1037 | } |
960 | } |
1038 | } |
961 | } |
1039 | } |
962 | } |
1040 | |
963 | |
|
|
964 | // hack to ensure that freed objects still have a valid map |
|
|
965 | { |
|
|
966 | static maptile *freed_map; // freed objects are moved here to avoid crashes |
|
|
967 | |
|
|
968 | if (!freed_map) |
|
|
969 | { |
|
|
970 | freed_map = new maptile; |
|
|
971 | |
|
|
972 | freed_map->name = "/internal/freed_objects_map"; |
|
|
973 | freed_map->width = 3; |
|
|
974 | freed_map->height = 3; |
|
|
975 | |
|
|
976 | freed_map->allocate (); |
|
|
977 | } |
|
|
978 | |
|
|
979 | map = freed_map; |
|
|
980 | x = 1; |
|
|
981 | y = 1; |
|
|
982 | } |
|
|
983 | |
1041 | // clear those pointers that likely might have circular references to us |
984 | // clear those pointers that likely might have circular references to us |
1042 | owner = 0; |
985 | owner = 0; |
1043 | enemy = 0; |
986 | enemy = 0; |
1044 | attacked_by = 0; |
987 | attacked_by = 0; |
1045 | |
988 | |
… | |
… | |
1176 | * use translated coordinates in case some oddness with map tiling is |
1119 | * use translated coordinates in case some oddness with map tiling is |
1177 | * evident |
1120 | * evident |
1178 | */ |
1121 | */ |
1179 | if (GET_MAP_OB (m, x, y) != op) |
1122 | if (GET_MAP_OB (m, x, y) != op) |
1180 | { |
1123 | { |
1181 | dump_object (op); |
1124 | char *dump = dump_object (op); |
1182 | LOG (llevError, |
1125 | LOG (llevError, |
1183 | "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); |
1126 | "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); |
|
|
1127 | free (dump); |
1184 | dump_object (GET_MAP_OB (m, x, y)); |
1128 | dump = dump_object (GET_MAP_OB (m, x, y)); |
1185 | LOG (llevError, "%s\n", errmsg); |
1129 | LOG (llevError, "%s\n", dump); |
|
|
1130 | free (dump); |
1186 | } |
1131 | } |
1187 | |
1132 | |
1188 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
1133 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
1189 | } |
1134 | } |
1190 | |
1135 | |
… | |
… | |
1345 | return NULL; |
1290 | return NULL; |
1346 | } |
1291 | } |
1347 | |
1292 | |
1348 | if (m == NULL) |
1293 | if (m == NULL) |
1349 | { |
1294 | { |
1350 | dump_object (op); |
1295 | char *dump = dump_object (op); |
1351 | LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); |
1296 | LOG (llevError, "Trying to insert in null-map!\n%s\n", dump); |
|
|
1297 | free (dump); |
1352 | return op; |
1298 | return op; |
1353 | } |
1299 | } |
1354 | |
1300 | |
1355 | if (out_of_map (m, op->x, op->y)) |
1301 | if (out_of_map (m, op->x, op->y)) |
1356 | { |
1302 | { |
1357 | dump_object (op); |
1303 | char *dump = dump_object (op); |
1358 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); |
1304 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", dump); |
1359 | #ifdef MANY_CORES |
1305 | #ifdef MANY_CORES |
1360 | /* Better to catch this here, as otherwise the next use of this object |
1306 | /* Better to catch this here, as otherwise the next use of this object |
1361 | * is likely to cause a crash. Better to find out where it is getting |
1307 | * is likely to cause a crash. Better to find out where it is getting |
1362 | * improperly inserted. |
1308 | * improperly inserted. |
1363 | */ |
1309 | */ |
1364 | abort (); |
1310 | abort (); |
1365 | #endif |
1311 | #endif |
|
|
1312 | free (dump); |
1366 | return op; |
1313 | return op; |
1367 | } |
1314 | } |
1368 | |
1315 | |
1369 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1316 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1370 | { |
1317 | { |
1371 | dump_object (op); |
1318 | char *dump = dump_object (op); |
1372 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); |
1319 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", dump); |
|
|
1320 | free (dump); |
1373 | return op; |
1321 | return op; |
1374 | } |
1322 | } |
1375 | |
1323 | |
1376 | if (op->more != NULL) |
1324 | if (op->more != NULL) |
1377 | { |
1325 | { |
… | |
… | |
1814 | tmp, * |
1762 | tmp, * |
1815 | otmp; |
1763 | otmp; |
1816 | |
1764 | |
1817 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1765 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1818 | { |
1766 | { |
1819 | dump_object (op); |
1767 | char *dump = dump_object (op); |
1820 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); |
1768 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", dump); |
|
|
1769 | free (dump); |
1821 | return op; |
1770 | return op; |
1822 | } |
1771 | } |
1823 | |
1772 | |
1824 | if (where == NULL) |
1773 | if (where == NULL) |
1825 | { |
1774 | { |
1826 | dump_object (op); |
1775 | char *dump = dump_object (op); |
1827 | LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); |
1776 | LOG (llevError, "Trying to put object in NULL.\n%s\n", dump); |
|
|
1777 | free (dump); |
1828 | return op; |
1778 | return op; |
1829 | } |
1779 | } |
1830 | |
1780 | |
1831 | if (where->head) |
1781 | if (where->head) |
1832 | { |
1782 | { |