… | |
… | |
357 | /* |
357 | /* |
358 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
358 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
359 | * Some error messages. |
359 | * Some error messages. |
360 | * The result of the dump is stored in the static global errmsg array. |
360 | * The result of the dump is stored in the static global errmsg array. |
361 | */ |
361 | */ |
362 | |
|
|
363 | char * |
362 | char * |
364 | dump_object (object *op) |
363 | dump_object (object *op) |
365 | { |
364 | { |
366 | if (!op) |
365 | if (!op) |
367 | return strdup ("[NULLOBJ]"); |
366 | return strdup ("[NULLOBJ]"); |
368 | |
367 | |
369 | object_freezer freezer; |
368 | object_freezer freezer; |
370 | save_object (freezer, op, 1); |
369 | op->write (freezer); |
371 | return freezer.as_string (); |
370 | return freezer.as_string (); |
372 | } |
371 | } |
373 | |
372 | |
374 | /* |
373 | /* |
375 | * get_nearest_part(multi-object, object 2) returns the part of the |
374 | * get_nearest_part(multi-object, object 2) returns the part of the |
… | |
… | |
522 | } |
521 | } |
523 | } |
522 | } |
524 | } |
523 | } |
525 | |
524 | |
526 | dst->set_speed (dst->speed); |
525 | dst->set_speed (dst->speed); |
|
|
526 | } |
|
|
527 | |
|
|
528 | void |
|
|
529 | object::instantiate () |
|
|
530 | { |
|
|
531 | if (!uuid.seq) // HACK |
|
|
532 | uuid = gen_uuid (); |
|
|
533 | |
|
|
534 | speed_left = -0.1f; |
|
|
535 | /* copy the body_info to the body_used - this is only really |
|
|
536 | * need for monsters, but doesn't hurt to do it for everything. |
|
|
537 | * by doing so, when a monster is created, it has good starting |
|
|
538 | * values for the body_used info, so when items are created |
|
|
539 | * for it, they can be properly equipped. |
|
|
540 | */ |
|
|
541 | memcpy (body_used, body_info, sizeof (body_used)); |
|
|
542 | |
|
|
543 | attachable::instantiate (); |
527 | } |
544 | } |
528 | |
545 | |
529 | object * |
546 | object * |
530 | object::clone () |
547 | object::clone () |
531 | { |
548 | { |
… | |
… | |
589 | * UP_OBJ_FACE: only the objects face has changed. |
606 | * UP_OBJ_FACE: only the objects face has changed. |
590 | */ |
607 | */ |
591 | void |
608 | void |
592 | update_object (object *op, int action) |
609 | update_object (object *op, int action) |
593 | { |
610 | { |
594 | MoveType move_on, move_off, move_block, move_slow; |
|
|
595 | |
|
|
596 | if (op == NULL) |
611 | if (op == NULL) |
597 | { |
612 | { |
598 | /* this should never happen */ |
613 | /* this should never happen */ |
599 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
614 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
600 | return; |
615 | return; |
… | |
… | |
670 | face = blank_face; |
685 | face = blank_face; |
671 | } |
686 | } |
672 | |
687 | |
673 | object::~object () |
688 | object::~object () |
674 | { |
689 | { |
675 | if (index) |
|
|
676 | unlink (); |
690 | unlink (); |
677 | |
691 | |
678 | free_key_values (this); |
692 | free_key_values (this); |
679 | } |
693 | } |
680 | |
694 | |
681 | static int object_count; |
695 | static int object_count; |
… | |
… | |
690 | objects.insert (this); |
704 | objects.insert (this); |
691 | } |
705 | } |
692 | |
706 | |
693 | void object::unlink () |
707 | void object::unlink () |
694 | { |
708 | { |
695 | assert (index);//D |
709 | if (!index) |
|
|
710 | return; |
|
|
711 | |
696 | objects.erase (this); |
712 | objects.erase (this); |
697 | refcnt_dec (); |
713 | refcnt_dec (); |
698 | } |
714 | } |
699 | |
715 | |
700 | void |
716 | void |
… | |
… | |
774 | * drop on that space. |
790 | * drop on that space. |
775 | */ |
791 | */ |
776 | if (!drop_to_ground |
792 | if (!drop_to_ground |
777 | || !map |
793 | || !map |
778 | || map->in_memory != MAP_IN_MEMORY |
794 | || map->in_memory != MAP_IN_MEMORY |
|
|
795 | || map->nodrop |
779 | || ms ().move_block == MOVE_ALL) |
796 | || ms ().move_block == MOVE_ALL) |
780 | { |
797 | { |
781 | while (inv) |
798 | while (inv) |
782 | { |
799 | { |
783 | inv->destroy_inv (drop_to_ground); |
800 | inv->destroy_inv (drop_to_ground); |
… | |
… | |
817 | |
834 | |
818 | if (flag [FLAG_IS_LINKED]) |
835 | if (flag [FLAG_IS_LINKED]) |
819 | remove_button_link (this); |
836 | remove_button_link (this); |
820 | |
837 | |
821 | if (flag [FLAG_FRIENDLY]) |
838 | if (flag [FLAG_FRIENDLY]) |
|
|
839 | { |
822 | remove_friendly_object (this); |
840 | remove_friendly_object (this); |
|
|
841 | |
|
|
842 | if (type == GOLEM |
|
|
843 | && owner |
|
|
844 | && owner->type == PLAYER |
|
|
845 | && owner->contr->ranges[range_golem] == this) |
|
|
846 | owner->contr->ranges[range_golem] = 0; |
|
|
847 | } |
823 | |
848 | |
824 | if (!flag [FLAG_REMOVED]) |
849 | if (!flag [FLAG_REMOVED]) |
825 | remove (); |
850 | remove (); |
826 | |
851 | |
827 | destroy_inv (true); |
852 | destroy_inv (true); |
… | |
… | |
899 | * This function removes the object op from the linked list of objects |
924 | * This function removes the object op from the linked list of objects |
900 | * which it is currently tied to. When this function is done, the |
925 | * which it is currently tied to. When this function is done, the |
901 | * object will have no environment. If the object previously had an |
926 | * object will have no environment. If the object previously had an |
902 | * environment, the x and y coordinates will be updated to |
927 | * environment, the x and y coordinates will be updated to |
903 | * the previous environment. |
928 | * the previous environment. |
904 | * Beware: This function is called from the editor as well! |
|
|
905 | */ |
929 | */ |
906 | void |
930 | void |
907 | object::remove_slow () |
931 | object::do_remove () |
908 | { |
932 | { |
909 | object *tmp, *last = 0; |
933 | object *tmp, *last = 0; |
910 | object *otmp; |
934 | object *otmp; |
911 | |
935 | |
912 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
936 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
… | |
… | |
955 | } |
979 | } |
956 | else if (map) |
980 | else if (map) |
957 | { |
981 | { |
958 | if (type == PLAYER) |
982 | if (type == PLAYER) |
959 | { |
983 | { |
|
|
984 | // leaving a spot always closes any open container on the ground |
|
|
985 | if (container && !container->env) |
|
|
986 | // this causes spurious floorbox updates, but it ensures |
|
|
987 | // that the CLOSE event is being sent. |
|
|
988 | close_container (); |
|
|
989 | |
960 | --map->players; |
990 | --map->players; |
961 | map->touch (); |
991 | map->touch (); |
962 | } |
992 | } |
963 | |
993 | |
964 | map->dirty = true; |
994 | map->dirty = true; |
… | |
… | |
1259 | * looks like instead of lots of conditions here. |
1289 | * looks like instead of lots of conditions here. |
1260 | * makes things faster, and effectively the same result. |
1290 | * makes things faster, and effectively the same result. |
1261 | */ |
1291 | */ |
1262 | |
1292 | |
1263 | /* Have object 'fall below' other objects that block view. |
1293 | /* Have object 'fall below' other objects that block view. |
1264 | * Unless those objects are exits, type 66 |
1294 | * Unless those objects are exits. |
1265 | * If INS_ON_TOP is used, don't do this processing |
1295 | * If INS_ON_TOP is used, don't do this processing |
1266 | * Need to find the object that in fact blocks view, otherwise |
1296 | * Need to find the object that in fact blocks view, otherwise |
1267 | * stacking is a bit odd. |
1297 | * stacking is a bit odd. |
1268 | */ |
1298 | */ |
1269 | if (!(flag & INS_ON_TOP) |
1299 | if (!(flag & INS_ON_TOP) |
1270 | && ms.flags () & P_BLOCKSVIEW |
1300 | && ms.flags () & P_BLOCKSVIEW |
1271 | && (op->face && !op->face->visibility)) |
1301 | && (op->face && !faces [op->face].visibility)) |
1272 | { |
1302 | { |
1273 | for (last = top; last != floor; last = last->below) |
1303 | for (last = top; last != floor; last = last->below) |
1274 | if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) |
1304 | if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) |
1275 | break; |
1305 | break; |
1276 | |
1306 | |
… | |
… | |
1399 | tmp1->x = op->x; |
1429 | tmp1->x = op->x; |
1400 | tmp1->y = op->y; |
1430 | tmp1->y = op->y; |
1401 | insert_ob_in_map (tmp1, op->map, op, 0); |
1431 | insert_ob_in_map (tmp1, op->map, op, 0); |
1402 | } |
1432 | } |
1403 | |
1433 | |
|
|
1434 | // XXX: function not returning object* |
1404 | object * |
1435 | object * |
1405 | object::insert_at (object *where, object *originator, int flags) |
1436 | object::insert_at (object *where, object *originator, int flags) |
1406 | { |
1437 | { |
1407 | where->map->insert (this, where->x, where->y, originator, flags); |
1438 | where->map->insert (this, where->x, where->y, originator, flags); |
1408 | } |
1439 | } |
… | |
… | |
1966 | } |
1997 | } |
1967 | |
1998 | |
1968 | if (!index) |
1999 | if (!index) |
1969 | return -1; |
2000 | return -1; |
1970 | |
2001 | |
1971 | return altern[RANDOM () % index]; |
2002 | return altern [rndm (index)]; |
1972 | } |
2003 | } |
1973 | |
2004 | |
1974 | /* |
2005 | /* |
1975 | * find_first_free_spot(archetype, maptile, x, y) works like |
2006 | * find_first_free_spot(archetype, maptile, x, y) works like |
1976 | * find_free_spot(), but it will search max number of squares. |
2007 | * find_free_spot(), but it will search max number of squares. |
… | |
… | |
1997 | { |
2028 | { |
1998 | arr += begin; |
2029 | arr += begin; |
1999 | end -= begin; |
2030 | end -= begin; |
2000 | |
2031 | |
2001 | while (--end) |
2032 | while (--end) |
2002 | swap (arr [end], arr [RANDOM () % (end + 1)]); |
2033 | swap (arr [end], arr [rndm (end + 1)]); |
2003 | } |
2034 | } |
2004 | |
2035 | |
2005 | /* new function to make monster searching more efficient, and effective! |
2036 | /* new function to make monster searching more efficient, and effective! |
2006 | * This basically returns a randomized array (in the passed pointer) of |
2037 | * This basically returns a randomized array (in the passed pointer) of |
2007 | * the spaces to find monsters. In this way, it won't always look for |
2038 | * the spaces to find monsters. In this way, it won't always look for |
… | |
… | |
2319 | insert_ob_in_ob (object_create_clone (item), dst); |
2350 | insert_ob_in_ob (object_create_clone (item), dst); |
2320 | |
2351 | |
2321 | return dst; |
2352 | return dst; |
2322 | } |
2353 | } |
2323 | |
2354 | |
2324 | /* GROS - Creates an object using a string representing its content. */ |
|
|
2325 | /* Basically, we save the content of the string to a temp file, then call */ |
|
|
2326 | /* load_object on it. I admit it is a highly inefficient way to make things, */ |
|
|
2327 | /* but it was simple to make and allows reusing the load_object function. */ |
|
|
2328 | /* Remember not to use load_object_str in a time-critical situation. */ |
|
|
2329 | /* Also remember that multiparts objects are not supported for now. */ |
|
|
2330 | object * |
|
|
2331 | load_object_str (const char *obstr) |
|
|
2332 | { |
|
|
2333 | object *op; |
|
|
2334 | char filename[MAX_BUF]; |
|
|
2335 | |
|
|
2336 | sprintf (filename, "%s/cfloadobstr2044", settings.tmpdir); |
|
|
2337 | |
|
|
2338 | FILE *tempfile = fopen (filename, "w"); |
|
|
2339 | |
|
|
2340 | if (tempfile == NULL) |
|
|
2341 | { |
|
|
2342 | LOG (llevError, "Error - Unable to access load object temp file\n"); |
|
|
2343 | return NULL; |
|
|
2344 | } |
|
|
2345 | |
|
|
2346 | fprintf (tempfile, obstr); |
|
|
2347 | fclose (tempfile); |
|
|
2348 | |
|
|
2349 | op = object::create (); |
|
|
2350 | |
|
|
2351 | object_thawer thawer (filename); |
|
|
2352 | |
|
|
2353 | if (thawer) |
|
|
2354 | load_object (thawer, op, 0); |
|
|
2355 | |
|
|
2356 | LOG (llevDebug, " load str completed, object=%s\n", &op->name); |
|
|
2357 | CLEAR_FLAG (op, FLAG_REMOVED); |
|
|
2358 | |
|
|
2359 | return op; |
|
|
2360 | } |
|
|
2361 | |
|
|
2362 | /* This returns the first object in who's inventory that |
2355 | /* This returns the first object in who's inventory that |
2363 | * has the same type and subtype match. |
2356 | * has the same type and subtype match. |
2364 | * returns NULL if no match. |
2357 | * returns NULL if no match. |
2365 | */ |
2358 | */ |
2366 | object * |
2359 | object * |
… | |
… | |
2569 | { |
2562 | { |
2570 | char flagdesc[512]; |
2563 | char flagdesc[512]; |
2571 | char info2[256 * 4]; |
2564 | char info2[256 * 4]; |
2572 | char *p = info; |
2565 | char *p = info; |
2573 | |
2566 | |
2574 | p += snprintf (p, 512, "{cnt:%d,uuid:<1,%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2567 | p += snprintf (p, 512, "{cnt:%d,uuid:<1.%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2575 | count, uuid.seq, |
2568 | count, uuid.seq, |
2576 | &name, |
2569 | &name, |
2577 | title ? "\",title:\"" : "", |
2570 | title ? "\",title:\"" : "", |
2578 | title ? (const char *)title : "", |
2571 | title ? (const char *)title : "", |
2579 | flag_desc (flagdesc, 512), type); |
2572 | flag_desc (flagdesc, 512), type); |
… | |
… | |
2599 | { |
2592 | { |
2600 | static char info[256 * 4]; |
2593 | static char info[256 * 4]; |
2601 | return debug_desc (info); |
2594 | return debug_desc (info); |
2602 | } |
2595 | } |
2603 | |
2596 | |
|
|
2597 | struct region * |
|
|
2598 | object::region () const |
|
|
2599 | { |
|
|
2600 | return map ? map->region (x, y) |
|
|
2601 | : region::default_region (); |
|
|
2602 | } |
|
|
2603 | |
|
|
2604 | const materialtype_t * |
|
|
2605 | object::dominant_material () const |
|
|
2606 | { |
|
|
2607 | if (materialtype_t *mat = name_to_material (materialname)) |
|
|
2608 | return mat; |
|
|
2609 | |
|
|
2610 | // omfg this is slow, this has to be temporary :) |
|
|
2611 | shstr unknown ("unknown"); |
|
|
2612 | |
|
|
2613 | return name_to_material (unknown); |
|
|
2614 | } |
|
|
2615 | |
|
|
2616 | void |
|
|
2617 | object::open_container (object *new_container) |
|
|
2618 | { |
|
|
2619 | if (container == new_container) |
|
|
2620 | return; |
|
|
2621 | |
|
|
2622 | if (object *old_container = container) |
|
|
2623 | { |
|
|
2624 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
|
|
2625 | return; |
|
|
2626 | |
|
|
2627 | #if 0 |
|
|
2628 | // remove the "Close old_container" object. |
|
|
2629 | if (object *closer = old_container->inv) |
|
|
2630 | if (closer->type == CLOSE_CON) |
|
|
2631 | closer->destroy (); |
|
|
2632 | #endif |
|
|
2633 | |
|
|
2634 | old_container->flag [FLAG_APPLIED] = 0; |
|
|
2635 | container = 0; |
|
|
2636 | |
|
|
2637 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2638 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
|
|
2639 | } |
|
|
2640 | |
|
|
2641 | if (new_container) |
|
|
2642 | { |
|
|
2643 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
|
|
2644 | return; |
|
|
2645 | |
|
|
2646 | // TODO: this does not seem to serve any purpose anymore? |
|
|
2647 | #if 0 |
|
|
2648 | // insert the "Close Container" object. |
|
|
2649 | if (archetype *closer = new_container->other_arch) |
|
|
2650 | { |
|
|
2651 | object *closer = arch_to_object (new_container->other_arch); |
|
|
2652 | closer->flag [FLAG_NO_MAP_SAVE] = 1; |
|
|
2653 | new_container->insert (closer); |
|
|
2654 | } |
|
|
2655 | #endif |
|
|
2656 | |
|
|
2657 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
|
|
2658 | |
|
|
2659 | new_container->flag [FLAG_APPLIED] = 1; |
|
|
2660 | container = new_container; |
|
|
2661 | |
|
|
2662 | esrv_update_item (UPD_FLAGS, this, new_container); |
|
|
2663 | esrv_send_inventory (this, new_container); |
|
|
2664 | } |
|
|
2665 | } |
|
|
2666 | |
|
|
2667 | |