… | |
… | |
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 | { |
… | |
… | |
670 | face = blank_face; |
687 | face = blank_face; |
671 | } |
688 | } |
672 | |
689 | |
673 | object::~object () |
690 | object::~object () |
674 | { |
691 | { |
675 | if (index) |
|
|
676 | unlink (); |
692 | unlink (); |
677 | |
693 | |
678 | free_key_values (this); |
694 | free_key_values (this); |
679 | } |
695 | } |
680 | |
696 | |
681 | static int object_count; |
697 | static int object_count; |
… | |
… | |
690 | objects.insert (this); |
706 | objects.insert (this); |
691 | } |
707 | } |
692 | |
708 | |
693 | void object::unlink () |
709 | void object::unlink () |
694 | { |
710 | { |
695 | assert (index);//D |
711 | if (!index) |
|
|
712 | return; |
|
|
713 | |
696 | objects.erase (this); |
714 | objects.erase (this); |
697 | refcnt_dec (); |
715 | refcnt_dec (); |
698 | } |
716 | } |
699 | |
717 | |
700 | void |
718 | void |
… | |
… | |
774 | * drop on that space. |
792 | * drop on that space. |
775 | */ |
793 | */ |
776 | if (!drop_to_ground |
794 | if (!drop_to_ground |
777 | || !map |
795 | || !map |
778 | || map->in_memory != MAP_IN_MEMORY |
796 | || map->in_memory != MAP_IN_MEMORY |
|
|
797 | || map->nodrop |
779 | || ms ().move_block == MOVE_ALL) |
798 | || ms ().move_block == MOVE_ALL) |
780 | { |
799 | { |
781 | while (inv) |
800 | while (inv) |
782 | { |
801 | { |
783 | inv->destroy_inv (drop_to_ground); |
802 | inv->destroy_inv (drop_to_ground); |
… | |
… | |
817 | |
836 | |
818 | if (flag [FLAG_IS_LINKED]) |
837 | if (flag [FLAG_IS_LINKED]) |
819 | remove_button_link (this); |
838 | remove_button_link (this); |
820 | |
839 | |
821 | if (flag [FLAG_FRIENDLY]) |
840 | if (flag [FLAG_FRIENDLY]) |
|
|
841 | { |
822 | remove_friendly_object (this); |
842 | remove_friendly_object (this); |
|
|
843 | |
|
|
844 | if (type == GOLEM |
|
|
845 | && owner |
|
|
846 | && owner->type == PLAYER |
|
|
847 | && owner->contr->ranges[range_golem] == this) |
|
|
848 | owner->contr->ranges[range_golem] = 0; |
|
|
849 | } |
823 | |
850 | |
824 | if (!flag [FLAG_REMOVED]) |
851 | if (!flag [FLAG_REMOVED]) |
825 | remove (); |
852 | remove (); |
826 | |
853 | |
827 | destroy_inv (true); |
854 | destroy_inv (true); |
… | |
… | |
899 | * This function removes the object op from the linked list of objects |
926 | * 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 |
927 | * which it is currently tied to. When this function is done, the |
901 | * object will have no environment. If the object previously had an |
928 | * object will have no environment. If the object previously had an |
902 | * environment, the x and y coordinates will be updated to |
929 | * environment, the x and y coordinates will be updated to |
903 | * the previous environment. |
930 | * the previous environment. |
904 | * Beware: This function is called from the editor as well! |
|
|
905 | */ |
931 | */ |
906 | void |
932 | void |
907 | object::remove_slow () |
933 | object::do_remove () |
908 | { |
934 | { |
909 | object *tmp, *last = 0; |
935 | object *tmp, *last = 0; |
910 | object *otmp; |
936 | object *otmp; |
911 | |
937 | |
912 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
938 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
… | |
… | |
955 | } |
981 | } |
956 | else if (map) |
982 | else if (map) |
957 | { |
983 | { |
958 | if (type == PLAYER) |
984 | if (type == PLAYER) |
959 | { |
985 | { |
|
|
986 | // leaving a spot always closes any open container on the ground |
|
|
987 | if (container && !container->env) |
|
|
988 | // this causes spurious floorbox updates, but it ensures |
|
|
989 | // that the CLOSE event is being sent. |
|
|
990 | close_container (); |
|
|
991 | |
960 | --map->players; |
992 | --map->players; |
961 | map->touch (); |
993 | map->touch (); |
962 | } |
994 | } |
963 | |
995 | |
964 | map->dirty = true; |
996 | map->dirty = true; |
… | |
… | |
1749 | if ((!op->move_type && tmp->move_slow & MOVE_WALK) || |
1781 | if ((!op->move_type && tmp->move_slow & MOVE_WALK) || |
1750 | ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) |
1782 | ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) |
1751 | { |
1783 | { |
1752 | |
1784 | |
1753 | float |
1785 | float |
1754 | diff = tmp->move_slow_penalty * FABS (op->speed); |
1786 | diff = tmp->move_slow_penalty * fabs (op->speed); |
1755 | |
1787 | |
1756 | if (op->type == PLAYER) |
1788 | if (op->type == PLAYER) |
1757 | if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || |
1789 | if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || |
1758 | (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) |
1790 | (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) |
1759 | diff /= 4.0; |
1791 | diff /= 4.0; |
… | |
… | |
1966 | } |
1998 | } |
1967 | |
1999 | |
1968 | if (!index) |
2000 | if (!index) |
1969 | return -1; |
2001 | return -1; |
1970 | |
2002 | |
1971 | return altern[RANDOM () % index]; |
2003 | return altern [rndm (index)]; |
1972 | } |
2004 | } |
1973 | |
2005 | |
1974 | /* |
2006 | /* |
1975 | * find_first_free_spot(archetype, maptile, x, y) works like |
2007 | * find_first_free_spot(archetype, maptile, x, y) works like |
1976 | * find_free_spot(), but it will search max number of squares. |
2008 | * find_free_spot(), but it will search max number of squares. |
… | |
… | |
1997 | { |
2029 | { |
1998 | arr += begin; |
2030 | arr += begin; |
1999 | end -= begin; |
2031 | end -= begin; |
2000 | |
2032 | |
2001 | while (--end) |
2033 | while (--end) |
2002 | swap (arr [end], arr [RANDOM () % (end + 1)]); |
2034 | swap (arr [end], arr [rndm (end + 1)]); |
2003 | } |
2035 | } |
2004 | |
2036 | |
2005 | /* new function to make monster searching more efficient, and effective! |
2037 | /* new function to make monster searching more efficient, and effective! |
2006 | * This basically returns a randomized array (in the passed pointer) of |
2038 | * 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 |
2039 | * the spaces to find monsters. In this way, it won't always look for |
… | |
… | |
2319 | insert_ob_in_ob (object_create_clone (item), dst); |
2351 | insert_ob_in_ob (object_create_clone (item), dst); |
2320 | |
2352 | |
2321 | return dst; |
2353 | return dst; |
2322 | } |
2354 | } |
2323 | |
2355 | |
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 |
2356 | /* This returns the first object in who's inventory that |
2363 | * has the same type and subtype match. |
2357 | * has the same type and subtype match. |
2364 | * returns NULL if no match. |
2358 | * returns NULL if no match. |
2365 | */ |
2359 | */ |
2366 | object * |
2360 | object * |
… | |
… | |
2569 | { |
2563 | { |
2570 | char flagdesc[512]; |
2564 | char flagdesc[512]; |
2571 | char info2[256 * 4]; |
2565 | char info2[256 * 4]; |
2572 | char *p = info; |
2566 | char *p = info; |
2573 | |
2567 | |
2574 | p += snprintf (p, 512, "{cnt:%d,uuid:<1,%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2568 | p += snprintf (p, 512, "{cnt:%d,uuid:<1.%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2575 | count, uuid.seq, |
2569 | count, uuid.seq, |
2576 | &name, |
2570 | &name, |
2577 | title ? "\",title:\"" : "", |
2571 | title ? "\",title:\"" : "", |
2578 | title ? (const char *)title : "", |
2572 | title ? (const char *)title : "", |
2579 | flag_desc (flagdesc, 512), type); |
2573 | flag_desc (flagdesc, 512), type); |
… | |
… | |
2599 | { |
2593 | { |
2600 | static char info[256 * 4]; |
2594 | static char info[256 * 4]; |
2601 | return debug_desc (info); |
2595 | return debug_desc (info); |
2602 | } |
2596 | } |
2603 | |
2597 | |
|
|
2598 | struct region * |
|
|
2599 | object::region () const |
|
|
2600 | { |
|
|
2601 | return map ? map->region (x, y) |
|
|
2602 | : region::default_region (); |
|
|
2603 | } |
|
|
2604 | |
|
|
2605 | const materialtype_t * |
|
|
2606 | object::dominant_material () const |
|
|
2607 | { |
|
|
2608 | if (materialtype_t *mat = name_to_material (materialname)) |
|
|
2609 | return mat; |
|
|
2610 | |
|
|
2611 | // omfg this is slow, this has to be temporary :) |
|
|
2612 | shstr unknown ("unknown"); |
|
|
2613 | |
|
|
2614 | return name_to_material (unknown); |
|
|
2615 | } |
|
|
2616 | |
|
|
2617 | void |
|
|
2618 | object::open_container (object *new_container) |
|
|
2619 | { |
|
|
2620 | if (container == new_container) |
|
|
2621 | return; |
|
|
2622 | |
|
|
2623 | if (object *old_container = container) |
|
|
2624 | { |
|
|
2625 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
|
|
2626 | return; |
|
|
2627 | |
|
|
2628 | #if 0 |
|
|
2629 | // remove the "Close old_container" object. |
|
|
2630 | if (object *closer = old_container->inv) |
|
|
2631 | if (closer->type == CLOSE_CON) |
|
|
2632 | closer->destroy (); |
|
|
2633 | #endif |
|
|
2634 | |
|
|
2635 | old_container->flag [FLAG_APPLIED] = 0; |
|
|
2636 | container = 0; |
|
|
2637 | |
|
|
2638 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2639 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
|
|
2640 | } |
|
|
2641 | |
|
|
2642 | if (new_container) |
|
|
2643 | { |
|
|
2644 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
|
|
2645 | return; |
|
|
2646 | |
|
|
2647 | // TODO: this does not seem to serve any purpose anymore? |
|
|
2648 | #if 0 |
|
|
2649 | // insert the "Close Container" object. |
|
|
2650 | if (archetype *closer = new_container->other_arch) |
|
|
2651 | { |
|
|
2652 | object *closer = arch_to_object (new_container->other_arch); |
|
|
2653 | closer->flag [FLAG_NO_MAP_SAVE] = 1; |
|
|
2654 | new_container->insert (closer); |
|
|
2655 | } |
|
|
2656 | #endif |
|
|
2657 | |
|
|
2658 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
|
|
2659 | |
|
|
2660 | new_container->flag [FLAG_APPLIED] = 1; |
|
|
2661 | container = new_container; |
|
|
2662 | |
|
|
2663 | esrv_update_item (UPD_FLAGS, this, new_container); |
|
|
2664 | esrv_send_inventory (this, new_container); |
|
|
2665 | } |
|
|
2666 | } |
|
|
2667 | |
|
|
2668 | |