… | |
… | |
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. |
… | |
… | |
911 | mortals.erase (i); |
844 | mortals.erase (i); |
912 | } |
845 | } |
913 | |
846 | |
914 | static int lastmortals = 0;//D |
847 | static int lastmortals = 0;//D |
915 | |
848 | |
916 | if (mortals.size() != lastmortals)//D |
849 | if (mortals.size() != lastmortals && lastmortals > 100)//D |
917 | { |
850 | { |
918 | lastmortals = mortals.size ();//D |
851 | lastmortals = mortals.size ();//D |
919 | LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D |
852 | LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D |
920 | } |
853 | } |
921 | } |
854 | } |
… | |
… | |
972 | * it from the list of used objects, and puts it on the list of |
905 | * 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. |
906 | * free objects. The IS_FREED() flag is set in the object. |
974 | * The object must have been removed by remove_ob() first for |
907 | * The object must have been removed by remove_ob() first for |
975 | * this function to succeed. |
908 | * this function to succeed. |
976 | * |
909 | * |
977 | * If free_inventory is set, free inventory as well. Else drop items in |
910 | * If destroy_inventory is set, free inventory as well. Else drop items in |
978 | * inventory to the ground. |
911 | * inventory to the ground. |
979 | */ |
912 | */ |
980 | void object::free (bool free_inventory) |
913 | void object::destroy (bool destroy_inventory) |
981 | { |
914 | { |
982 | if (QUERY_FLAG (this, FLAG_FREED)) |
915 | if (QUERY_FLAG (this, FLAG_FREED)) |
983 | return; |
916 | return; |
984 | |
917 | |
985 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
918 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
… | |
… | |
990 | |
923 | |
991 | SET_FLAG (this, FLAG_FREED); |
924 | SET_FLAG (this, FLAG_FREED); |
992 | |
925 | |
993 | if (more) |
926 | if (more) |
994 | { |
927 | { |
995 | more->free (free_inventory); |
928 | more->destroy (destroy_inventory); |
996 | more = 0; |
929 | more = 0; |
997 | } |
930 | } |
998 | |
931 | |
999 | if (inv) |
932 | if (inv) |
1000 | { |
933 | { |
1001 | /* Only if the space blocks everything do we not process - |
934 | /* Only if the space blocks everything do we not process - |
1002 | * if some form of movement is allowed, let objects |
935 | * if some form of movement is allowed, let objects |
1003 | * drop on that space. |
936 | * drop on that space. |
1004 | */ |
937 | */ |
1005 | if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) |
938 | if (destroy_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) |
1006 | { |
939 | { |
1007 | object *op = inv; |
940 | object *op = inv; |
1008 | |
941 | |
1009 | while (op) |
942 | while (op) |
1010 | { |
943 | { |
1011 | object *tmp = op->below; |
944 | object *tmp = op->below; |
1012 | op->free (free_inventory); |
945 | op->destroy (destroy_inventory); |
1013 | op = tmp; |
946 | op = tmp; |
1014 | } |
947 | } |
1015 | } |
948 | } |
1016 | else |
949 | else |
1017 | { /* Put objects in inventory onto this space */ |
950 | { /* Put objects in inventory onto this space */ |
… | |
… | |
1041 | // clear those pointers that likely might have circular references to us |
974 | // clear those pointers that likely might have circular references to us |
1042 | owner = 0; |
975 | owner = 0; |
1043 | enemy = 0; |
976 | enemy = 0; |
1044 | attacked_by = 0; |
977 | attacked_by = 0; |
1045 | |
978 | |
|
|
979 | // only relevant for players(?), but make sure of it anyways |
|
|
980 | contr = 0; |
|
|
981 | |
1046 | /* Remove object from the active list */ |
982 | /* Remove object from the active list */ |
1047 | speed = 0; |
983 | speed = 0; |
1048 | update_ob_speed (this); |
984 | update_ob_speed (this); |
1049 | |
985 | |
1050 | unlink (); |
986 | unlink (); |
… | |
… | |
1084 | { |
1020 | { |
1085 | object *tmp, *last = 0; |
1021 | object *tmp, *last = 0; |
1086 | object *otmp; |
1022 | object *otmp; |
1087 | |
1023 | |
1088 | int check_walk_off; |
1024 | int check_walk_off; |
1089 | mapstruct *m; |
1025 | maptile *m; |
1090 | |
1026 | |
1091 | sint16 x, y; |
1027 | sint16 x, y; |
1092 | |
1028 | |
1093 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1029 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1094 | return; |
1030 | return; |
… | |
… | |
1173 | * use translated coordinates in case some oddness with map tiling is |
1109 | * use translated coordinates in case some oddness with map tiling is |
1174 | * evident |
1110 | * evident |
1175 | */ |
1111 | */ |
1176 | if (GET_MAP_OB (m, x, y) != op) |
1112 | if (GET_MAP_OB (m, x, y) != op) |
1177 | { |
1113 | { |
1178 | dump_object (op); |
1114 | char *dump = dump_object (op); |
1179 | LOG (llevError, |
1115 | 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); |
1116 | "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); |
|
|
1117 | free (dump); |
1181 | dump_object (GET_MAP_OB (m, x, y)); |
1118 | dump = dump_object (GET_MAP_OB (m, x, y)); |
1182 | LOG (llevError, "%s\n", errmsg); |
1119 | LOG (llevError, "%s\n", dump); |
|
|
1120 | free (dump); |
1183 | } |
1121 | } |
1184 | |
1122 | |
1185 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
1123 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
1186 | } |
1124 | } |
1187 | |
1125 | |
… | |
… | |
1213 | |
1151 | |
1214 | tmp->contr->socket.update_look = 1; |
1152 | tmp->contr->socket.update_look = 1; |
1215 | } |
1153 | } |
1216 | |
1154 | |
1217 | /* See if player moving off should effect something */ |
1155 | /* See if player moving off should effect something */ |
1218 | if (check_walk_off && ((op->move_type & tmp->move_off) && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
1156 | if (check_walk_off |
|
|
1157 | && ((op->move_type & tmp->move_off) |
|
|
1158 | && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
1219 | { |
1159 | { |
1220 | move_apply (tmp, op, NULL); |
1160 | move_apply (tmp, op, NULL); |
1221 | |
1161 | |
1222 | if (op->destroyed ()); |
1162 | if (op->destroyed ()) |
1223 | LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name); |
1163 | LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ()); |
1224 | } |
1164 | } |
1225 | |
1165 | |
1226 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1166 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1227 | |
1167 | |
1228 | if (tmp->above == tmp) |
1168 | if (tmp->above == tmp) |
… | |
… | |
1289 | /* |
1229 | /* |
1290 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1230 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1291 | * job preparing multi-part monsters |
1231 | * job preparing multi-part monsters |
1292 | */ |
1232 | */ |
1293 | object * |
1233 | object * |
1294 | insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y) |
1234 | insert_ob_in_map_at (object *op, maptile *m, object *originator, int flag, int x, int y) |
1295 | { |
1235 | { |
1296 | object *tmp; |
1236 | object *tmp; |
1297 | |
1237 | |
1298 | if (op->head) |
1238 | if (op->head) |
1299 | op = op->head; |
1239 | op = op->head; |
… | |
… | |
1327 | * NULL if 'op' was destroyed |
1267 | * NULL if 'op' was destroyed |
1328 | * just 'op' otherwise |
1268 | * just 'op' otherwise |
1329 | */ |
1269 | */ |
1330 | |
1270 | |
1331 | object * |
1271 | object * |
1332 | insert_ob_in_map (object *op, mapstruct *m, object *originator, int flag) |
1272 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1333 | { |
1273 | { |
1334 | object *tmp, *top, *floor = NULL; |
1274 | object *tmp, *top, *floor = NULL; |
1335 | sint16 x, y; |
1275 | sint16 x, y; |
1336 | |
1276 | |
1337 | if (QUERY_FLAG (op, FLAG_FREED)) |
1277 | if (QUERY_FLAG (op, FLAG_FREED)) |
… | |
… | |
1340 | return NULL; |
1280 | return NULL; |
1341 | } |
1281 | } |
1342 | |
1282 | |
1343 | if (m == NULL) |
1283 | if (m == NULL) |
1344 | { |
1284 | { |
1345 | dump_object (op); |
1285 | char *dump = dump_object (op); |
1346 | LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); |
1286 | LOG (llevError, "Trying to insert in null-map!\n%s\n", dump); |
|
|
1287 | free (dump); |
1347 | return op; |
1288 | return op; |
1348 | } |
1289 | } |
1349 | |
1290 | |
1350 | if (out_of_map (m, op->x, op->y)) |
1291 | if (out_of_map (m, op->x, op->y)) |
1351 | { |
1292 | { |
1352 | dump_object (op); |
1293 | char *dump = dump_object (op); |
1353 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); |
1294 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", dump); |
1354 | #ifdef MANY_CORES |
1295 | #ifdef MANY_CORES |
1355 | /* Better to catch this here, as otherwise the next use of this object |
1296 | /* Better to catch this here, as otherwise the next use of this object |
1356 | * is likely to cause a crash. Better to find out where it is getting |
1297 | * is likely to cause a crash. Better to find out where it is getting |
1357 | * improperly inserted. |
1298 | * improperly inserted. |
1358 | */ |
1299 | */ |
1359 | abort (); |
1300 | abort (); |
1360 | #endif |
1301 | #endif |
|
|
1302 | free (dump); |
1361 | return op; |
1303 | return op; |
1362 | } |
1304 | } |
1363 | |
1305 | |
1364 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1306 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1365 | { |
1307 | { |
1366 | dump_object (op); |
1308 | char *dump = dump_object (op); |
1367 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); |
1309 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", dump); |
|
|
1310 | free (dump); |
1368 | return op; |
1311 | return op; |
1369 | } |
1312 | } |
1370 | |
1313 | |
1371 | if (op->more != NULL) |
1314 | if (op->more != NULL) |
1372 | { |
1315 | { |
… | |
… | |
1809 | tmp, * |
1752 | tmp, * |
1810 | otmp; |
1753 | otmp; |
1811 | |
1754 | |
1812 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1755 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1813 | { |
1756 | { |
1814 | dump_object (op); |
1757 | char *dump = dump_object (op); |
1815 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); |
1758 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", dump); |
|
|
1759 | free (dump); |
1816 | return op; |
1760 | return op; |
1817 | } |
1761 | } |
1818 | |
1762 | |
1819 | if (where == NULL) |
1763 | if (where == NULL) |
1820 | { |
1764 | { |
1821 | dump_object (op); |
1765 | char *dump = dump_object (op); |
1822 | LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); |
1766 | LOG (llevError, "Trying to put object in NULL.\n%s\n", dump); |
|
|
1767 | free (dump); |
1823 | return op; |
1768 | return op; |
1824 | } |
1769 | } |
1825 | |
1770 | |
1826 | if (where->head) |
1771 | if (where->head) |
1827 | { |
1772 | { |
… | |
… | |
1928 | |
1873 | |
1929 | int |
1874 | int |
1930 | check_move_on (object *op, object *originator) |
1875 | check_move_on (object *op, object *originator) |
1931 | { |
1876 | { |
1932 | object *tmp; |
1877 | object *tmp; |
1933 | mapstruct *m = op->map; |
1878 | maptile *m = op->map; |
1934 | int x = op->x, y = op->y; |
1879 | int x = op->x, y = op->y; |
1935 | |
1880 | |
1936 | MoveType move_on, move_slow, move_block; |
1881 | MoveType move_on, move_slow, move_block; |
1937 | |
1882 | |
1938 | if (QUERY_FLAG (op, FLAG_NO_APPLY)) |
1883 | if (QUERY_FLAG (op, FLAG_NO_APPLY)) |
… | |
… | |
2027 | * a matching archetype at the given map and coordinates. |
1972 | * a matching archetype at the given map and coordinates. |
2028 | * The first matching object is returned, or NULL if none. |
1973 | * The first matching object is returned, or NULL if none. |
2029 | */ |
1974 | */ |
2030 | |
1975 | |
2031 | object * |
1976 | object * |
2032 | present_arch (const archetype *at, mapstruct *m, int x, int y) |
1977 | present_arch (const archetype *at, maptile *m, int x, int y) |
2033 | { |
1978 | { |
2034 | object * |
1979 | object * |
2035 | tmp; |
1980 | tmp; |
2036 | |
1981 | |
2037 | if (m == NULL || out_of_map (m, x, y)) |
1982 | if (m == NULL || out_of_map (m, x, y)) |
… | |
… | |
2050 | * a matching type variable at the given map and coordinates. |
1995 | * a matching type variable at the given map and coordinates. |
2051 | * The first matching object is returned, or NULL if none. |
1996 | * The first matching object is returned, or NULL if none. |
2052 | */ |
1997 | */ |
2053 | |
1998 | |
2054 | object * |
1999 | object * |
2055 | present (unsigned char type, mapstruct *m, int x, int y) |
2000 | present (unsigned char type, maptile *m, int x, int y) |
2056 | { |
2001 | { |
2057 | object * |
2002 | object * |
2058 | tmp; |
2003 | tmp; |
2059 | |
2004 | |
2060 | if (out_of_map (m, x, y)) |
2005 | if (out_of_map (m, x, y)) |
… | |
… | |
2200 | * the archetype because that isn't correct if the monster has been |
2145 | * the archetype because that isn't correct if the monster has been |
2201 | * customized, changed states, etc. |
2146 | * customized, changed states, etc. |
2202 | */ |
2147 | */ |
2203 | |
2148 | |
2204 | int |
2149 | int |
2205 | find_free_spot (const object *ob, mapstruct *m, int x, int y, int start, int stop) |
2150 | find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |
2206 | { |
2151 | { |
2207 | int |
2152 | int |
2208 | i, |
2153 | i, |
2209 | index = 0, flag; |
2154 | index = 0, flag; |
2210 | static int |
2155 | static int |
… | |
… | |
2231 | return -1; |
2176 | return -1; |
2232 | return altern[RANDOM () % index]; |
2177 | return altern[RANDOM () % index]; |
2233 | } |
2178 | } |
2234 | |
2179 | |
2235 | /* |
2180 | /* |
2236 | * find_first_free_spot(archetype, mapstruct, x, y) works like |
2181 | * find_first_free_spot(archetype, maptile, x, y) works like |
2237 | * find_free_spot(), but it will search max number of squares. |
2182 | * find_free_spot(), but it will search max number of squares. |
2238 | * But it will return the first available spot, not a random choice. |
2183 | * But it will return the first available spot, not a random choice. |
2239 | * Changed 0.93.2: Have it return -1 if there is no free spot available. |
2184 | * Changed 0.93.2: Have it return -1 if there is no free spot available. |
2240 | */ |
2185 | */ |
2241 | |
2186 | |
2242 | int |
2187 | int |
2243 | find_first_free_spot (const object *ob, mapstruct *m, int x, int y) |
2188 | find_first_free_spot (const object *ob, maptile *m, int x, int y) |
2244 | { |
2189 | { |
2245 | int |
2190 | int |
2246 | i; |
2191 | i; |
2247 | |
2192 | |
2248 | for (i = 0; i < SIZEOFFREE; i++) |
2193 | for (i = 0; i < SIZEOFFREE; i++) |
… | |
… | |
2312 | * because we have to know what movement the thing looking to move |
2257 | * because we have to know what movement the thing looking to move |
2313 | * there is capable of. |
2258 | * there is capable of. |
2314 | */ |
2259 | */ |
2315 | |
2260 | |
2316 | int |
2261 | int |
2317 | find_dir (mapstruct *m, int x, int y, object *exclude) |
2262 | find_dir (maptile *m, int x, int y, object *exclude) |
2318 | { |
2263 | { |
2319 | int |
2264 | int |
2320 | i, |
2265 | i, |
2321 | max = SIZEOFFREE, mflags; |
2266 | max = SIZEOFFREE, mflags; |
2322 | |
2267 | |
2323 | sint16 nx, ny; |
2268 | sint16 nx, ny; |
2324 | object * |
2269 | object * |
2325 | tmp; |
2270 | tmp; |
2326 | mapstruct * |
2271 | maptile * |
2327 | mp; |
2272 | mp; |
2328 | |
2273 | |
2329 | MoveType blocked, move_type; |
2274 | MoveType blocked, move_type; |
2330 | |
2275 | |
2331 | if (exclude && exclude->head) |
2276 | if (exclude && exclude->head) |
… | |
… | |
2539 | * Modified to be map tile aware -.MSW |
2484 | * Modified to be map tile aware -.MSW |
2540 | */ |
2485 | */ |
2541 | |
2486 | |
2542 | |
2487 | |
2543 | int |
2488 | int |
2544 | can_see_monsterP (mapstruct *m, int x, int y, int dir) |
2489 | can_see_monsterP (maptile *m, int x, int y, int dir) |
2545 | { |
2490 | { |
2546 | sint16 dx, dy; |
2491 | sint16 dx, dy; |
2547 | int |
2492 | int |
2548 | mflags; |
2493 | mflags; |
2549 | |
2494 | |