ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.48 by root, Thu Sep 14 23:13:48 2006 UTC vs.
Revision 1.55 by root, Sun Dec 3 00:41:33 2006 UTC

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
379void 379char *
380dump_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
433void
434dump_object (object *op) 380dump_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
445void 385 object_freezer freezer;
446dump_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
481object * 414object *
482find_object (tag_t i) 415find_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 */
980void object::free (bool free_inventory) 911void 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))
988 if (!QUERY_FLAG (this, FLAG_REMOVED)) 919 if (!QUERY_FLAG (this, FLAG_REMOVED))
989 remove_ob (this); 920 remove_ob (this);
990 921
991 SET_FLAG (this, FLAG_FREED); 922 SET_FLAG (this, FLAG_FREED);
992 923
924 // hack to ensure that freed objects still have a valid map
925 {
926 static maptile *freed_map; // freed objects are moved here to avoid crashes
927
928 if (!freed_map)
929 {
930 freed_map = get_empty_map (3, 3);
931 freed_map->name = "freed objects map";
932 allocate_map (freed_map);
933 }
934
935 map = freed_map;
936 x = 1;
937 y = 1;
938 }
939
993 if (more) 940 if (more)
994 { 941 {
995 more->free (free_inventory); 942 more->destroy (destroy_inventory);
996 more = 0; 943 more = 0;
997 } 944 }
998 945
999 if (inv) 946 if (inv)
1000 { 947 {
1001 /* Only if the space blocks everything do we not process - 948 /* Only if the space blocks everything do we not process -
1002 * if some form of movement is allowed, let objects 949 * if some form of movement is allowed, let objects
1003 * drop on that space. 950 * drop on that space.
1004 */ 951 */
1005 if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL) 952 if (destroy_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)
1006 { 953 {
1007 object *op = inv; 954 object *op = inv;
1008 955
1009 while (op) 956 while (op)
1010 { 957 {
1011 object *tmp = op->below; 958 object *tmp = op->below;
1012 op->free (free_inventory); 959 op->destroy (destroy_inventory);
1013 op = tmp; 960 op = tmp;
1014 } 961 }
1015 } 962 }
1016 else 963 else
1017 { /* Put objects in inventory onto this space */ 964 { /* Put objects in inventory onto this space */
1041 // clear those pointers that likely might have circular references to us 988 // clear those pointers that likely might have circular references to us
1042 owner = 0; 989 owner = 0;
1043 enemy = 0; 990 enemy = 0;
1044 attacked_by = 0; 991 attacked_by = 0;
1045 992
993 // only relevant for players(?), but make sure of it anyways
994 contr = 0;
995
1046 /* Remove object from the active list */ 996 /* Remove object from the active list */
1047 speed = 0; 997 speed = 0;
1048 update_ob_speed (this); 998 update_ob_speed (this);
1049 999
1050 unlink (); 1000 unlink ();
1084{ 1034{
1085 object *tmp, *last = 0; 1035 object *tmp, *last = 0;
1086 object *otmp; 1036 object *otmp;
1087 1037
1088 int check_walk_off; 1038 int check_walk_off;
1089 mapstruct *m; 1039 maptile *m;
1090 1040
1091 sint16 x, y; 1041 sint16 x, y;
1092 1042
1093 if (QUERY_FLAG (op, FLAG_REMOVED)) 1043 if (QUERY_FLAG (op, FLAG_REMOVED))
1094 return; 1044 return;
1173 * use translated coordinates in case some oddness with map tiling is 1123 * use translated coordinates in case some oddness with map tiling is
1174 * evident 1124 * evident
1175 */ 1125 */
1176 if (GET_MAP_OB (m, x, y) != op) 1126 if (GET_MAP_OB (m, x, y) != op)
1177 { 1127 {
1178 dump_object (op); 1128 char *dump = dump_object (op);
1179 LOG (llevError, 1129 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); 1130 "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);
1131 free (dump);
1181 dump_object (GET_MAP_OB (m, x, y)); 1132 dump = dump_object (GET_MAP_OB (m, x, y));
1182 LOG (llevError, "%s\n", errmsg); 1133 LOG (llevError, "%s\n", dump);
1134 free (dump);
1183 } 1135 }
1184 1136
1185 SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ 1137 SET_MAP_OB (m, x, y, op->above); /* goes on above it. */
1186 } 1138 }
1187 1139
1213 1165
1214 tmp->contr->socket.update_look = 1; 1166 tmp->contr->socket.update_look = 1;
1215 } 1167 }
1216 1168
1217 /* See if player moving off should effect something */ 1169 /* 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)) 1170 if (check_walk_off
1171 && ((op->move_type & tmp->move_off)
1172 && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0))
1219 { 1173 {
1220 move_apply (tmp, op, NULL); 1174 move_apply (tmp, op, NULL);
1221 1175
1222 if (op->destroyed ()); 1176 if (op->destroyed ())
1223 LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name); 1177 LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ());
1224 } 1178 }
1225 1179
1226 /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ 1180 /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */
1227 1181
1228 if (tmp->above == tmp) 1182 if (tmp->above == tmp)
1289/* 1243/*
1290 * same as insert_ob_in_map except it handle separate coordinates and do a clean 1244 * same as insert_ob_in_map except it handle separate coordinates and do a clean
1291 * job preparing multi-part monsters 1245 * job preparing multi-part monsters
1292 */ 1246 */
1293object * 1247object *
1294insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y) 1248insert_ob_in_map_at (object *op, maptile *m, object *originator, int flag, int x, int y)
1295{ 1249{
1296 object *tmp; 1250 object *tmp;
1297 1251
1298 if (op->head) 1252 if (op->head)
1299 op = op->head; 1253 op = op->head;
1327 * NULL if 'op' was destroyed 1281 * NULL if 'op' was destroyed
1328 * just 'op' otherwise 1282 * just 'op' otherwise
1329 */ 1283 */
1330 1284
1331object * 1285object *
1332insert_ob_in_map (object *op, mapstruct *m, object *originator, int flag) 1286insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1333{ 1287{
1334 object *tmp, *top, *floor = NULL; 1288 object *tmp, *top, *floor = NULL;
1335 sint16 x, y; 1289 sint16 x, y;
1336 1290
1337 if (QUERY_FLAG (op, FLAG_FREED)) 1291 if (QUERY_FLAG (op, FLAG_FREED))
1340 return NULL; 1294 return NULL;
1341 } 1295 }
1342 1296
1343 if (m == NULL) 1297 if (m == NULL)
1344 { 1298 {
1345 dump_object (op); 1299 char *dump = dump_object (op);
1346 LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); 1300 LOG (llevError, "Trying to insert in null-map!\n%s\n", dump);
1301 free (dump);
1347 return op; 1302 return op;
1348 } 1303 }
1349 1304
1350 if (out_of_map (m, op->x, op->y)) 1305 if (out_of_map (m, op->x, op->y))
1351 { 1306 {
1352 dump_object (op); 1307 char *dump = dump_object (op);
1353 LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); 1308 LOG (llevError, "Trying to insert object outside the map.\n%s\n", dump);
1354#ifdef MANY_CORES 1309#ifdef MANY_CORES
1355 /* Better to catch this here, as otherwise the next use of this object 1310 /* 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 1311 * is likely to cause a crash. Better to find out where it is getting
1357 * improperly inserted. 1312 * improperly inserted.
1358 */ 1313 */
1359 abort (); 1314 abort ();
1360#endif 1315#endif
1316 free (dump);
1361 return op; 1317 return op;
1362 } 1318 }
1363 1319
1364 if (!QUERY_FLAG (op, FLAG_REMOVED)) 1320 if (!QUERY_FLAG (op, FLAG_REMOVED))
1365 { 1321 {
1366 dump_object (op); 1322 char *dump = dump_object (op);
1367 LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); 1323 LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", dump);
1324 free (dump);
1368 return op; 1325 return op;
1369 } 1326 }
1370 1327
1371 if (op->more != NULL) 1328 if (op->more != NULL)
1372 { 1329 {
1809 tmp, * 1766 tmp, *
1810 otmp; 1767 otmp;
1811 1768
1812 if (!QUERY_FLAG (op, FLAG_REMOVED)) 1769 if (!QUERY_FLAG (op, FLAG_REMOVED))
1813 { 1770 {
1814 dump_object (op); 1771 char *dump = dump_object (op);
1815 LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); 1772 LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", dump);
1773 free (dump);
1816 return op; 1774 return op;
1817 } 1775 }
1818 1776
1819 if (where == NULL) 1777 if (where == NULL)
1820 { 1778 {
1821 dump_object (op); 1779 char *dump = dump_object (op);
1822 LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); 1780 LOG (llevError, "Trying to put object in NULL.\n%s\n", dump);
1781 free (dump);
1823 return op; 1782 return op;
1824 } 1783 }
1825 1784
1826 if (where->head) 1785 if (where->head)
1827 { 1786 {
1928 1887
1929int 1888int
1930check_move_on (object *op, object *originator) 1889check_move_on (object *op, object *originator)
1931{ 1890{
1932 object *tmp; 1891 object *tmp;
1933 mapstruct *m = op->map; 1892 maptile *m = op->map;
1934 int x = op->x, y = op->y; 1893 int x = op->x, y = op->y;
1935 1894
1936 MoveType move_on, move_slow, move_block; 1895 MoveType move_on, move_slow, move_block;
1937 1896
1938 if (QUERY_FLAG (op, FLAG_NO_APPLY)) 1897 if (QUERY_FLAG (op, FLAG_NO_APPLY))
2027 * a matching archetype at the given map and coordinates. 1986 * a matching archetype at the given map and coordinates.
2028 * The first matching object is returned, or NULL if none. 1987 * The first matching object is returned, or NULL if none.
2029 */ 1988 */
2030 1989
2031object * 1990object *
2032present_arch (const archetype *at, mapstruct *m, int x, int y) 1991present_arch (const archetype *at, maptile *m, int x, int y)
2033{ 1992{
2034 object * 1993 object *
2035 tmp; 1994 tmp;
2036 1995
2037 if (m == NULL || out_of_map (m, x, y)) 1996 if (m == NULL || out_of_map (m, x, y))
2050 * a matching type variable at the given map and coordinates. 2009 * a matching type variable at the given map and coordinates.
2051 * The first matching object is returned, or NULL if none. 2010 * The first matching object is returned, or NULL if none.
2052 */ 2011 */
2053 2012
2054object * 2013object *
2055present (unsigned char type, mapstruct *m, int x, int y) 2014present (unsigned char type, maptile *m, int x, int y)
2056{ 2015{
2057 object * 2016 object *
2058 tmp; 2017 tmp;
2059 2018
2060 if (out_of_map (m, x, y)) 2019 if (out_of_map (m, x, y))
2200 * the archetype because that isn't correct if the monster has been 2159 * the archetype because that isn't correct if the monster has been
2201 * customized, changed states, etc. 2160 * customized, changed states, etc.
2202 */ 2161 */
2203 2162
2204int 2163int
2205find_free_spot (const object *ob, mapstruct *m, int x, int y, int start, int stop) 2164find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop)
2206{ 2165{
2207 int 2166 int
2208 i, 2167 i,
2209 index = 0, flag; 2168 index = 0, flag;
2210 static int 2169 static int
2231 return -1; 2190 return -1;
2232 return altern[RANDOM () % index]; 2191 return altern[RANDOM () % index];
2233} 2192}
2234 2193
2235/* 2194/*
2236 * find_first_free_spot(archetype, mapstruct, x, y) works like 2195 * find_first_free_spot(archetype, maptile, x, y) works like
2237 * find_free_spot(), but it will search max number of squares. 2196 * find_free_spot(), but it will search max number of squares.
2238 * But it will return the first available spot, not a random choice. 2197 * 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. 2198 * Changed 0.93.2: Have it return -1 if there is no free spot available.
2240 */ 2199 */
2241 2200
2242int 2201int
2243find_first_free_spot (const object *ob, mapstruct *m, int x, int y) 2202find_first_free_spot (const object *ob, maptile *m, int x, int y)
2244{ 2203{
2245 int 2204 int
2246 i; 2205 i;
2247 2206
2248 for (i = 0; i < SIZEOFFREE; i++) 2207 for (i = 0; i < SIZEOFFREE; i++)
2312 * because we have to know what movement the thing looking to move 2271 * because we have to know what movement the thing looking to move
2313 * there is capable of. 2272 * there is capable of.
2314 */ 2273 */
2315 2274
2316int 2275int
2317find_dir (mapstruct *m, int x, int y, object *exclude) 2276find_dir (maptile *m, int x, int y, object *exclude)
2318{ 2277{
2319 int 2278 int
2320 i, 2279 i,
2321 max = SIZEOFFREE, mflags; 2280 max = SIZEOFFREE, mflags;
2322 2281
2323 sint16 nx, ny; 2282 sint16 nx, ny;
2324 object * 2283 object *
2325 tmp; 2284 tmp;
2326 mapstruct * 2285 maptile *
2327 mp; 2286 mp;
2328 2287
2329 MoveType blocked, move_type; 2288 MoveType blocked, move_type;
2330 2289
2331 if (exclude && exclude->head) 2290 if (exclude && exclude->head)
2539 * Modified to be map tile aware -.MSW 2498 * Modified to be map tile aware -.MSW
2540 */ 2499 */
2541 2500
2542 2501
2543int 2502int
2544can_see_monsterP (mapstruct *m, int x, int y, int dir) 2503can_see_monsterP (maptile *m, int x, int y, int dir)
2545{ 2504{
2546 sint16 dx, dy; 2505 sint16 dx, dy;
2547 int 2506 int
2548 mflags; 2507 mflags;
2549 2508

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines